cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r954463 [1/2] - in /cayenne/main/trunk: build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/ framework/cayenne-jdk1.5-unpublished/src/main/java/...
Date Mon, 14 Jun 2010 13:40:51 GMT
Author: aadamchik
Date: Mon Jun 14 13:40:50 2010
New Revision: 954463

URL: http://svn.apache.org/viewvc?rev=954463&view=rev
Log:
DI-enabled unit tests

* implementing DataNode injection
* implementing closure-based query blocker
* switching test stacks to the new injectable testing:
	testmap (partial switch, as it is huge)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtras1Test.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestClosure.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesAccessStackAdapterProvider.java
      - copied, changed from r954459, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryBase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryBlocker.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryBlocker.java
      - copied, changed from r954459, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryBase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataNodeProvider.java
      - copied, changed from r954459, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryBase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-testmap.xml
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryBase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/CAY_788Test.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextEJBQLArrayResultTest.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextEJBQLDeleteTest.xml
Modified:
    cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLArrayResultTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextNoPkTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/IdentityColumnsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataDomainProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-default.xml

Modified: cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java (original)
+++ cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java Mon Jun 14 13:40:50 2010
@@ -46,6 +46,10 @@ public class TableHelper {
         dbHelper.deleteAll(tableName);
         return this;
     }
+    
+    public String getTableName() {
+        return tableName;
+    }
 
     /**
      * Sets columns that will be implicitly used in subsequent inserts and selects.

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java (original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java Mon Jun 14 13:40:50 2010
@@ -30,14 +30,15 @@ public interface Injector {
 
     /**
      * Returns a service instance bound in the container for a specific type. Throws
-     * {@link DIException} if the type is not bound, or an instance can not be created.
+     *{@link ConfigurationException} if the type is not bound, or an instance can not be
+     * created.
      */
     <T> T getInstance(Class<T> type) throws ConfigurationException;
 
     /**
      * Returns a service instance bound in the container for a specific binding key.
-     * Throws {@link DIException} if the key is not bound, or an instance can not be
-     * created.
+     * Throws {@link ConfigurationException} if the key is not bound, or an instance can
+     * not be created.
      */
     <T> T getInstance(Key<T> key) throws ConfigurationException;
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java Mon Jun 14 13:40:50 2010
@@ -79,7 +79,7 @@ public class DataDomainProvider implemen
     public DataDomain get() throws ConfigurationException {
 
         try {
-            return createDataDomain();
+            return createAndInitDataDomain();
         }
         catch (ConfigurationException e) {
             throw e;
@@ -89,8 +89,12 @@ public class DataDomainProvider implemen
                     .getMessage());
         }
     }
+    
+    protected DataDomain createDataDomain(String name) {
+        return new DataDomain(name);
+    }
 
-    protected DataDomain createDataDomain() throws Exception {
+    protected DataDomain createAndInitDataDomain() throws Exception {
         String configurationLocation = configurationProperties
                 .get(ServerModule.CONFIGURATION_LOCATION);
 
@@ -144,7 +148,7 @@ public class DataDomainProvider implemen
         }
 
         DataChannelDescriptor descriptor = tree.getRootNode();
-        DataDomain dataDomain = new DataDomain(descriptor.getName());
+        DataDomain dataDomain = createDataDomain(descriptor.getName());
         injector.injectMembers(dataDomain);
 
         dataDomain.initWithProperties(descriptor.getProperties());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLArrayResultTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLArrayResultTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLArrayResultTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLArrayResultTest.java Mon Jun 14 13:40:50 2010
@@ -21,26 +21,56 @@ package org.apache.cayenne.access;
 import java.math.BigDecimal;
 import java.util.List;
 
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class DataContextEJBQLArrayResultTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextEJBQLArrayResultTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
 
     @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        deleteTestData();
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST");
+
+        TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+        tArtist.insert(33001, "AA1");
+        tArtist.insert(33002, "AA2");
+        tArtist.insert(33003, "BB1");
+        tArtist.insert(33004, "BB2");
+
+        TableHelper tPainting = new TableHelper(dbHelper, "PAINTING");
+        tPainting.setColumns(
+                "PAINTING_ID",
+                "ARTIST_ID",
+                "PAINTING_TITLE",
+                "ESTIMATED_PRICE");
+        tPainting.insert(33001, 33001, "P1", 3000);
+        tPainting.insert(33002, 33002, "P2", 5000);
+        tPainting.insert(33003, null, "P3", 5000);
     }
 
     public void testSQLResultSetMappingScalar() throws Exception {
-        createTestData("prepare");
 
         String ejbql = "SELECT count(p) FROM Painting p JOIN p.toArtist a";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        List objects = createDataContext().performQuery(query);
+        List objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Object o1 = objects.get(0);
@@ -48,13 +78,12 @@ public class DataContextEJBQLArrayResult
     }
 
     public void testSQLResultSetMappingScalars() throws Exception {
-        createTestData("prepare");
 
         String ejbql = "SELECT count(p), sum(p.estimatedPrice) FROM Painting p JOIN p.toArtist a";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        List objects = createDataContext().performQuery(query);
+        List objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Object o1 = objects.get(0);
@@ -67,7 +96,6 @@ public class DataContextEJBQLArrayResult
     }
 
     public void testSQLResultSetMappingMixed() throws Exception {
-        createTestData("prepare");
 
         String ejbql = "SELECT count(p), a, sum(p.estimatedPrice) "
                 + "FROM Artist a LEFT JOIN a.paintingArray p "
@@ -75,7 +103,7 @@ public class DataContextEJBQLArrayResult
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        List objects = createDataContext().performQuery(query);
+        List objects = context.performQuery(query);
         assertEquals(4, objects.size());
 
         Object o1 = objects.get(0);
@@ -87,4 +115,5 @@ public class DataContextEJBQLArrayResult
         assertTrue("Expected Artist, got: " + array1[1], array1[1] instanceof Artist);
         assertEquals(0, new BigDecimal(3000).compareTo((BigDecimal) array1[2]));
     }
+
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java Mon Jun 14 13:40:50 2010
@@ -28,23 +28,82 @@ import java.util.Set;
 import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.Persistent;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class DataContextEJBQLConditionsTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextEJBQLConditionsTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    protected TableHelper tArtist;
+    protected TableHelper tPainting;
 
     @Override
-    protected void setUp() throws Exception {
-        deleteTestData();
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+        tPainting = new TableHelper(dbHelper, "PAINTING");
+        tPainting.setColumns(
+                "PAINTING_ID",
+                "ARTIST_ID",
+                "PAINTING_TITLE",
+                "ESTIMATED_PRICE");
     }
 
