cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [cayenne] 04/06: CAY-2571 DataDomainFlushAction redesign tests
Date Wed, 24 Apr 2019 14:54:01 GMT
This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit 1e2d9bfef2cd35c450562b918538eaea7723ae58
Author: Nikita Timofeev <stariy95@gmail.com>
AuthorDate: Mon Apr 22 18:05:24 2019 +0300

    CAY-2571 DataDomainFlushAction redesign
    tests
---
 .../DataContextEntityWithMeaningfulPKIT.java       | 15 +++++
 .../access/DataContextFlattenedAttributesIT.java   | 66 ++++++++++++++++++++++
 .../access/DefaultDataRowStoreFactoryIT.java       |  6 ++
 .../cayenne/access/VerticalInheritanceIT.java      | 19 ++-----
 .../server/DataContextFactoryTest.java             | 12 ++++
 .../test/resources/inheritance-vertical.map.xml    |  4 +-
 cayenne-server/src/test/resources/testmap.map.xml  |  4 +-
 7 files changed, 107 insertions(+), 19 deletions(-)

diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextEntityWithMeaningfulPKIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextEntityWithMeaningfulPKIT.java
index 31136a0..2ac114d 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextEntityWithMeaningfulPKIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextEntityWithMeaningfulPKIT.java
@@ -29,10 +29,12 @@ import org.apache.cayenne.query.ObjectIdQuery;
 import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKDep;
 import org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1;
+import org.apache.cayenne.testdo.meaningful_pk.MeaningfulPk;
 import org.apache.cayenne.testdo.meaningful_pk.MeaningfulPkTest2;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import java.util.List;
@@ -189,4 +191,17 @@ public class DataContextEntityWithMeaningfulPKIT extends ServerCase {
         assertEquals(1, obj1.getPkAttribute());
         assertEquals(2, obj2.getPkAttribute());
     }
+
+    @Test
+    @Ignore("Insert will fail")
+    public void testInsertDelete() {
+        MeaningfulPk pkObj = context.newObject(MeaningfulPk.class);
+        pkObj.setPk("123");
+        context.commitChanges();
+
+        context.deleteObject(pkObj);
+        MeaningfulPk pkObj2 = context.newObject(MeaningfulPk.class);
+        pkObj2.setPk("123");
+        context.commitChanges();
+    }
 }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java
index fb8f7a5..c3f2bed 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java
@@ -20,10 +20,14 @@
 package org.apache.cayenne.access;
 
 import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.query.ObjectSelect;
+import org.apache.cayenne.query.SelectById;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.reflect.PersistentDescriptor;
 import org.apache.cayenne.test.jdbc.DBHelper;
