cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1098747 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextBinaryPKTest.java
Date Mon, 02 May 2011 19:13:17 GMT
Author: aadamchik
Date: Mon May  2 19:13:17 2011
New Revision: 1098747

URL: http://svn.apache.org/viewvc?rev=1098747&view=rev
Log:
CAY-1562 CayenneCase unit tests conversion

patches by Dzmitry Kazimirchyk:
DataContextBinaryPKTest + refactoring

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextBinaryPKTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextBinaryPKTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextBinaryPKTest.java?rev=1098747&r1=1098746&r2=1098747&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextBinaryPKTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextBinaryPKTest.java
Mon May  2 19:13:17 2011
@@ -19,68 +19,77 @@
 
 package org.apache.cayenne.access;
 
+import java.util.Arrays;
+
 import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.testdo.testmap.BinaryPKTest1;
 import org.apache.cayenne.testdo.testmap.BinaryPKTest2;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.AccessStackAdapter;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-/**
- */
-public class DataContextBinaryPKTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextBinaryPKTest extends ServerCase {
 
-    protected DataContext context;
+    @Inject
+    private DataContext context;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Inject
+    private DataContext context1;
+
+    @Inject
+    private AccessStackAdapter accessStackAdapter;
 
-        deleteTestData();
-        context = createDataContext();
+    @Inject
+    private DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("BINARY_PK_TEST2");
+        dbHelper.deleteAll("BINARY_PK_TEST1");
     }
 
     public void testInsertBinaryPK() throws Exception {
-        if (!getAccessStackAdapter().supportsBinaryPK()) {
-            return;
-        }
-
-        BinaryPKTest1 master = (BinaryPKTest1) context.newObject("BinaryPKTest1");
-        master.setName("master1");
+        if (accessStackAdapter.supportsBinaryPK()) {
 
-        BinaryPKTest2 detail = (BinaryPKTest2) context.newObject("BinaryPKTest2");
-        detail.setDetailName("detail2");
+            BinaryPKTest1 master = (BinaryPKTest1) context.newObject("BinaryPKTest1");
+            master.setName("master1");
 
-        master.addToBinaryPKDetails(detail);
+            BinaryPKTest2 detail = (BinaryPKTest2) context.newObject("BinaryPKTest2");
+            detail.setDetailName("detail2");
 
-        context.commitChanges();
+            master.addToBinaryPKDetails(detail);
 
+            context.commitChanges();
+        }
     }
 
     public void testFetchRelationshipBinaryPK() throws Exception {
-        if (!getAccessStackAdapter().supportsBinaryPK()) {
-            return;
-        }
+        if (accessStackAdapter.supportsBinaryPK()) {
 
-        BinaryPKTest1 master = (BinaryPKTest1) context.newObject("BinaryPKTest1");
-        master.setName("master1");
+            BinaryPKTest1 master = (BinaryPKTest1) context.newObject("BinaryPKTest1");
+            master.setName("master1");
 
-        BinaryPKTest2 detail = (BinaryPKTest2) context.newObject("BinaryPKTest2");
-        detail.setDetailName("detail2");
+            BinaryPKTest2 detail = (BinaryPKTest2) context.newObject("BinaryPKTest2");
+            detail.setDetailName("detail2");
 
-        master.addToBinaryPKDetails(detail);
+            master.addToBinaryPKDetails(detail);
 
-        context.commitChanges();
+            context.commitChanges();
+            context.invalidateObjects(Arrays.asList(master, detail));
 
-        // create new context
-        context = createDataContext();
-        BinaryPKTest2 fetchedDetail = (BinaryPKTest2) context.performQuery(
-                new SelectQuery(BinaryPKTest2.class)).get(0);
+            BinaryPKTest2 fetchedDetail = (BinaryPKTest2) context1.performQuery(
+                    new SelectQuery(BinaryPKTest2.class)).get(0);
 
-        assertNotNull(fetchedDetail.readPropertyDirectly("toBinaryPKMaster"));
+            assertNotNull(fetchedDetail.readPropertyDirectly("toBinaryPKMaster"));
 
-        BinaryPKTest1 fetchedMaster = fetchedDetail.getToBinaryPKMaster();
-        assertNotNull(fetchedMaster);
-        assertEquals(PersistenceState.HOLLOW, fetchedMaster.getPersistenceState());
-        assertEquals("master1", fetchedMaster.getName());
+            BinaryPKTest1 fetchedMaster = fetchedDetail.getToBinaryPKMaster();
+            assertNotNull(fetchedMaster);
+            assertEquals(PersistenceState.HOLLOW, fetchedMaster.getPersistenceState());
+            assertEquals("master1", fetchedMaster.getName());
+        }
     }
 }



Mime
View raw message