-    public void testDateParameter() throws Exception {
-        createTestData("prepareCollection");
+    protected void createCollectionDataSet() throws Exception {
+        tArtist.insert(33001, "B");
+        tArtist.insert(33002, "A");
+        tArtist.insert(33003, "D");
+
+        tPainting.insert(33009, 33001, "X", 5000);
+        tPainting.insert(33010, 33001, "Y", 5000);
+        tPainting.insert(33011, 33002, "Z", 5000);
+    }
 
-        ObjectContext context = createDataContext();
+    protected void createLikeDataSet() throws Exception {
+        tPainting.insert(33001, null, "ABAAC", 3000);
+        tPainting.insert(33002, null, "ADDDD", 4000);
+        tPainting.insert(33003, null, "BDDDD", 5000);
+        tPainting.insert(33004, null, "BBDDDD", 5000);
+        tPainting.insert(33005, null, "_DDDD", 5000);
+    }
+
+    protected void createGreaterThanDataSet() throws Exception {
+        createLikeDataSet();
+    }
+
+    protected void createInDataSet() throws Exception {
+        tPainting.insert(33006, null, "A", 5000);
+        tPainting.insert(33007, null, "B", 5000);
+        tPainting.insert(33008, null, "C", 5000);
+    }
+
+    protected void createInSubqueryDataSet() throws Exception {
+        tPainting.insert(33012, null, "C", 5000);
+        tPainting.insert(33013, null, "D", 5000);
+        tPainting.insert(33014, null, "C", 5000);
+    }
+
+    public void testDateParameter() throws Exception {
+        createCollectionDataSet();
 
         SelectQuery q = new SelectQuery(Artist.class);
         List<Artist> allArtists = context.performQuery(q);
@@ -64,7 +123,7 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testArithmetics() throws Exception {
-        createTestData("prepareLike");
+        createLikeDataSet();
 
         // TODO: andrus 02/25/2008 - fails on HSQLDB / succeeds on MySQL. HSQLDB error is
         // "Unresolved parameter type : as both operands of aritmetic operator in
@@ -89,12 +148,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testLike1() throws Exception {
-        createTestData("prepareLike");
+        createLikeDataSet();
 
         String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'A%C'";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -108,12 +167,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testNotLike() throws Exception {
-        createTestData("prepareLike");
+        createLikeDataSet();
 
         String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle NOT LIKE 'A%C'";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(4, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -127,12 +186,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testLike2() throws Exception {
-        createTestData("prepareLike");
+        createLikeDataSet();
 
         String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE '_DDDD'";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(3, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -148,12 +207,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testLikeEscape() throws Exception {
-        createTestData("prepareLike");
+        createLikeDataSet();
 
         String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'X_DDDD' ESCAPE 'X'";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -167,12 +226,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testIn() throws Exception {
-        createTestData("prepareIn");
+        createInDataSet();
 
         String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle IN ('A', 'B')";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(2, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -187,12 +246,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testNotIn() throws Exception {
-        createTestData("prepareIn");
+        createInDataSet();
 
         String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle NOT IN ('A', 'B')";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -206,14 +265,14 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testInSubquery() throws Exception {
-        createTestData("prepareInSubquery");
+        createInSubqueryDataSet();
 
         String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle IN ("
                 + "SELECT p1.paintingTitle FROM Painting p1 WHERE p1.paintingTitle = 'C'"
                 + ")";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(2, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -228,12 +287,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testCollectionEmpty() throws Exception {
-        createTestData("prepareCollection");
+        createCollectionDataSet();
 
         String ejbql = "SELECT a FROM Artist a WHERE a.paintingArray IS EMPTY";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -247,12 +306,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testCollectionNotEmpty() throws Exception {
-        createTestData("prepareCollection");
+        createCollectionDataSet();
 
         String ejbql = "SELECT a FROM Artist a WHERE a.paintingArray IS NOT EMPTY";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(2, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -267,12 +326,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testCollectionNotEmptyExplicitDistinct() throws Exception {
-        createTestData("prepareCollection");
+        createCollectionDataSet();
 
         String ejbql = "SELECT DISTINCT a FROM Artist a WHERE a.paintingArray IS NOT EMPTY";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(2, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -287,17 +346,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testCollectionMemberOfParameter() throws Exception {
-        createTestData("prepareCollection");
+        createCollectionDataSet();
 
         String ejbql = "SELECT a FROM Artist a WHERE :x MEMBER OF a.paintingArray";
 
-        ObjectContext context = createDataContext();
-
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        query.setParameter("x", Cayenne.objectForPK(
-                context,
-                Painting.class,
-                33010));
+        query.setParameter("x", Cayenne.objectForPK(context, Painting.class, 33010));
         List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
@@ -312,12 +366,10 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testGreaterOrEquals() throws Exception {
-        createTestData("prepareGreaterThan");
+        createGreaterThanDataSet();
 
         String ejbql = "SELECT p FROM Painting p WHERE p.estimatedPrice >= :estimatedPrice";
 
-        ObjectContext context = createDataContext();
-
         EJBQLQuery query = new EJBQLQuery(ejbql);
         query.setParameter("estimatedPrice", new BigDecimal(4000));
         List<?> objects = context.performQuery(query);
@@ -325,12 +377,10 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testLessOrEquals() throws Exception {
-        createTestData("prepareGreaterThan");
+        createGreaterThanDataSet();
 
         String ejbql = "SELECT p FROM Painting p WHERE p.estimatedPrice <= :estimatedPrice";
 
-        ObjectContext context = createDataContext();
-
         EJBQLQuery query = new EJBQLQuery(ejbql);
         query.setParameter("estimatedPrice", new BigDecimal(4000));
         List<?> objects = context.performQuery(query);
@@ -338,17 +388,12 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testCollectionNotMemberOfParameter() throws Exception {
-        createTestData("prepareCollection");
+        createCollectionDataSet();
 
         String ejbql = "SELECT a FROM Artist a WHERE :x NOT MEMBER a.paintingArray";
 
-        ObjectContext context = createDataContext();
-
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        query.setParameter("x", Cayenne.objectForPK(
-                context,
-                Painting.class,
-                33010));
+        query.setParameter("x", Cayenne.objectForPK(context, Painting.class, 33010));
         List<?> objects = context.performQuery(query);
         assertEquals(2, objects.size());
 
@@ -364,13 +409,13 @@ public class DataContextEJBQLConditionsT
     }
 
     public void testCollectionMemberOfThetaJoin() throws Exception {
-        createTestData("prepareCollection");
+        createCollectionDataSet();
 
         String ejbql = "SELECT p FROM Painting p, Artist a "
                 + "WHERE p MEMBER OF a.paintingArray AND a.artistName = 'B'";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<?> objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(2, objects.size());
 
         Set<Object> ids = new HashSet<Object>();
@@ -383,4 +428,5 @@ public class DataContextEJBQLConditionsT
         assertTrue(ids.contains(new Integer(33009)));
         assertTrue(ids.contains(new Integer(33010)));
     }
+
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java Mon Jun 14 13:40:50 2010
@@ -21,29 +21,70 @@ package org.apache.cayenne.access;
 import java.util.List;
 
 import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.EJBQLQuery;
-import org.apache.cayenne.testdo.testmap.MeaningfulPKTest1;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.ServerRuntimeFactory;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextEJBQLDeleteTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Inject
+    protected ServerRuntimeFactory runtimeFactory;
+
+    protected TableHelper tPainting;
+
+    protected TableHelper tMeaningfulPKTest1Table;
 
-public class DataContextEJBQLDeleteTest extends CayenneCase {
-    
-    protected DataContext context;
-    
     @Override
-    protected void setUp() throws Exception {
-        deleteTestData();
-        context = createDataContext();
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST");
+
+        tPainting = new TableHelper(dbHelper, "PAINTING");
+        tPainting.setColumns(
+                "PAINTING_ID",
+                "ARTIST_ID",
+                "PAINTING_TITLE",
+                "ESTIMATED_PRICE");
+
+        tMeaningfulPKTest1Table = new TableHelper(dbHelper, "MEANINGFUL_PK_TEST1");
+        tMeaningfulPKTest1Table.setColumns("PK_ATTRIBUTE", "DESCR");
+    }
+
+    protected void createPaintingsDataSet() throws Exception {
+        tPainting.insert(33001, null, "P1", 3000);
+        tPainting.insert(33002, null, "P2", 5000);
+    }
+
+    protected void createMeaningfulPKDataSet() throws Exception {
+
+        for (int i = 1; i <= 33; i++) {
+            tMeaningfulPKTest1Table.insert(i, "a" + i);
+        }
     }
-    
+
     public void testDeleteNoIdVar() throws Exception {
-        createTestData("prepare");
+        createPaintingsDataSet();
 
         String ejbql = "delete from Painting";
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        QueryResponse result = createDataContext().performGenericQuery(query);
+        QueryResponse result = context.performGenericQuery(query);
 
         int[] count = result.firstUpdateCount();
         assertNotNull(count);
@@ -52,12 +93,12 @@ public class DataContextEJBQLDeleteTest 
     }
 
     public void testDeleteNoQualifier() throws Exception {
-        createTestData("prepare");
+        createPaintingsDataSet();
 
         String ejbql = "delete from Painting AS p";
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        QueryResponse result = createDataContext().performGenericQuery(query);
+        QueryResponse result = context.performGenericQuery(query);
 
         int[] count = result.firstUpdateCount();
         assertNotNull(count);
@@ -66,52 +107,41 @@ public class DataContextEJBQLDeleteTest 
     }
 
     public void testDeleteSameEntityQualifier() throws Exception {
-        createTestData("prepare");
+        createPaintingsDataSet();
 
         String ejbql = "delete from Painting AS p WHERE p.paintingTitle = 'P2'";
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        QueryResponse result = createDataContext().performGenericQuery(query);
+        QueryResponse result = context.performGenericQuery(query);
 
         int[] count = result.firstUpdateCount();
         assertNotNull(count);
         assertEquals(1, count.length);
         assertEquals(1, count[0]);
 
-        assertNotNull(Cayenne
-                .objectForPK(createDataContext(), Painting.class, 33001));
-        assertNull(Cayenne
-                .objectForPK(createDataContext(), Painting.class, 33002));
+        ObjectContext freshContext = runtimeFactory.get(TESTMAP_PROJECT).getContext();
+
+        assertNotNull(Cayenne.objectForPK(freshContext, Painting.class, 33001));
+        assertNull(Cayenne.objectForPK(freshContext, Painting.class, 33002));
     }
-    
+
     public void testDeleteIdVar() throws Exception {
-        insertValue();
-        
+
+        createMeaningfulPKDataSet();
+
         EJBQLQuery q = new EJBQLQuery("select m.pkAttribute from MeaningfulPKTest1 m");
-    
-        List<Integer> id = createDataContext().performQuery(q);
-       
+
+        List<Integer> id = context.performQuery(q);
+
         String ejbql = "delete from MeaningfulPKTest1 m WHERE m.pkAttribute in (:id)";
-         
+
         EJBQLQuery query = new EJBQLQuery(ejbql);
         query.setParameter("id", id);
-        QueryResponse result = createDataContext().performGenericQuery(query);
-    
+        QueryResponse result = context.performGenericQuery(query);
+
         int[] count = result.firstUpdateCount();
         assertNotNull(count);
         assertEquals(1, count.length);
-        assertEquals(420, count[0]);
-
-    }
-    
-    public void insertValue(){
-        MeaningfulPKTest1 obj ;
-        
-        for(int i=0;i<420;i++){
-            obj = (MeaningfulPKTest1) context.newObject("MeaningfulPKTest1");
-            obj.setPkAttribute(new Integer(i));
-            obj.setDescr("a" + i);
-            context.commitChanges();
-        }
+        assertEquals(33, count[0]);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java Mon Jun 14 13:40:50 2010
@@ -18,448 +18,395 @@
  ****************************************************************/
 package org.apache.cayenne.access;
 
-import java.math.BigDecimal;
-import java.sql.Connection;
 import java.sql.Date;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.ArtistExhibit;
 import org.apache.cayenne.testdo.testmap.Gallery;
 import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.UnitTestClosure;
+import org.apache.cayenne.unit.di.server.DataChannelQueryBlocker;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextEJBQLFetchJoinTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Inject
+    protected DataChannelQueryBlocker queryBlocker;
+
+    protected TableHelper tArtist;
+    protected TableHelper tPainting;
+    protected TableHelper tGallery;
+    protected TableHelper tExhibit;
+    protected TableHelper tArtistExhibit;
 
-public class DataContextEJBQLFetchJoinTest extends CayenneCase {
-    public static final String INSERT_ARTIST = "INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES (?,?)";
-    public static final String INSERT_PAINTING = "INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) VALUES (?, ?, ?, ?)";
-    public static final String INSERT_GALLERY = "INSERT INTO GALLERY (GALLERY_ID, GALLERY_NAME) VALUES (?,?)";
-    public static final String INSERT_EXIBIT = "INSERT INTO EXHIBIT (EXHIBIT_ID, GALLERY_ID, CLOSING_DATE, OPENING_DATE) VALUES (?, ?, ?, ?)";
-    public static final String INSERT_ARTIST_EXIBIT = "INSERT INTO ARTIST_EXHIBIT (ARTIST_ID, EXHIBIT_ID) VALUES (?, ?)";
-
-    Connection conn; 
     @Override
-    protected void setUp() throws Exception {
-        deleteTestData();
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST");
+        dbHelper.deleteAll("EXHIBIT");
+        dbHelper.deleteAll("GALLERY");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+        tPainting = new TableHelper(dbHelper, "PAINTING");
+        tPainting.setColumns(
+                "PAINTING_ID",
+                "ARTIST_ID",
+                "PAINTING_TITLE",
+                "ESTIMATED_PRICE");
+
+        tGallery = new TableHelper(dbHelper, "GALLERY");
+        tGallery.setColumns("GALLERY_ID", "GALLERY_NAME");
+
+        tExhibit = new TableHelper(dbHelper, "EXHIBIT");
+        tExhibit.setColumns("EXHIBIT_ID", "GALLERY_ID", "CLOSING_DATE", "OPENING_DATE");
+
+        tArtistExhibit = new TableHelper(dbHelper, "ARTIST_EXHIBIT");
+        tArtistExhibit.setColumns("ARTIST_ID", "EXHIBIT_ID");
     }
 
-    private void populateTables(TestData data) throws Exception {
-                
-        Object[][] artistsData = {
-                {1, "A1"},
-                {2, "A2"},
-                {3, "A3"}
-        };
-        Object[][] paintingsData = {
-                {1, "P11", 1, new BigDecimal(3000d)},
-                {2, "P2", 2, new BigDecimal(5000d)},
-                {3, "P12", 1, new BigDecimal(3000d)}
-        };
-        Object[][] galleriesData = {
-                {1, "gallery1"},
-                {2, "gallery2"}
-        };
-        Object[][] exibitsData = {
-                {1, 1, new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 1), new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 2)},
-                {2, 1, new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 3), new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 4)}
-        };
-        Object[][] artistExibitsData = {
-                {1, 1},
-                {1, 2}
-        };
-        conn = getConnection();
-        try {
-            conn.setAutoCommit(false);
-
-            switch (data) {
-                case ONE_ENTITY_FETCH_JOIN:
-                    insertArtists(artistsData);
-                    insertPaintings(paintingsData);
-                    break;
-                case SEVERAL_FETCH_JOINS:
-                    insertArtists(artistsData);
-                    insertPaintings(paintingsData);
-                    insertGalleries(galleriesData);
-                    insertExibits(exibitsData);
-                    insertArtistExibits(artistExibitsData);
-                    break;
-            }
+    protected void createOneFetchJoinDataSet() throws Exception {
+        tArtist.insert(1, "A1");
+        tArtist.insert(2, "A2");
+        tArtist.insert(3, "A3");
+
+        tPainting.insert(1, 1, "P11", 3000d);
+        tPainting.insert(2, 2, "P2", 5000d);
+        tPainting.insert(3, 1, "P12", 3000d);
+    }
+
+    protected void createMultipleFetchJoinsDataSet() throws Exception {
+        createOneFetchJoinDataSet();
+
+        tGallery.insert(1, "gallery1");
+        tGallery.insert(2, "gallery2");
+
+        long t = System.currentTimeMillis();
 
-        }
-        finally {
-            conn.close();
-        }
+        tExhibit.insert(1, 1, new Date(1 + 10000), new Date(t + 20000));
+        tExhibit.insert(2, 1, new Date(1 + 30000), new Date(t + 40000));
 
+        tArtistExhibit.insert(1, 1);
+        tArtistExhibit.insert(1, 2);
     }
 
-    
     public void testFetchJoinForOneEntity() throws Exception {
-        populateTables(TestData.ONE_ENTITY_FETCH_JOIN);
+        createOneFetchJoinDataSet();
+
         String ejbql = "SELECT a FROM Artist a JOIN FETCH a.paintingArray ";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        DataContext context = createDataContext();
+        final List objects = context.performQuery(query);
 
-        List objects = context.performQuery(query);
+        queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
 
-        blockQueries();
-        try {
-            assertEquals(2, objects.size());
+            public void execute() {
 
-            Iterator it = objects.iterator();
-            while (it.hasNext()) {
-                Artist a = (Artist) it.next();
-                List list = a.getPaintingArray();
+                assertEquals(2, objects.size());
 
-                assertNotNull(list);
-                assertFalse(((ValueHolder) list).isFault());
+                Iterator it = objects.iterator();
+                while (it.hasNext()) {
+                    Artist a = (Artist) it.next();
+                    List list = a.getPaintingArray();
 
-                Iterator children = list.iterator();
-                while (children.hasNext()) {
-                    Painting p = (Painting) children.next();
-                    assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
-                    // make sure properties are not null..
-                    assertNotNull(p.getPaintingTitle());
+                    assertNotNull(list);
+                    assertFalse(((ValueHolder) list).isFault());
+
+                    Iterator children = list.iterator();
+                    while (children.hasNext()) {
+                        Painting p = (Painting) children.next();
+                        assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
+                        // make sure properties are not null..
+                        assertNotNull(p.getPaintingTitle());
+                    }
                 }
             }
-        }
-        finally {
-            unblockQueries();
-        }
+        });
     }
 
     public void testSeveralFetchJoins() throws Exception {
-        populateTables(TestData.SEVERAL_FETCH_JOINS);
+        createMultipleFetchJoinsDataSet();
+
         String ejbql = "SELECT a "
                 + "FROM Artist a JOIN FETCH a.paintingArray JOIN FETCH a.artistExhibitArray "
                 + "WHERE a.artistName = 'A1'";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        DataContext context = createDataContext();
+        final List objects = context.performQuery(query);
 
-        List objects = context.performQuery(query);
+        queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
 
-        blockQueries();
-        try {
-            assertEquals(1, objects.size());
+            public void execute() {
 
-            Artist a = (Artist) objects.get(0);
-            assertEquals("A1", a.getArtistName());
+                assertEquals(1, objects.size());
 
-            List<Painting> paintings = a.getPaintingArray();
+                Artist a = (Artist) objects.get(0);
+                assertEquals("A1", a.getArtistName());
 
-            assertNotNull(paintings);
-            assertFalse(((ValueHolder) paintings).isFault());
-            assertEquals(2, paintings.size());
+                List<Painting> paintings = a.getPaintingArray();
 
-            List<String> expectedPaintingsNames = new ArrayList<String>();
-            expectedPaintingsNames.add("P11");
-            expectedPaintingsNames.add("P12");
+                assertNotNull(paintings);
+                assertFalse(((ValueHolder) paintings).isFault());
+                assertEquals(2, paintings.size());
 
-            Iterator<Painting> paintingsIterator = paintings.iterator();
-            while (paintingsIterator.hasNext()) {
-                Painting p = paintingsIterator.next();
-                assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
-                assertNotNull(p.getPaintingTitle());
-                assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
-            }
+                List<String> expectedPaintingsNames = new ArrayList<String>();
+                expectedPaintingsNames.add("P11");
+                expectedPaintingsNames.add("P12");
 
-            List<ArtistExhibit> exibits = a.getArtistExhibitArray();
+                Iterator<Painting> paintingsIterator = paintings.iterator();
+                while (paintingsIterator.hasNext()) {
+                    Painting p = paintingsIterator.next();
+                    assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
+                    assertNotNull(p.getPaintingTitle());
+                    assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
+                }
 
-            assertNotNull(exibits);
-            assertFalse(((ValueHolder) exibits).isFault());
-            assertEquals(2, exibits.size());
-
-            Iterator<ArtistExhibit> exibitsIterator = exibits.iterator();
-            while (exibitsIterator.hasNext()) {
-                ArtistExhibit ae = exibitsIterator.next();
-                assertEquals(PersistenceState.COMMITTED, ae.getPersistenceState());
-                assertNotNull(ae.getObjectId());
+                List<ArtistExhibit> exibits = a.getArtistExhibitArray();
 
-            }
+                assertNotNull(exibits);
+                assertFalse(((ValueHolder) exibits).isFault());
+                assertEquals(2, exibits.size());
+
+                Iterator<ArtistExhibit> exibitsIterator = exibits.iterator();
+                while (exibitsIterator.hasNext()) {
+                    ArtistExhibit ae = exibitsIterator.next();
+                    assertEquals(PersistenceState.COMMITTED, ae.getPersistenceState());
+                    assertNotNull(ae.getObjectId());
 
-        }
-        finally {
-            unblockQueries();
-        }
+                }
+            }
+        });
     }
 
     public void testSeveralEntitiesFetchJoins() throws Exception {
-        populateTables(TestData.SEVERAL_FETCH_JOINS);
+        createMultipleFetchJoinsDataSet();
+
         String ejbql = "SELECT DISTINCT a , g "
                 + "FROM Artist a JOIN FETCH a.paintingArray , Gallery g JOIN FETCH g.exhibitArray "
                 + "WHERE a.artistName='A1' AND g.galleryName='gallery1'";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        DataContext context = createDataContext();
+        final List objects = context.performQuery(query);
+
+        queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
 
-        List objects = context.performQuery(query);
+            public void execute() {
 
-        blockQueries();
-        try {
-            assertNotNull(objects);
-            assertFalse(objects.isEmpty());
-            assertEquals(1, objects.size());
-        }
-        finally {
-            unblockQueries();
-        }
+                assertNotNull(objects);
+                assertFalse(objects.isEmpty());
+                assertEquals(1, objects.size());
+            }
+        });
     }
 
     public void testSeveralEntitiesAndScalarFetchInnerJoins() throws Exception {
-        populateTables(TestData.SEVERAL_FETCH_JOINS);
+        createMultipleFetchJoinsDataSet();
+
         String ejbql = "SELECT DISTINCT a, a.artistName , g "
                 + "FROM Artist a JOIN FETCH a.paintingArray, Gallery g JOIN FETCH g.exhibitArray "
                 + "ORDER BY a.artistName";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        DataContext context = createDataContext();
+        final List objects = context.performQuery(query);
 
-        List objects = context.performQuery(query);
+        queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
 
-        blockQueries();
-        try {
-            assertEquals(2, objects.size());
+            public void execute() {
 
-            Object[] firstRow = (Object[]) objects.get(0);
-            Artist a = (Artist) firstRow[0];
-            assertEquals("A1", a.getArtistName());
+                assertEquals(2, objects.size());
 
-            List<Painting> paintings = a.getPaintingArray();
+                Object[] firstRow = (Object[]) objects.get(0);
+                Artist a = (Artist) firstRow[0];
+                assertEquals("A1", a.getArtistName());
 
-            assertNotNull(paintings);
-            assertFalse(((ValueHolder) paintings).isFault());
-            assertEquals(2, paintings.size());
+                List<Painting> paintings = a.getPaintingArray();
 
-            List<String> expectedPaintingsNames = new ArrayList<String>();
-            expectedPaintingsNames.add("P11");
-            expectedPaintingsNames.add("P12");
+                assertNotNull(paintings);
+                assertFalse(((ValueHolder) paintings).isFault());
+                assertEquals(2, paintings.size());
 
-            Iterator<Painting> paintingsIterator = paintings.iterator();
-            while (paintingsIterator.hasNext()) {
-                Painting p = paintingsIterator.next();
-                assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
-                assertNotNull(p.getPaintingTitle());
-                assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
-            }
-            String artistName = (String) firstRow[1];
-            assertEquals("A1", artistName);
+                List<String> expectedPaintingsNames = new ArrayList<String>();
+                expectedPaintingsNames.add("P11");
+                expectedPaintingsNames.add("P12");
 
-            Gallery g1 = (Gallery) firstRow[2];
-            assertEquals("gallery1", g1.getGalleryName());
+                Iterator<Painting> paintingsIterator = paintings.iterator();
+                while (paintingsIterator.hasNext()) {
+                    Painting p = paintingsIterator.next();
+                    assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
+                    assertNotNull(p.getPaintingTitle());
+                    assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
+                }
+                String artistName = (String) firstRow[1];
+                assertEquals("A1", artistName);
 
-            List exibits = g1.getExhibitArray();
+                Gallery g1 = (Gallery) firstRow[2];
+                assertEquals("gallery1", g1.getGalleryName());
 
-            assertNotNull(exibits);
-            assertFalse(((ValueHolder) exibits).isFault());
-            assertEquals(2, exibits.size());
+                List exibits = g1.getExhibitArray();
 
-            Object[] secondRow = (Object[]) objects.get(1);
-            a = (Artist) secondRow[0];
-            assertEquals("A2", a.getArtistName());
+                assertNotNull(exibits);
+                assertFalse(((ValueHolder) exibits).isFault());
+                assertEquals(2, exibits.size());
 
-            paintings = a.getPaintingArray();
+                Object[] secondRow = (Object[]) objects.get(1);
+                a = (Artist) secondRow[0];
+                assertEquals("A2", a.getArtistName());
 
-            assertNotNull(paintings);
-            assertFalse(((ValueHolder) paintings).isFault());
-            assertEquals(1, paintings.size());
+                paintings = a.getPaintingArray();
 
-            expectedPaintingsNames = new ArrayList<String>();
-            expectedPaintingsNames.add("P2");
+                assertNotNull(paintings);
+                assertFalse(((ValueHolder) paintings).isFault());
+                assertEquals(1, paintings.size());
 
-            paintingsIterator = paintings.iterator();
-            while (paintingsIterator.hasNext()) {
-                Painting p = paintingsIterator.next();
-                assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
-                assertNotNull(p.getPaintingTitle());
-                assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
-            }
-            artistName = (String) secondRow[1];
-            assertEquals("A2", artistName);
+                expectedPaintingsNames = new ArrayList<String>();
+                expectedPaintingsNames.add("P2");
 
-            Gallery g2 = (Gallery) secondRow[2];
-            assertEquals(g1, g2);
-        }
-        finally {
-            unblockQueries();
-        }
+                paintingsIterator = paintings.iterator();
+                while (paintingsIterator.hasNext()) {
+                    Painting p = paintingsIterator.next();
+                    assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
+                    assertNotNull(p.getPaintingTitle());
+                    assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
+                }
+                artistName = (String) secondRow[1];
+                assertEquals("A2", artistName);
+
+                Gallery g2 = (Gallery) secondRow[2];
+                assertEquals(g1, g2);
+            }
+        });
     }
 
     public void testSeveralEntitiesAndScalarFetchOuterJoins() throws Exception {
-        populateTables(TestData.SEVERAL_FETCH_JOINS);
+        createMultipleFetchJoinsDataSet();
+
         String ejbql = "SELECT DISTINCT a, a.artistName , g "
                 + "FROM Artist a LEFT JOIN FETCH a.paintingArray, Gallery g LEFT JOIN FETCH g.exhibitArray "
                 + "ORDER BY a.artistName, g.galleryName";
 
         EJBQLQuery query = new EJBQLQuery(ejbql);
 
-        DataContext context = createDataContext();
+        final List objects = context.performQuery(query);
+        queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
 
-        List objects = context.performQuery(query);
+            public void execute() {
 
-        blockQueries();
-        try {
-            assertEquals(6, objects.size());
+                assertEquals(6, objects.size());
 
-            Object[] row = (Object[]) objects.get(0);
-            Artist a1 = (Artist) row[0];
-            assertEquals("A1", a1.getArtistName());
+                Object[] row = (Object[]) objects.get(0);
+                Artist a1 = (Artist) row[0];
+                assertEquals("A1", a1.getArtistName());
 
-            List<Painting> paintings = a1.getPaintingArray();
+                List<Painting> paintings = a1.getPaintingArray();
 
-            assertNotNull(paintings);
-            assertFalse(((ValueHolder) paintings).isFault());
-            assertEquals(2, paintings.size());
+                assertNotNull(paintings);
+                assertFalse(((ValueHolder) paintings).isFault());
+                assertEquals(2, paintings.size());
 
-            List<String> expectedPaintingsNames = new ArrayList<String>();
-            expectedPaintingsNames.add("P11");
-            expectedPaintingsNames.add("P12");
+                List<String> expectedPaintingsNames = new ArrayList<String>();
+                expectedPaintingsNames.add("P11");
+                expectedPaintingsNames.add("P12");
 
-            Iterator<Painting> paintingsIterator = paintings.iterator();
-            while (paintingsIterator.hasNext()) {
-                Painting p = paintingsIterator.next();
-                assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
-                assertNotNull(p.getPaintingTitle());
-                assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
-            }
-            String artistName1 = (String) row[1];
-            assertEquals("A1", artistName1);
-
-            Gallery g1 = (Gallery) row[2];
-            assertEquals("gallery1", g1.getGalleryName());
+                Iterator<Painting> paintingsIterator = paintings.iterator();
+                while (paintingsIterator.hasNext()) {
+                    Painting p = paintingsIterator.next();
+                    assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
+                    assertNotNull(p.getPaintingTitle());
+                    assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
+                }
+                String artistName1 = (String) row[1];
+                assertEquals("A1", artistName1);
 
-            List exibits = g1.getExhibitArray();
+                Gallery g1 = (Gallery) row[2];
+                assertEquals("gallery1", g1.getGalleryName());
 
-            assertNotNull(exibits);
-            assertFalse(((ValueHolder) exibits).isFault());
-            assertEquals(2, exibits.size());
+                List exibits = g1.getExhibitArray();
 
-            row = (Object[]) objects.get(1);
+                assertNotNull(exibits);
+                assertFalse(((ValueHolder) exibits).isFault());
+                assertEquals(2, exibits.size());
 
-            assertEquals(a1, (Artist) row[0]);
-            assertEquals(artistName1, row[1]);
+                row = (Object[]) objects.get(1);
 
-            Gallery g2 = (Gallery) row[2];
-            assertEquals("gallery2", g2.getGalleryName());
+                assertEquals(a1, row[0]);
+                assertEquals(artistName1, row[1]);
 
-            exibits = g2.getExhibitArray();
+                Gallery g2 = (Gallery) row[2];
+                assertEquals("gallery2", g2.getGalleryName());
 
-            assertTrue(exibits.isEmpty());
+                exibits = g2.getExhibitArray();
 
-            row = (Object[]) objects.get(2);
+                assertTrue(exibits.isEmpty());
 
-            Artist a2 = (Artist) row[0];
-            assertEquals("A2", a2.getArtistName());
+                row = (Object[]) objects.get(2);
 
-            paintings = a2.getPaintingArray();
+                Artist a2 = (Artist) row[0];
+                assertEquals("A2", a2.getArtistName());
 
-            assertNotNull(paintings);
-            assertEquals(1, paintings.size());
+                paintings = a2.getPaintingArray();
 
-            Painting p = paintings.get(0);
-            assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
-            assertNotNull(p.getPaintingTitle());
-            assertEquals("P2", p.getPaintingTitle());
+                assertNotNull(paintings);
+                assertEquals(1, paintings.size());
 
-            String artistName2 = (String) row[1];
-            assertEquals("A2", artistName2);
-            assertEquals(g1, row[2]);
+                Painting p = paintings.get(0);
+                assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
+                assertNotNull(p.getPaintingTitle());
+                assertEquals("P2", p.getPaintingTitle());
 
-            row = (Object[]) objects.get(3);
+                String artistName2 = (String) row[1];
+                assertEquals("A2", artistName2);
+                assertEquals(g1, row[2]);
 
-            assertEquals(a2, (Artist) row[0]);
-            assertEquals(artistName2, row[1]);
-            assertEquals(g2, row[2]);
+                row = (Object[]) objects.get(3);
 
-            row = (Object[]) objects.get(4);
+                assertEquals(a2, row[0]);
+                assertEquals(artistName2, row[1]);
+                assertEquals(g2, row[2]);
 
-            Artist a3 = (Artist) row[0];
-            assertEquals("A3", a3.getArtistName());
+                row = (Object[]) objects.get(4);
 
-            paintings = a3.getPaintingArray();
+                Artist a3 = (Artist) row[0];
+                assertEquals("A3", a3.getArtistName());
 
-            assertTrue(paintings.isEmpty());
+                paintings = a3.getPaintingArray();
 
-            String artistName3 = (String) row[1];
-            assertEquals("A3", artistName3);
-            assertEquals(g1, row[2]);
+                assertTrue(paintings.isEmpty());
 
-            row = (Object[]) objects.get(5);
+                String artistName3 = (String) row[1];
+                assertEquals("A3", artistName3);
+                assertEquals(g1, row[2]);
 
-            assertEquals(a3, (Artist) row[0]);
-            assertEquals(artistName3, row[1]);
-            assertEquals(g2, row[2]);
-        }
-        finally {
-            unblockQueries();
-        }
-    }
+                row = (Object[]) objects.get(5);
 
-    private void insertArtists(Object[][] artistsData) throws SQLException {
-        PreparedStatement stmt = conn.prepareStatement(INSERT_ARTIST);
-        for (int i = 0; i < artistsData.length; i++) {
-            stmt.setInt(1, (Integer)artistsData[i][0]);
-            stmt.setString(2, (String) artistsData[i][1]);
-            stmt.executeUpdate();
-        }
-        stmt.close();
-    }
-
-    private void insertPaintings(Object[][] paintingsData) throws SQLException {
-        PreparedStatement stmt = conn.prepareStatement(INSERT_PAINTING);
-        for (int i = 0; i < paintingsData.length; i++) {
-            stmt.setInt(1, (Integer)paintingsData[i][0]);
-            stmt.setString(2, (String) paintingsData[i][1]);
-            stmt.setInt(3, (Integer)paintingsData[i][2]);
-            stmt.setBigDecimal(4, (BigDecimal) paintingsData[i][3]);
-            stmt.executeUpdate();
-        }
-        stmt.close();
-    }
-    
-    private void insertGalleries(Object[][] galleriesData) throws SQLException {
-        PreparedStatement stmt = conn.prepareStatement(INSERT_GALLERY);
-        for (int i = 0; i < galleriesData.length; i++) {
-            stmt.setInt(1, (Integer)galleriesData[i][0]);
-            stmt.setString(2, (String) galleriesData[i][1]);
-            stmt.executeUpdate();
-        }
-        stmt.close();
-    }
-    
-    private void insertExibits(Object[][] exibitsData) throws SQLException {
-        PreparedStatement stmt = conn.prepareStatement(INSERT_EXIBIT);
-        for (int i = 0; i < exibitsData.length; i++) {
-            stmt.setInt(1, (Integer)exibitsData[i][0]);
-            stmt.setInt(2, (Integer) exibitsData[i][1]);
-            stmt.setDate(3, (Date)exibitsData[i][2]);
-            stmt.setDate(4, (Date)exibitsData[i][3]);
-            stmt.executeUpdate();
-        }
-        stmt.close();
-    }
-    
-    private void insertArtistExibits(Object[][] artistExibitsData) throws SQLException {
-        PreparedStatement stmt = conn.prepareStatement(INSERT_ARTIST_EXIBIT);
-        for (int i = 0; i < artistExibitsData.length; i++) {
-            stmt.setInt(1, (Integer)artistExibitsData[i][0]);
-            stmt.setInt(2, (Integer) artistExibitsData[i][1]);
-            stmt.executeUpdate();
-        }
-        stmt.close();
-    }
-    
-    enum TestData{
-        ONE_ENTITY_FETCH_JOIN, SEVERAL_FETCH_JOINS
+                assertEquals(a3, row[0]);
+                assertEquals(artistName3, row[1]);
+                assertEquals(g2, row[2]);
+            }
+        });
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextNoPkTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextNoPkTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextNoPkTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextNoPkTest.java Mon Jun 14 13:40:50 2010
@@ -23,19 +23,27 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.NoPkTestEntity;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class DataContextNoPkTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextNoPkTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
 
     @Override
-    protected void setUp() throws Exception {
-        TableHelper noPkTestTable = new TableHelper(
-                getDbHelper(),
-                "NO_PK_TEST",
-                "ATTRIBUTE1");
+    protected void setUpAfterInjection() throws Exception {
+        TableHelper noPkTestTable = new TableHelper(dbHelper, "NO_PK_TEST", "ATTRIBUTE1");
         noPkTestTable.deleteAll();
 
         noPkTestTable.insert(1);
@@ -44,8 +52,7 @@ public class DataContextNoPkTest extends
 
     public void testNoPkFetchObjects() throws Exception {
         try {
-            List objects = createDataContext().performQuery(
-                    new SelectQuery(NoPkTestEntity.class));
+            List objects = context.performQuery(new SelectQuery(NoPkTestEntity.class));
             fail("Query for entity with no primary key must have failed, instead we got "
                     + objects.size()
                     + " rows.");
@@ -59,7 +66,7 @@ public class DataContextNoPkTest extends
         SelectQuery query = new SelectQuery(NoPkTestEntity.class);
         query.setFetchingDataRows(true);
 
-        List rows = createDataContext().performQuery(query);
+        List rows = context.performQuery(query);
         assertNotNull(rows);
         assertEquals(2, rows.size());
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsTest.java Mon Jun 14 13:40:50 2010
@@ -20,6 +20,8 @@ package org.apache.cayenne.access;
 
 import java.util.List;
 
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.map.Entity;
@@ -29,9 +31,17 @@ import org.apache.cayenne.test.jdbc.DBHe
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class DataContextOuterJoinsTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextOuterJoinsTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
 
     protected TableHelper artistHelper;
     protected TableHelper paintingHelper;
@@ -39,8 +49,8 @@ public class DataContextOuterJoinsTest e
     protected TableHelper artistGroupHelper;
 
     @Override
-    protected void setUp() throws Exception {
-        DBHelper dbHelper = getDbHelper();
+    protected void setUpAfterInjection() throws Exception {
+
         artistHelper = new TableHelper(dbHelper, "ARTIST", "ARTIST_ID", "ARTIST_NAME");
         paintingHelper = new TableHelper(
                 dbHelper,
@@ -48,6 +58,7 @@ public class DataContextOuterJoinsTest e
                 "PAINTING_ID",
                 "ARTIST_ID",
                 "PAINTING_TITLE");
+
         artgroupHelper = new TableHelper(dbHelper, "ARTGROUP", "GROUP_ID", "NAME");
         artistGroupHelper = new TableHelper(
                 dbHelper,
@@ -80,7 +91,7 @@ public class DataContextOuterJoinsTest e
                 null));
         missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
 
-        List<Artist> artists = createDataContext().performQuery(missingToManyQuery);
+        List<Artist> artists = context.performQuery(missingToManyQuery);
         assertEquals(1, artists.size());
         assertEquals("BB1", artists.get(0).getArtistName());
     }
@@ -101,7 +112,7 @@ public class DataContextOuterJoinsTest e
                 null));
         missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
 
-        List<Artist> artists = createDataContext().performQuery(missingToManyQuery);
+        List<Artist> artists = context.performQuery(missingToManyQuery);
         assertEquals(2, artists.size());
         assertEquals("BB1", artists.get(0).getArtistName());
 
@@ -114,7 +125,7 @@ public class DataContextOuterJoinsTest e
                 "AA1"));
         mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
 
-        artists = createDataContext().performQuery(mixedConditionQuery);
+        artists = context.performQuery(mixedConditionQuery);
         assertEquals(3, artists.size());
         assertEquals("AA1", artists.get(0).getArtistName());
         assertEquals("BB1", artists.get(1).getArtistName());
@@ -135,7 +146,7 @@ public class DataContextOuterJoinsTest e
         missingToManyQuery.andQualifier(Expression.fromString("paintingArray+ = null"));
         missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
 
-        List<Artist> artists = createDataContext().performQuery(missingToManyQuery);
+        List<Artist> artists = context.performQuery(missingToManyQuery);
         assertEquals(2, artists.size());
         assertEquals("BB1", artists.get(0).getArtistName());
 
@@ -148,7 +159,7 @@ public class DataContextOuterJoinsTest e
                 "AA1"));
         mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
 
-        artists = createDataContext().performQuery(mixedConditionQuery);
+        artists = context.performQuery(mixedConditionQuery);
         assertEquals(3, artists.size());
         assertEquals("AA1", artists.get(0).getArtistName());
         assertEquals("BB1", artists.get(1).getArtistName());
@@ -168,7 +179,7 @@ public class DataContextOuterJoinsTest e
 
         query.addOrdering("toArtist+.artistName", SortOrder.DESCENDING);
 
-        List<Artist> paintings = createDataContext().performQuery(query);
+        List<Artist> paintings = context.performQuery(query);
         assertEquals(3, paintings.size());
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtras1Test.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtras1Test.java?rev=954463&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtras1Test.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtras1Test.java Mon Jun 14 13:40:50 2010
@@ -0,0 +1,83 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.access;
+
+import java.util.List;
+
+import org.apache.cayenne.ObjectContext;
+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.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.testdo.testmap.PaintingInfo;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+/**
+ * A test case for CAY-788.
+ */
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextPrefetchExtras1Test extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST");
+    }
+
+    protected void createDataSet() throws Exception {
+
+        TableHelper tPainting = new TableHelper(dbHelper, "PAINTING");
+        tPainting.setColumns("PAINTING_ID", "PAINTING_TITLE");
+
+        TableHelper tPaintingInfo = new TableHelper(dbHelper, "PAINTING_INFO");
+        tPaintingInfo.setColumns("PAINTING_ID", "TEXT_REVIEW");
+
+        for (int i = 1; i <= 10; i++) {
+            tPainting.insert(i, "P" + i);
+            tPaintingInfo.insert(i, "Review #" + i);
+        }
+    }
+
+    public void testPrefetchToOne() throws Exception {
+        createDataSet();
+
+        SelectQuery query = new SelectQuery(Painting.class);
+        query.addPrefetch(Painting.TO_PAINTING_INFO_PROPERTY);
+
+        List<Painting> objects = context.performQuery(query);
+        assertTrue(!objects.isEmpty());
+        for (Painting p : objects) {
+            PaintingInfo pi = p.getToPaintingInfo();
+            assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
+            assertEquals(PersistenceState.COMMITTED, pi.getPersistenceState());
+        }
+    }
+
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java Mon Jun 14 13:40:50 2010
@@ -37,7 +37,6 @@ import org.apache.cayenne.unit.CayenneCa
 
 /**
  * Test prefetching of various obscure cases.
- * 
  */
 public class DataContextPrefetchExtrasTest extends CayenneCase {
 
@@ -64,7 +63,7 @@ public class DataContextPrefetchExtrasTe
         assertEquals("n1", pk1.getOtherCol());
         List toMany = (List) pk1.readPropertyDirectly("charFKs");
         assertNotNull(toMany);
-        assertFalse(((ValueHolder)toMany).isFault());
+        assertFalse(((ValueHolder) toMany).isFault());
         assertEquals(3, toMany.size());
 
         CharFkTestEntity fk1 = (CharFkTestEntity) toMany.get(0);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/IdentityColumnsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/IdentityColumnsTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/IdentityColumnsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/IdentityColumnsTest.java Mon Jun 14 13:40:50 2010
@@ -24,11 +24,15 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.GeneratedColumnCompKey;
 import org.apache.cayenne.testdo.testmap.GeneratedColumnCompMaster;
@@ -37,16 +41,36 @@ import org.apache.cayenne.testdo.testmap
 import org.apache.cayenne.testdo.testmap.GeneratedColumnTestEntity;
 import org.apache.cayenne.testdo.testmap.GeneratedF1;
 import org.apache.cayenne.testdo.testmap.GeneratedF2;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-/**
- */
-public class IdentityColumnsTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class IdentityColumnsTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Inject
+    protected DbAdapter adapter;
+
+    @Inject
+    protected DataNode node;
+
+    protected TableHelper joinTable;
 
     @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        deleteTestData();
+    protected void setUpAfterInjection() throws Exception {
+        // TODO: extract in a separate DataMap?
+        dbHelper.deleteAll("GENERATED_JOIN");
+        dbHelper.deleteAll("GENERATED_F1");
+        dbHelper.deleteAll("GENERATED_F2");
+        dbHelper.deleteAll("GENERATED_COLUMN_DEP");
+        dbHelper.deleteAll("GENERATED_COLUMN_TEST");
+
+        joinTable = new TableHelper(dbHelper, "GENERATED_JOIN");
     }
 
     /**
@@ -54,7 +78,7 @@ public class IdentityColumnsTest extends
      * column.
      */
     public void testCAY823() throws Exception {
-        DataContext context = createDataContext();
+
         GeneratedColumnTestEntity idObject = context
                 .newObject(GeneratedColumnTestEntity.class);
 
@@ -76,7 +100,7 @@ public class IdentityColumnsTest extends
     }
 
     public void testNewObject() throws Exception {
-        DataContext context = createDataContext();
+
         GeneratedColumnTestEntity idObject = context
                 .newObject(GeneratedColumnTestEntity.class);
 
@@ -100,20 +124,13 @@ public class IdentityColumnsTest extends
     }
 
     public void testGeneratedJoinInFlattenedRelationship() throws Exception {
-        String joinTableName = "GENERATED_JOIN";
-
-        TableHelper joinTable = new TableHelper(getDbHelper(), joinTableName);
-        joinTable.deleteAll();
-
-        DataContext context = createDataContext();
 
         // before saving objects, let's manually access PKGenerator to get a base PK value
         // for comparison
-        DbEntity joinTableEntity = context.getEntityResolver().getDbEntity(joinTableName);
+        DbEntity joinTableEntity = context.getEntityResolver().getDbEntity(
+                joinTable.getTableName());
         DbAttribute pkAttribute = (DbAttribute) joinTableEntity.getAttribute("ID");
-        Number pk = (Number) getNode().getAdapter().getPkGenerator().generatePk(
-                getNode(),
-                pkAttribute);
+        Number pk = (Number) adapter.getPkGenerator().generatePk(node, pkAttribute);
 
         GeneratedF1 f1 = context.newObject(GeneratedF1.class);
         GeneratedF2 f2 = context.newObject(GeneratedF2.class);
@@ -127,7 +144,7 @@ public class IdentityColumnsTest extends
         // this is a leap of faith that autoincrement-based IDs will not match
         // PkGenertor provided ids... This sorta works though if pk generator has a 200
         // base value
-        if (getNode().getAdapter().supportsGeneratedKeys()) {
+        if (adapter.supportsGeneratedKeys()) {
             assertFalse("Looks like auto-increment wasn't used for the join table. ID: "
                     + id, id == pk.intValue() + 1);
         }
@@ -140,7 +157,7 @@ public class IdentityColumnsTest extends
      * Tests CAY-422 bug.
      */
     public void testUnrelatedUpdate() throws Exception {
-        DataContext context = createDataContext();
+
         GeneratedColumnTestEntity m = context.newObject(GeneratedColumnTestEntity.class);
 
         m.setName("m");
@@ -166,7 +183,6 @@ public class IdentityColumnsTest extends
      * CAY-341 for the original bug.
      */
     public void testMultipleNewObjectsSeparateTables() throws Exception {
-        DataContext context = createDataContext();
 
         GeneratedColumnTestEntity idObject1 = context
                 .newObject(GeneratedColumnTestEntity.class);
@@ -179,7 +195,6 @@ public class IdentityColumnsTest extends
     }
 
     public void testMultipleNewObjects() throws Exception {
-        DataContext context = createDataContext();
 
         String[] names = new String[] {
                 "n1_" + System.currentTimeMillis(), "n2_" + System.currentTimeMillis(),
@@ -217,7 +232,7 @@ public class IdentityColumnsTest extends
     }
 
     public void testCompoundPKWithGeneratedColumn() throws Exception {
-        if (getAccessStackAdapter().getAdapter().supportsGeneratedKeys()) {
+        if (adapter.supportsGeneratedKeys()) {
             // only works for generated keys, as the entity tested has one Cayenne
             // auto-pk and one generated key
 
@@ -225,7 +240,6 @@ public class IdentityColumnsTest extends
             String depName1 = "dep1_" + System.currentTimeMillis();
             String depName2 = "dep2_" + System.currentTimeMillis();
 
-            DataContext context = createDataContext();
             GeneratedColumnCompMaster master = context
                     .newObject(GeneratedColumnCompMaster.class);
             master.setName(masterName);
@@ -268,7 +282,7 @@ public class IdentityColumnsTest extends
     }
 
     public void testUpdateDependentWithNewMaster() throws Exception {
-        DataContext context = createDataContext();
+
         GeneratedColumnTestEntity master1 = context
                 .newObject(GeneratedColumnTestEntity.class);
         master1.setName("aaa");
@@ -308,7 +322,7 @@ public class IdentityColumnsTest extends
     }
 
     public void testPropagateToDependent() throws Exception {
-        DataContext context = createDataContext();
+
         GeneratedColumnTestEntity idObject = context
                 .newObject(GeneratedColumnTestEntity.class);
         idObject.setName("aaa");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java Mon Jun 14 13:40:50 2010
@@ -33,7 +33,7 @@ import org.apache.cayenne.testdo.quotema
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-@UseServerRuntime(ServerCase.QUOTED_IDENTIFIERS_STACK)
+@UseServerRuntime(ServerCase.QUOTED_IDENTIFIERS_PROJECT)
 public class QuotedIdentifiersTest extends ServerCase {
 
     @Inject

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java Mon Jun 14 13:40:50 2010
@@ -33,7 +33,7 @@ import org.apache.cayenne.unit.di.server
 /**
  * Special test cases per CAY-1378, CAY-1379.
  */
-@UseServerRuntime(ServerCase.INHERTITANCE_SINGLE_TABLE1_STACK)
+@UseServerRuntime(ServerCase.INHERTITANCE_SINGLE_TABLE1_PROJECT)
 public class SingleTableInheritance1Test extends ServerCase {
 
     @Inject

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java?rev=954463&r1=954462&r2=954463&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java Mon Jun 14 13:40:50 2010
@@ -36,7 +36,7 @@ import org.apache.cayenne.testdo.inherit
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-@UseServerRuntime(ServerCase.INHERTITANCE_VERTICAL_STACK)
+@UseServerRuntime(ServerCase.INHERTITANCE_VERTICAL_PROJECT)
 public class VerticalInheritanceTest extends ServerCase {
 
     @Inject



Mime
View raw message