cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1126105 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java
Date Sun, 22 May 2011 17:19:40 GMT
Author: aadamchik
Date: Sun May 22 17:19:40 2011
New Revision: 1126105

URL: http://svn.apache.org/viewvc?rev=1126105&view=rev
Log:
unit test refactoring

porting test to DI

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

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java?rev=1126105&r1=1126104&r2=1126105&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java
Sun May 22 17:19:40 2011
@@ -19,29 +19,40 @@
 
 package org.apache.cayenne.util;
 
-import java.util.Iterator;
-
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.testdo.inherit.Department;
 import org.apache.cayenne.testdo.inherit.Employee;
 import org.apache.cayenne.testdo.inherit.Manager;
-import org.apache.cayenne.unit.PeopleCase;
-import org.apache.cayenne.util.DeepMergeOperation;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
+import org.apache.cayenne.unit.di.UnitTestClosure;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class DeepMergeOperationInheritanceTest extends PeopleCase {
+@UseServerRuntime(ServerCase.PEOPLE_PROJECT)
+public class DeepMergeOperationInheritanceTest extends ServerCase {
 
-    public void testDeepMergeExistingSubclass() {
+    @Inject
+    private EntityResolver resolver;
+
+    @Inject
+    private DataContext context;
 
-        ClassDescriptor d = getDomain().getEntityResolver().getClassDescriptor(
-                "Department");
+    @Inject
+    private DataContext context1;
+
+    @Inject
+    protected DataChannelInterceptor queryInterceptor;
+
+    public void testDeepMergeExistingSubclass() {
 
-        DataContext context = createDataContext();
-        DataContext context1 = createDataContext();
+        final ClassDescriptor d = resolver.getClassDescriptor("Department");
 
-        Department d1 = context.newObject(Department.class);
+        final Department d1 = context.newObject(Department.class);
         d1.setName("D1");
 
         // need to do double commit as Ashwood sorter blows on Employees/Departments
@@ -67,38 +78,33 @@ public class DeepMergeOperationInheritan
         // resolve Employees
         context1.performQuery(new SelectQuery(Employee.class));
 
-        DeepMergeOperation op = new DeepMergeOperation(context1);
+        final DeepMergeOperation op = new DeepMergeOperation(context1);
 
-        blockQueries();
-        try {
-            Department d2 = (Department) op.merge(d1, d);
-            assertNotNull(d2);
-            assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
-
-            Iterator it = d2.getEmployees().iterator();
-            while (it.hasNext()) {
-                Employee ex = (Employee) it.next();
-                if ("E2".equals(ex.getName())) {
-                    assertTrue(ex instanceof Manager);
-                }
-                else {
-                    assertFalse(ex instanceof Manager);
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                Department d2 = (Department) op.merge(d1, d);
+                assertNotNull(d2);
+                assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
+
+                for (Employee ex : d2.getEmployees()) {
+                    if ("E2".equals(ex.getName())) {
+                        assertTrue(ex instanceof Manager);
+                    }
+                    else {
+                        assertFalse(ex instanceof Manager);
+                    }
                 }
             }
-        }
-        finally {
-            unblockQueries();
-        }
+        });
+
     }
 
     public void testDeepMergeNonExistentSubclass() {
 
-        ClassDescriptor d = getDomain().getEntityResolver().getClassDescriptor(
-                "Department");
-        DataContext context = createDataContext();
-        DataContext context1 = createDataContext();
+        final ClassDescriptor d = resolver.getClassDescriptor("Department");
 
-        Department d1 = context.newObject(Department.class);
+        final Department d1 = context.newObject(Department.class);
         d1.setName("D1");
 
         // need to do double commit as Ashwood sorter blows on Employees/Departments
@@ -120,27 +126,24 @@ public class DeepMergeOperationInheritan
         // need to make sure source relationship is resolved as a result of some Ashwood
         // strangeness...
         d1.getEmployees().size();
-        DeepMergeOperation op = new DeepMergeOperation(context1);
+        final DeepMergeOperation op = new DeepMergeOperation(context1);
 
-        blockQueries();
-        try {
-            Department d2 = (Department) op.merge(d1, d);
-            assertNotNull(d2);
-            assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
-
-            Iterator it = d2.getEmployees().iterator();
-            while (it.hasNext()) {
-                Employee ex = (Employee) it.next();
-                if ("E2".equals(ex.getName())) {
-                    assertTrue(ex instanceof Manager);
-                }
-                else {
-                    assertFalse(ex instanceof Manager);
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                Department d2 = (Department) op.merge(d1, d);
+                assertNotNull(d2);
+                assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
+
+                for (Employee ex : d2.getEmployees()) {
+                    if ("E2".equals(ex.getName())) {
+                        assertTrue(ex instanceof Manager);
+                    }
+                    else {
+                        assertFalse(ex instanceof Manager);
+                    }
                 }
             }
-        }
-        finally {
-            unblockQueries();
-        }
+        });
     }
 }



Mime
View raw message