@@ -51,6 +55,9 @@ import static org.junit.Assert.assertTrue;
 public class DataContextFlattenedAttributesIT extends ServerCase {
 
     @Inject
+    private ServerRuntime runtime;
+
+    @Inject
     private DataContext context;
 
     @Inject
@@ -109,6 +116,21 @@ public class DataContextFlattenedAttributesIT extends ServerCase {
     }
 
     @Test
+    public void testSelect() throws Exception {
+        createTestDataSet();
+
+        CompoundPainting result = ObjectSelect
+                .query(CompoundPainting.class)
+                .orderBy(CompoundPainting.PAINTING_ID_PK_PROPERTY.asc())
+                .selectFirst(context);
+
+        assertNotNull(result);
+
+        result.setArtistName("new A");
+        context.commitChanges();
+    }
+
+    @Test
     public void testSelectCompound1() throws Exception {
         createTestDataSet();
         SelectQuery<CompoundPainting> query = SelectQuery.query(CompoundPainting.class);
@@ -377,4 +399,48 @@ public class DataContextFlattenedAttributesIT extends ServerCase {
 
         context.commitChanges();
     }
+
+    @Test
+    public void testUpdateDifferentContext() {
+        Object id;
+        {
+            // insert
+            ObjectContext context1 = runtime.newContext();
+            CompoundPainting o1 = context1.newObject(CompoundPainting.class);
+            o1.setArtistName("A1");
+            o1.setEstimatedPrice(new BigDecimal(1d));
+            o1.setGalleryName("G1");
+            o1.setPaintingTitle("P1");
+            o1.setTextReview("T1");
+
+            context1.commitChanges();
+            id = o1.getObjectId().getIdSnapshot().get(CompoundPainting.PAINTING_ID_PK_COLUMN);
+        }
+
+        {
+            // read and update
+            ObjectContext context2 = runtime.newContext();
+            CompoundPainting o2 = SelectById.query(CompoundPainting.class, id).selectFirst(context2);
+
+            o2.setArtistName("AX1");
+            o2.setEstimatedPrice(new BigDecimal(2d));
+            o2.setGalleryName("XG1");
+            o2.setPaintingTitle("PX1");
+            o2.setTextReview("TX1");
+
+            context2.commitChanges();
+        }
+
+        {
+            // read and check
+            ObjectContext context3 = runtime.newContext();
+            CompoundPainting o3 = SelectById.query(CompoundPainting.class, id).selectFirst(context3);
+
+            assertEquals("AX1", o3.getArtistName());
+            assertEquals("2.00", o3.getEstimatedPrice().toPlainString());
+            assertEquals("XG1", o3.getGalleryName());
+            assertEquals("PX1", o3.getPaintingTitle());
+            assertEquals("TX1", o3.getTextReview());
+        }
+    }
 }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DefaultDataRowStoreFactoryIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/DefaultDataRowStoreFactoryIT.java
index b95aeac..cd849d9 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DefaultDataRowStoreFactoryIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DefaultDataRowStoreFactoryIT.java
@@ -19,6 +19,10 @@
 
 package org.apache.cayenne.access;
 
+import org.apache.cayenne.access.flush.DataDomainFlushActionFactory;
+import org.apache.cayenne.access.flush.operation.DbRowOpSorter;
+import org.apache.cayenne.access.flush.DefaultDataDomainFlushActionFactory;
+import org.apache.cayenne.access.flush.operation.DefaultDbRowOpSorter;
 import org.apache.cayenne.configuration.DefaultRuntimeProperties;
 import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.configuration.server.ServerModule;
@@ -100,6 +104,8 @@ public class DefaultDataRowStoreFactoryIT extends ServerCase {
             binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
             binder.bind(EventBridge.class).toProvider(MockEventBridgeProvider.class);
             binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
+            binder.bind(DataDomainFlushActionFactory.class).to(DefaultDataDomainFlushActionFactory.class);
+            binder.bind(DbRowOpSorter.class).to(DefaultDbRowOpSorter.class);
             ServerModule.contributeProperties(binder);
         };
 
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/VerticalInheritanceIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/VerticalInheritanceIT.java
index c8d2077..b79989b 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/VerticalInheritanceIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/VerticalInheritanceIT.java
@@ -94,7 +94,7 @@ public class VerticalInheritanceIT extends ServerCase {
 		sub1.getObjectContext().commitChanges();
 
 		assertEquals(1, ivRootTable.getRowCount());
-		assertEquals(1, ivSub1Table.getRowCount());
+		assertEquals(0, ivSub1Table.getRowCount());
 
 		Object[] data = ivRootTable.select();
 		assertEquals(3, data.length);
@@ -103,11 +103,6 @@ public class VerticalInheritanceIT extends ServerCase {
 		assertEquals("XyZX", data[1]);
 		assertEquals("IvSub1", data[2]);
 
-		Object[] subdata = ivSub1Table.select();
-		assertEquals(2, subdata.length);
-		assertEquals(data[0], subdata[0]);
-		assertNull(subdata[1]);
-
 		ivSub1Table.deleteAll();
 		ivRootTable.deleteAll();
 
@@ -123,7 +118,7 @@ public class VerticalInheritanceIT extends ServerCase {
 		assertEquals("XyZXY", data[1]);
 		assertEquals("IvSub1", data[2]);
 
-		subdata = ivSub1Table.select();
+		Object[] subdata = ivSub1Table.select();
 		assertEquals(2, subdata.length);
 		assertEquals(data[0], subdata[0]);
 		assertEquals("BdE2", subdata[1]);
@@ -143,7 +138,7 @@ public class VerticalInheritanceIT extends ServerCase {
 		sub2.getObjectContext().commitChanges();
 
 		assertEquals(1, ivRootTable.getRowCount());
-		assertEquals(1, ivSub2Table.getRowCount());
+		assertEquals(0, ivSub2Table.getRowCount());
 
 		Object[] data = ivRootTable.select();
 		assertEquals(3, data.length);
@@ -152,12 +147,6 @@ public class VerticalInheritanceIT extends ServerCase {
 		assertEquals("XyZX", data[1]);
 		assertEquals("IvSub2", data[2]);
 
-		Object[] subdata = ivSub2Table.select();
-		assertEquals(3, subdata.length);
-		assertEquals(data[0], subdata[0]);
-		assertNull(subdata[1]);
-		assertNull(subdata[2]);
-
 		ivSub2Table.deleteAll();
 		ivRootTable.deleteAll();
 
@@ -174,7 +163,7 @@ public class VerticalInheritanceIT extends ServerCase {
 		assertEquals("XyZXY", data[1]);
 		assertEquals("IvSub2", data[2]);
 
-		subdata = ivSub2Table.select();
+		Object[] subdata = ivSub2Table.select();
 		assertEquals(3, subdata.length);
 		assertEquals(data[0], subdata[0]);
 		assertEquals("BdE2", subdata[1]);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
index d92ca62..62ac624 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
@@ -24,6 +24,11 @@ import org.apache.cayenne.access.DataRowStoreFactory;
 import org.apache.cayenne.access.DefaultDataRowStoreFactory;
 import org.apache.cayenne.access.DefaultObjectMapRetainStrategy;
 import org.apache.cayenne.access.ObjectMapRetainStrategy;
+import org.apache.cayenne.access.flush.DataDomainFlushActionFactory;
+import org.apache.cayenne.access.flush.operation.DbRowOpSorter;
+import org.apache.cayenne.access.flush.DefaultDataDomainFlushActionFactory;
+import org.apache.cayenne.access.flush.operation.DefaultDbRowOpSorter;
+import org.apache.cayenne.ashwood.AshwoodEntitySorter;
 import org.apache.cayenne.cache.MapQueryCache;
 import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.configuration.DefaultObjectStoreFactory;
@@ -39,6 +44,7 @@ import org.apache.cayenne.event.MockEventManager;
 import org.apache.cayenne.event.NoopEventBridgeProvider;
 import org.apache.cayenne.log.JdbcEventLogger;
 import org.apache.cayenne.log.Slf4jJdbcEventLogger;
+import org.apache.cayenne.map.EntitySorter;
 import org.apache.cayenne.tx.DefaultTransactionFactory;
 import org.apache.cayenne.tx.DefaultTransactionManager;
 import org.apache.cayenne.tx.TransactionFactory;
@@ -74,6 +80,9 @@ public class DataContextFactoryTest {
             binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
             binder.bind(EventBridge.class).toProvider(NoopEventBridgeProvider.class);
             binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
+            binder.bind(DataDomainFlushActionFactory.class).to(DefaultDataDomainFlushActionFactory.class);
+            binder.bind(DbRowOpSorter.class).to(DefaultDbRowOpSorter.class);
+            binder.bind(EntitySorter.class).to(AshwoodEntitySorter.class);
         };
 
         Injector injector = DIBootstrap.createInjector(testModule);
@@ -110,6 +119,9 @@ public class DataContextFactoryTest {
             binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
             binder.bind(EventBridge.class).toProvider(NoopEventBridgeProvider.class);
             binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
+            binder.bind(DataDomainFlushActionFactory.class).to(DefaultDataDomainFlushActionFactory.class);
+            binder.bind(DbRowOpSorter.class).to(DefaultDbRowOpSorter.class);
+            binder.bind(EntitySorter.class).to(AshwoodEntitySorter.class);
         };
 
         Injector injector = DIBootstrap.createInjector(testModule);
diff --git a/cayenne-server/src/test/resources/inheritance-vertical.map.xml b/cayenne-server/src/test/resources/inheritance-vertical.map.xml
index 4af9df1..25b772a 100644
--- a/cayenne-server/src/test/resources/inheritance-vertical.map.xml
+++ b/cayenne-server/src/test/resources/inheritance-vertical.map.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <data-map xmlns="http://cayenne.apache.org/schema/10/modelMap"
 	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	 xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap http://cayenne.apache.org/schema/10/modelMap.xsd"
+	 xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap https://cayenne.apache.org/schema/10/modelMap.xsd"
 	 project-version="10">
 	<property name="defaultPackage" value="org.apache.cayenne.testdo.inheritance_vertical"/>
 	<db-entity name="IV1_ROOT">
@@ -117,7 +117,7 @@
 		<obj-attribute name="attr1" type="java.lang.String" db-attribute-path="impl.ATTR1"/>
 		<obj-attribute name="attr2" type="java.lang.String" db-attribute-path="impl.ATTR2"/>
 	</obj-entity>
-	<obj-entity name="IvImplWithLock" superEntityName="IvBaseWithLock" className="org.apache.cayenne.testdo.inheritance_vertical.IvImplWithLock">
+	<obj-entity name="IvImplWithLock" superEntityName="IvBaseWithLock" className="org.apache.cayenne.testdo.inheritance_vertical.IvImplWithLock"
lock-type="optimistic">
 		<qualifier><![CDATA[type = "I"]]></qualifier>
 		<obj-attribute name="attr1" type="java.lang.String" db-attribute-path="impl.ATTR1"/>
 	</obj-entity>
diff --git a/cayenne-server/src/test/resources/testmap.map.xml b/cayenne-server/src/test/resources/testmap.map.xml
index 68539b6..442ce65 100644
--- a/cayenne-server/src/test/resources/testmap.map.xml
+++ b/cayenne-server/src/test/resources/testmap.map.xml
@@ -158,7 +158,7 @@
 	<obj-entity name="SubPainting" className="org.apache.cayenne.testdo.testmap.SubPainting"
dbEntityName="PAINTING">
 		<obj-attribute name="paintingTitle" type="java.lang.String" db-attribute-path="PAINTING_TITLE"/>
 	</obj-entity>
-	<db-relationship name="artistGroupArray" source="ARTGROUP" target="ARTIST_GROUP" toMany="true">
+	<db-relationship name="artistGroupArray" source="ARTGROUP" target="ARTIST_GROUP" toDependentPK="true"
toMany="true">
 		<db-attribute-pair source="GROUP_ID" target="GROUP_ID"/>
 	</db-relationship>
 	<db-relationship name="toChildGroups" source="ARTGROUP" target="ARTGROUP" toMany="true">
@@ -170,7 +170,7 @@
 	<db-relationship name="artistExhibitArray" source="ARTIST" target="ARTIST_EXHIBIT" toDependentPK="true"
toMany="true">
 		<db-attribute-pair source="ARTIST_ID" target="ARTIST_ID"/>
 	</db-relationship>
-	<db-relationship name="artistGroupArray" source="ARTIST" target="ARTIST_GROUP" toMany="true">
+	<db-relationship name="artistGroupArray" source="ARTIST" target="ARTIST_GROUP" toDependentPK="true"
toMany="true">
 		<db-attribute-pair source="ARTIST_ID" target="ARTIST_ID"/>
 	</db-relationship>
 	<db-relationship name="paintingArray" source="ARTIST" target="PAINTING" toMany="true">


Mime
View raw message