cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r955148 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne: access/ unit/di/server/
Date Wed, 16 Jun 2010 07:38:41 GMT
Author: aadamchik
Date: Wed Jun 16 07:38:40 2010
New Revision: 955148

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

* switching old style unit tests

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java
      - copied, changed from r954855, 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/ServerCaseDataChannelQueryInterceptor.java
      - copied, changed from r954855, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryBlocker.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseObjectContextProvider.java
      - copied, changed from r954855, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java
Removed:
    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
Modified:
    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/DataContextRollbackTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListTest.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/ServerCaseDataContextProvider.java

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=955148&r1=955147&r2=955148&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 Wed Jun 16 07:38:40 2010
@@ -35,7 +35,7 @@ import org.apache.cayenne.testdo.testmap
 import org.apache.cayenne.testdo.testmap.Gallery;
 import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.DataChannelQueryBlocker;
+import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
@@ -49,7 +49,7 @@ public class DataContextEJBQLFetchJoinTe
     protected DBHelper dbHelper;
 
     @Inject
-    protected DataChannelQueryBlocker queryBlocker;
+    protected DataChannelQueryInterceptor queryBlocker;
 
     protected TableHelper tArtist;
     protected TableHelper tPainting;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRollbackTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRollbackTest.java?rev=955148&r1=955147&r2=955148&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRollbackTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRollbackTest.java Wed Jun 16 07:38:40 2010
@@ -23,14 +23,35 @@ import java.util.List;
 
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-/**
- */
-public class DataContextRollbackTest extends DataContextCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextRollbackTest extends ServerCase {
+
+    @Inject
+    protected DataContext context;
+
+    @Inject
+    protected ServerRuntime serverRuntime;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST");
+    }
 
     public void testRollbackNew() {
         Artist artist = (Artist) context.newObject("Artist");
@@ -56,10 +77,6 @@ public class DataContextRollbackTest ext
 
         // after:
         assertEquals(PersistenceState.TRANSIENT, artist.getPersistenceState());
-
-        // TODO: should we expect relationships to be unset?
-        // assertNull(p1.getToArtist());
-        // assertEquals(0, artist.getPaintingArray().size());
     }
 
     public void testRollbackNewObject() {
@@ -74,17 +91,19 @@ public class DataContextRollbackTest ext
         // The commit should have made no changes, so
         // perform a fetch to ensure that this artist hasn't been persisted to the db
 
-        DataContext freshContext = createDataContext();
+        DataContext freshContext = (DataContext) serverRuntime.getContext();
+        assertNotSame(this.context, freshContext);
+
         SelectQuery query = new SelectQuery(Artist.class);
         query.setQualifier(ExpressionFactory.matchExp("artistName", artistName));
-        List queryResults = freshContext.performQuery(query);
+        List<?> queryResults = freshContext.performQuery(query);
 
         assertEquals(0, queryResults.size());
     }
 
     // Catches a bug where new objects were unregistered within an object iterator, thus
-    // modifying the
-    // collection the iterator was iterating over (ConcurrentModificationException)
+    // modifying the collection the iterator was iterating over
+    // (ConcurrentModificationException)
     public void testRollbackWithMultipleNewObjects() {
         String artistName = "rollbackTestArtist";
         String paintingTitle = "rollbackTestPainting";
@@ -95,23 +114,20 @@ public class DataContextRollbackTest ext
         painting.setPaintingTitle(paintingTitle);
         painting.setToArtist(artist);
 
-        try {
-            context.rollbackChanges();
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail("rollbackChanges should not have caused the exception " + e.getMessage());
-        }
+        context.rollbackChanges();
 
         assertEquals(PersistenceState.TRANSIENT, artist.getPersistenceState());
         context.commitChanges();
+        
         // The commit should have made no changes, so
         // perform a fetch to ensure that this artist hasn't been persisted to the db
 
-        DataContext freshContext = createDataContext();
+        DataContext freshContext = (DataContext) serverRuntime.getContext();
+        assertNotSame(this.context, freshContext);
+
         SelectQuery query = new SelectQuery(Artist.class);
         query.setQualifier(ExpressionFactory.matchExp("artistName", artistName));
-        List queryResults = freshContext.performQuery(query);
+        List<?> queryResults = freshContext.performQuery(query);
 
         assertEquals(0, queryResults.size());
     }
@@ -138,7 +154,9 @@ public class DataContextRollbackTest ext
         assertEquals(1, artist.getPaintingArray().size());
         context.commitChanges();
 
-        DataContext freshContext = createDataContext();
+        DataContext freshContext = (DataContext) serverRuntime.getContext();
+        assertNotSame(this.context, freshContext);
+        
         SelectQuery query = new SelectQuery(Painting.class);
         query.setQualifier(ExpressionFactory.matchExp("paintingTitle", paintingTitle));
         List queryResults = freshContext.performQuery(query);
@@ -166,7 +184,9 @@ public class DataContextRollbackTest ext
         // The commit should have made no changes, so
         // perform a fetch to ensure that this artist hasn't been deleted from the db
 
-        DataContext freshContext = createDataContext();
+        DataContext freshContext = (DataContext) serverRuntime.getContext();
+        assertNotSame(this.context, freshContext);
+        
         SelectQuery query = new SelectQuery(Artist.class);
         query.setQualifier(ExpressionFactory.matchExp("artistName", artistName));
         List queryResults = freshContext.performQuery(query);
@@ -191,7 +211,10 @@ public class DataContextRollbackTest ext
         context.commitChanges();
 
         // .. and ensure that the correct data is in the db
-        DataContext freshContext = createDataContext();
+        DataContext freshContext = (DataContext) serverRuntime.getContext();
+        assertNotSame(this.context, freshContext);
+        
+        
         SelectQuery query = new SelectQuery(Artist.class);
         query.setQualifier(ExpressionFactory.matchExp("artistName", artistName));
         List queryResults = freshContext.performQuery(query);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java?rev=955148&r1=955147&r2=955148&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java Wed Jun 16 07:38:40 2010
@@ -20,6 +20,7 @@
 package org.apache.cayenne.access;
 
 import java.math.BigDecimal;
+import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -27,12 +28,15 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.sql.DataSource;
+
 import org.apache.cayenne.DataObject;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.Fault;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.conn.PoolManager;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.EJBQLQuery;
@@ -41,36 +45,140 @@ import org.apache.cayenne.query.Ordering
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.SortOrder;
+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.Exhibit;
 import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.testdo.testmap.ROArtist;
+import org.apache.cayenne.unit.AccessStackAdapter;
+import org.apache.cayenne.unit.di.UnitTestClosure;
+import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextTest extends ServerCase {
+
+    @Inject
+    protected DataContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Inject
+    protected AccessStackAdapter accessStackAdapter;
+
+    @Inject
+    protected DataChannelQueryInterceptor queryInterceptor;
+
+    @Inject
+    protected DataSource dataSource;
+
+    protected TableHelper tArtist;
+    protected TableHelper tExhibit;
+    protected TableHelper tGallery;
+    protected TableHelper tPaining;
 
-public class DataContextTest extends DataContextCase {
+    @Override
+    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");
 
-    protected MockOperationObserver opObserver;
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+        tExhibit = new TableHelper(dbHelper, "EXHIBIT");
+        tExhibit.setColumns("EXHIBIT_ID", "GALLERY_ID", "OPENING_DATE", "CLOSING_DATE");
+
+        tGallery = new TableHelper(dbHelper, "GALLERY");
+        tGallery.setColumns("GALLERY_ID", "GALLERY_NAME");
+
+        tPaining = new TableHelper(dbHelper, "PAINTING");
+        tPaining.setColumns(
+                "PAINTING_ID",
+                "PAINTING_TITLE",
+                "ARTIST_ID",
+                "ESTIMATED_PRICE");
+    }
+
+    protected void createSingleArtistDataSet() throws Exception {
+        tArtist.insert(33001, "artist1");
+    }
+
+    protected void createFiveArtistDataSet_MixedCaseName() throws Exception {
+        tArtist.insert(33001, "artist1");
+        tArtist.insert(33002, "Artist3");
+        tArtist.insert(33003, "aRtist5");
+        tArtist.insert(33004, "arTist2");
+        tArtist.insert(33005, "artISt4");
+    }
+
+    protected void createGalleriesAndExhibitsDataSet() throws Exception {
 
-        opObserver = new MockOperationObserver();
+        tGallery.insert(33001, "gallery1");
+        tGallery.insert(33002, "gallery2");
+        tGallery.insert(33003, "gallery3");
+        tGallery.insert(33004, "gallery4");
+
+        Timestamp now = new Timestamp(System.currentTimeMillis());
+
+        tExhibit.insert(1, 33001, now, now);
+        tExhibit.insert(2, 33002, now, now);
+    }
+
+    protected void createArtistsDataSet() throws Exception {
+        tArtist.insert(33001, "artist1");
+        tArtist.insert(33002, "artist2");
+        tArtist.insert(33003, "artist3");
+        tArtist.insert(33004, "artist4");
+        tArtist.insert(33005, "artist5");
+        tArtist.insert(33006, "artist11");
+        tArtist.insert(33007, "artist21");
+    }
+
+    protected void createArtistsAndPaintingsDataSet() throws Exception {
+        createArtistsDataSet();
+
+        tPaining.insert(33001, "P_artist1", 33001, 1000);
+        tPaining.insert(33002, "P_artist2", 33002, 2000);
+        tPaining.insert(33003, "P_artist3", 33003, 3000);
+        tPaining.insert(33004, "P_artist4", 33004, 4000);
+        tPaining.insert(33005, "P_artist5", 33005, 5000);
+        tPaining.insert(33006, "P_artist11", 33006, 11000);
+        tPaining.insert(33007, "P_artist21", 33007, 21000);
     }
 
     public void testCurrentSnapshot1() throws Exception {
-        Artist artist = fetchArtist("artist1", false);
-        Map snapshot = context.currentSnapshot(artist);
+        createSingleArtistDataSet();
+
+        SelectQuery query = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
+                Artist.ARTIST_NAME_PROPERTY,
+                "artist1"));
+        Artist artist = (Artist) context.performQuery(query).get(0);
+
+        DataRow snapshot = context.currentSnapshot(artist);
         assertEquals(artist.getArtistName(), snapshot.get("ARTIST_NAME"));
         assertEquals(artist.getDateOfBirth(), snapshot.get("DATE_OF_BIRTH"));
     }
 
     public void testCurrentSnapshot2() throws Exception {
+        createSingleArtistDataSet();
+
         // test null values
-        Artist artist = fetchArtist("artist1", false);
+        SelectQuery query = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
+                Artist.ARTIST_NAME_PROPERTY,
+                "artist1"));
+        Artist artist = (Artist) context.performQuery(query).get(0);
+
         artist.setArtistName(null);
         artist.setDateOfBirth(null);
 
-        Map snapshot = context.currentSnapshot(artist);
+        DataRow snapshot = context.currentSnapshot(artist);
         assertTrue(snapshot.containsKey("ARTIST_NAME"));
         assertNull(snapshot.get("ARTIST_NAME"));
 
@@ -79,15 +187,21 @@ public class DataContextTest extends Dat
     }
 
     public void testCurrentSnapshot3() throws Exception {
-        // test FK relationship snapshotting
-        Artist a1 = fetchArtist("artist1", false);
+        createSingleArtistDataSet();
+
+        // test null values
+        SelectQuery query = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
+                Artist.ARTIST_NAME_PROPERTY,
+                "artist1"));
+        Artist artist = (Artist) context.performQuery(query).get(0);
 
+        // test FK relationship snapshotting
         Painting p1 = new Painting();
         context.registerNewObject(p1);
-        p1.setToArtist(a1);
+        p1.setToArtist(artist);
 
-        Map s1 = context.currentSnapshot(p1);
-        Map idMap = a1.getObjectId().getIdSnapshot();
+        DataRow s1 = context.currentSnapshot(p1);
+        Map<String, Object> idMap = artist.getObjectId().getIdSnapshot();
         assertEquals(idMap.get("ARTIST_ID"), s1.get("ARTIST_ID"));
     }
 
@@ -96,14 +210,12 @@ public class DataContextTest extends Dat
      */
     public void testCurrentSnapshotWithToOneFault() throws Exception {
 
+        createGalleriesAndExhibitsDataSet();
+
         // Exhibit with Gallery as Fault must still include Gallery
         // Artist and Exhibit (Exhibit has unresolved to-one to gallery as in the
         // CAY-96 bug report)
 
-        // first prepare test fixture
-        createTestData("testGalleries");
-        populateExhibits();
-
         ObjectId eId = new ObjectId("Exhibit", Exhibit.EXHIBIT_ID_PK_COLUMN, 2);
         Exhibit e = (Exhibit) context.performQuery(new ObjectIdQuery(eId)).get(0);
 
@@ -122,9 +234,10 @@ public class DataContextTest extends Dat
      * a CHAR column with extra spaces, returned to the client. Cayenne should trim it.
      */
     public void testCharFetch() throws Exception {
-        SelectQuery q = new SelectQuery("Artist");
-        List artists = context.performQuery(q);
-        Artist a = (Artist) artists.get(0);
+        createSingleArtistDataSet();
+
+        SelectQuery query = new SelectQuery(Artist.class);
+        Artist a = (Artist) context.performQuery(query).get(0);
         assertEquals(a.getArtistName().trim(), a.getArtistName());
     }
 
@@ -134,9 +247,11 @@ public class DataContextTest extends Dat
      * Cayenne should trim it.
      */
     public void testCharInQualifier() throws Exception {
+        createArtistsDataSet();
+
         Expression e = ExpressionFactory.matchExp("artistName", "artist1");
-        SelectQuery q = new SelectQuery("Artist", e);
-        List artists = context.performQuery(q);
+        SelectQuery q = new SelectQuery(Artist.class, e);
+        List<Artist> artists = context.performQuery(q);
         assertEquals(1, artists.size());
     }
 
@@ -145,12 +260,12 @@ public class DataContextTest extends Dat
      * used in qualifier.
      */
     public void testMultiObjRelFetch() throws Exception {
-        createTestData("testPaintings");
+        createArtistsAndPaintingsDataSet();
 
-        SelectQuery q = new SelectQuery("Painting");
+        SelectQuery q = new SelectQuery(Painting.class);
         q.andQualifier(ExpressionFactory.matchExp("toArtist.artistName", "artist2"));
         q.orQualifier(ExpressionFactory.matchExp("toArtist.artistName", "artist4"));
-        List results = context.performQuery(q);
+        List<Painting> results = context.performQuery(q);
 
         assertEquals(2, results.size());
     }
@@ -160,72 +275,86 @@ public class DataContextTest extends Dat
      * used in qualifier.
      */
     public void testMultiDbRelFetch() throws Exception {
-        createTestData("testPaintings");
+        createArtistsAndPaintingsDataSet();
 
         SelectQuery q = new SelectQuery("Painting");
         q.andQualifier(ExpressionFactory.matchDbExp("toArtist.ARTIST_NAME", "artist2"));
         q.orQualifier(ExpressionFactory.matchDbExp("toArtist.ARTIST_NAME", "artist4"));
-        List results = context.performQuery(q);
+        List<?> results = context.performQuery(q);
 
         assertEquals(2, results.size());
     }
 
     public void testSelectDate() throws Exception {
-        createTestData("testGalleries");
-        populateExhibits();
+        createGalleriesAndExhibitsDataSet();
 
-        List objects = context.performQuery(new SelectQuery(Exhibit.class));
+        List<Exhibit> objects = context.performQuery(new SelectQuery(Exhibit.class));
         assertFalse(objects.isEmpty());
 
-        Exhibit e1 = (Exhibit) objects.get(0);
+        Exhibit e1 = objects.get(0);
         assertEquals(java.util.Date.class, e1.getClosingDate().getClass());
     }
 
     public void testCaseInsensitiveOrdering() throws Exception {
-        if (!getAccessStackAdapter().supportsCaseInsensitiveOrder()) {
+        if (!accessStackAdapter.supportsCaseInsensitiveOrder()) {
             return;
         }
 
+        createFiveArtistDataSet_MixedCaseName();
+
         // case insensitive ordering appends extra columns
         // to the query when query is using DISTINCT...
-        // verify that the result is not messaged up
+        // verify that the result is not messed up
 
         SelectQuery query = new SelectQuery(Artist.class);
-        Ordering ordering = new Ordering("artistName", SortOrder.ASCENDING_INSENSITIVE);
+        Ordering ordering = new Ordering(
+                Artist.ARTIST_NAME_PROPERTY,
+                SortOrder.ASCENDING_INSENSITIVE);
         query.addOrdering(ordering);
         query.setDistinct(true);
 
-        List objects = context.performQuery(query);
-        assertEquals(artistCount, objects.size());
+        List<Artist> objects = context.performQuery(query);
+        assertEquals(5, objects.size());
 
-        Artist artist = (Artist) objects.get(0);
-        Map snapshot = context.getObjectStore().getSnapshot(artist.getObjectId());
+        Artist artist = objects.get(0);
+        DataRow snapshot = context.getObjectStore().getSnapshot(artist.getObjectId());
         assertEquals(3, snapshot.size());
+
+        // assert the ordering
+        assertEquals("artist1", objects.get(0).getArtistName());
+        assertEquals("arTist2", objects.get(1).getArtistName());
+        assertEquals("Artist3", objects.get(2).getArtistName());
+        assertEquals("artISt4", objects.get(3).getArtistName());
+        assertEquals("aRtist5", objects.get(4).getArtistName());
     }
 
     public void testPerformSelectQuery1() throws Exception {
-        SelectQuery query = new SelectQuery("Artist");
-        List objects = context.performQuery(query);
+        createArtistsAndPaintingsDataSet();
+
+        SelectQuery query = new SelectQuery(Artist.class);
+        List<?> objects = context.performQuery(query);
 
         assertNotNull(objects);
-        assertEquals(artistCount, objects.size());
+        assertEquals(7, objects.size());
         assertTrue(
                 "Artist expected, got " + objects.get(0).getClass(),
                 objects.get(0) instanceof Artist);
     }
 
     public void testPerformSelectQuery2() throws Exception {
+        createArtistsAndPaintingsDataSet();
+
         // do a query with complex qualifier
-        List expressions = new ArrayList();
+        List<Expression> expressions = new ArrayList<Expression>();
         expressions.add(ExpressionFactory.matchExp("artistName", "artist3"));
         expressions.add(ExpressionFactory.matchExp("artistName", "artist5"));
-        expressions.add(ExpressionFactory.matchExp("artistName", "artist15"));
+        expressions.add(ExpressionFactory.matchExp("artistName", "artist21"));
 
-        SelectQuery query = new SelectQuery("Artist", ExpressionFactory.joinExp(
+        SelectQuery query = new SelectQuery(Artist.class, ExpressionFactory.joinExp(
                 Expression.OR,
                 expressions));
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
 
         assertNotNull(objects);
         assertEquals(3, objects.size());
@@ -234,14 +363,10 @@ public class DataContextTest extends Dat
                 objects.get(0) instanceof Artist);
     }
 
-    public void testPerformQuery() throws Exception {
-        SelectQuery query = new SelectQuery("Artist");
-        List objects = context.performQuery(query);
-        assertNotNull(objects);
-        assertEquals(artistCount, objects.size());
-    }
-
     public void testPerformNonSelectingQuery() throws Exception {
+
+        createSingleArtistDataSet();
+
         SelectQuery select = new SelectQuery(Painting.class, Expression
                 .fromString("db:PAINTING_ID = 1"));
 
@@ -250,18 +375,20 @@ public class DataContextTest extends Dat
         SQLTemplate query = new SQLTemplate(
                 Painting.class,
                 "INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) "
-                        + "VALUES (1, 'PX', 33002, 1)");
+                        + "VALUES (1, 'PX', 33001, 1)");
         context.performNonSelectingQuery(query);
         assertEquals(1, context.performQuery(select).size());
     }
 
     public void testPerformNonSelectingQueryCounts1() throws Exception {
+        createArtistsDataSet();
+
         SQLTemplate query = new SQLTemplate(
                 Painting.class,
                 "INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) "
                         + "VALUES ($pid, '$pt', $aid, $price)");
 
-        Map map = new HashMap();
+        Map<String, Object> map = new HashMap<String, Object>();
         map.put("pid", new Integer(1));
         map.put("pt", "P1");
         map.put("aid", new Integer(33002));
@@ -277,14 +404,17 @@ public class DataContextTest extends Dat
     }
 
     public void testPerformNonSelectingQueryCounts2() throws Exception {
+        
+        createArtistsDataSet();
+        
         SQLTemplate query = new SQLTemplate(
                 Painting.class,
                 "INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) "
                         + "VALUES ($pid, '$pt', $aid, #bind($price 'DECIMAL' 2))");
 
-        Map[] maps = new Map[3];
+        Map<String, Object>[] maps = new Map[3];
         for (int i = 0; i < maps.length; i++) {
-            maps[i] = new HashMap();
+            maps[i] = new HashMap<String, Object>();
             maps[i].put("pid", new Integer(1 + i));
             maps[i].put("pt", "P-" + i);
             maps[i].put("aid", new Integer(33002));
@@ -309,58 +439,67 @@ public class DataContextTest extends Dat
     }
 
     public void testPerformPaginatedQuery() throws Exception {
-        SelectQuery query = new SelectQuery("Artist");
+        createArtistsDataSet();
+
+        SelectQuery query = new SelectQuery(Artist.class);
         query.setPageSize(5);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertNotNull(objects);
         assertTrue(objects instanceof IncrementalFaultList);
         assertTrue(((IncrementalFaultList<?>) objects).elements.get(0) instanceof Long);
-        assertTrue(((IncrementalFaultList<?>) objects).elements.get(7) instanceof Long);
-        
+        assertTrue(((IncrementalFaultList<?>) objects).elements.get(6) instanceof Long);
+
         assertTrue(objects.get(0) instanceof Artist);
     }
-    
+
     public void testPerformPaginatedQuery1() throws Exception {
+        createArtistsDataSet();
+
         EJBQLQuery query = new EJBQLQuery("select a FROM Artist a");
         query.setPageSize(5);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertNotNull(objects);
         assertTrue(objects instanceof IncrementalFaultList);
         assertTrue(((IncrementalFaultList<?>) objects).elements.get(0) instanceof Long);
-        assertTrue(((IncrementalFaultList<?>) objects).elements.get(7) instanceof Long);
-        
+        assertTrue(((IncrementalFaultList<?>) objects).elements.get(6) instanceof Long);
+
         assertTrue(objects.get(0) instanceof Artist);
     }
 
     public void testPerformPaginatedQueryBigPage() throws Exception {
-        SelectQuery query = new SelectQuery("Artist");
-        query.setPageSize(DataContextTest.artistCount + 2);
-        List objects = context.performQuery(query);
+        createArtistsDataSet();
+
+        SelectQuery query = new SelectQuery(Artist.class);
+        query.setPageSize(5);
+        final List<?> objects = context.performQuery(query);
         assertNotNull(objects);
         assertTrue(objects instanceof IncrementalFaultList);
 
-        blockQueries();
-        try {
-            assertEquals(DataContextTest.artistCount, objects.size());
-        }
-        finally {
-            unblockQueries();
-        }
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                assertEquals(7, objects.size());
+            }
+        });
     }
 
     public void testPerformDataRowQuery() throws Exception {
-        SelectQuery query = new SelectQuery("Artist");
+
+        createArtistsDataSet();
+
+        SelectQuery query = new SelectQuery(Artist.class);
         query.setFetchingDataRows(true);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
 
         assertNotNull(objects);
-        assertEquals(artistCount, objects.size());
+        assertEquals(7, objects.size());
         assertTrue(
                 "Map expected, got " + objects.get(0).getClass(),
                 objects.get(0) instanceof Map);
     }
 
     public void testCommitChangesRO1() throws Exception {
+
         ROArtist a1 = (ROArtist) context.newObject("ROArtist");
         a1.writePropertyDirectly("artistName", "abc");
         a1.setPersistenceState(PersistenceState.MODIFIED);
@@ -376,8 +515,13 @@ public class DataContextTest extends Dat
     }
 
     public void testCommitChangesRO2() throws Exception {
-        ROArtist a1 = fetchROArtist("artist1");
-        a1.writeProperty("artistName", "abc");
+        createArtistsDataSet();
+
+        SelectQuery query = new SelectQuery(ROArtist.class, ExpressionFactory.matchExp(
+                Artist.ARTIST_NAME_PROPERTY,
+                "artist1"));
+        ROArtist a1 = (ROArtist) context.performQuery(query).get(0);
+        a1.writeProperty(ROArtist.ARTIST_NAME_PROPERTY, "abc");
 
         try {
             context.commitChanges();
@@ -390,7 +534,13 @@ public class DataContextTest extends Dat
     }
 
     public void testCommitChangesRO3() throws Exception {
-        ROArtist a1 = fetchROArtist("artist1");
+
+        createArtistsDataSet();
+
+        SelectQuery query = new SelectQuery(ROArtist.class, ExpressionFactory.matchExp(
+                Artist.ARTIST_NAME_PROPERTY,
+                "artist1"));
+        ROArtist a1 = (ROArtist) context.performQuery(query).get(0);
         context.deleteObject(a1);
 
         try {
@@ -404,8 +554,14 @@ public class DataContextTest extends Dat
     }
 
     public void testCommitChangesRO4() throws Exception {
-        ROArtist a1 = fetchROArtist("artist1");
-        Painting painting = (Painting) context.newObject("Painting");
+        createArtistsDataSet();
+
+        SelectQuery query = new SelectQuery(ROArtist.class, ExpressionFactory.matchExp(
+                Artist.ARTIST_NAME_PROPERTY,
+                "artist1"));
+        ROArtist a1 = (ROArtist) context.performQuery(query).get(0);
+
+        Painting painting = context.newObject(Painting.class);
         painting.setPaintingTitle("paint");
         a1.addToPaintingArray(painting);
 
@@ -422,7 +578,10 @@ public class DataContextTest extends Dat
     }
 
     public void testPerformIteratedQuery1() throws Exception {
-        SelectQuery q1 = new SelectQuery("Artist");
+
+        createArtistsDataSet();
+
+        SelectQuery q1 = new SelectQuery(Artist.class);
         ResultIterator it = context.performIteratedQuery(q1);
 
         try {
@@ -432,7 +591,7 @@ public class DataContextTest extends Dat
                 count++;
             }
 
-            assertEquals(DataContextTest.artistCount, count);
+            assertEquals(7, count);
         }
         finally {
             it.close();
@@ -440,7 +599,7 @@ public class DataContextTest extends Dat
     }
 
     public void testPerformIteratedQuery2() throws Exception {
-        createTestData("testPaintings");
+        createArtistsAndPaintingsDataSet();
 
         ResultIterator it = context.performIteratedQuery(new SelectQuery(Artist.class));
 
@@ -452,11 +611,8 @@ public class DataContextTest extends Dat
                 DataRow row = (DataRow) it.nextRow();
 
                 // try instantiating an object and fetching its relationships
-                Artist artist = context.objectFromDataRow(
-                        Artist.class,
-                        row,
-                        false);
-                List paintings = artist.getPaintingArray();
+                Artist artist = context.objectFromDataRow(Artist.class, row, false);
+                List<?> paintings = artist.getPaintingArray();
                 assertNotNull(paintings);
                 assertEquals("Expected one painting for artist: " + artist, 1, paintings
                         .size());
@@ -465,28 +621,16 @@ public class DataContextTest extends Dat
         finally {
             // change allowed connections back
             changeMaxConnections(-1);
-
             it.close();
         }
     }
 
-    public void changeMaxConnections(int delta) {
-        DataNode node = context
-                .getParentDataDomain()
-                .getDataNodes()
-                .iterator()
-                .next();
-
-        // access DS directly as 'getDataSource' returns a wrapper.
-        PoolManager manager = (PoolManager) node.dataSource;
-        manager.setMaxConnections(manager.getMaxConnections() + delta);
-    }
-
     /**
      * Tests that hasChanges performs correctly when an object is "modified" and the
      * property is simply set to the same value (an unreal modification)
      */
     public void testHasChangesPhantom() {
+
         String artistName = "ArtistName";
         Artist artist = (Artist) context.newObject("Artist");
         artist.setArtistName(artistName);
@@ -515,7 +659,6 @@ public class DataContextTest extends Dat
     }
 
     public void testInvalidateObjects() throws Exception {
-        DataContext context = createDataContext();
 
         DataRow row = new DataRow(10);
         row.put("ARTIST_ID", new Integer(1));
@@ -536,14 +679,16 @@ public class DataContextTest extends Dat
         assertNull(context.getObjectStore().getCachedSnapshot(oid));
         assertSame(object, context.getObjectStore().getNode(oid));
     }
-    
+
     public void testBeforeHollowDeleteShouldChangeStateToCommited() throws Exception {
-        ObjectId gid = new ObjectId("Artist","ARTIST_ID",33001);  
+        createSingleArtistDataSet();
+
+        ObjectId gid = new ObjectId("Artist", "ARTIST_ID", 33001);
         final Artist inflated = new Artist();
         inflated.setPersistenceState(PersistenceState.COMMITTED);
         inflated.setObjectId(gid);
         inflated.setArtistName("artist1");
-        
+
         Artist hollow = (Artist) context.localObject(gid, null);
         assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
 
@@ -551,8 +696,12 @@ public class DataContextTest extends Dat
         context.deleteObject(hollow);
         assertSame(hollow, context.getGraphManager().getNode(gid));
         assertEquals(inflated.getArtistName(), hollow.getArtistName());
-          
+
         assertEquals(PersistenceState.DELETED, hollow.getPersistenceState());
     }
 
+    private void changeMaxConnections(int delta) {
+        PoolManager manager = (PoolManager) dataSource;
+        manager.setMaxConnections(manager.getMaxConnections() + delta);
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java?rev=955148&r1=955147&r2=955148&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java Wed Jun 16 07:38:40 2010
@@ -17,31 +17,87 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.access;
 
 import java.util.List;
 
 import org.apache.cayenne.DataObject;
+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.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
 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.di.UnitTestClosure;
+import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SimpleIdIncrementalFaultListPrefetchTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
 
-/**
- */
-public class SimpleIdIncrementalFaultListPrefetchTest extends DataContextCase {
+    @Inject
+    protected DataChannelQueryInterceptor queryInterceptor;
+
+    protected TableHelper tArtist;
+    protected TableHelper tPaining;
 
     @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        createTestData("testPaintings");
+    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");
+
+        tPaining = new TableHelper(dbHelper, "PAINTING");
+        tPaining.setColumns(
+                "PAINTING_ID",
+                "PAINTING_TITLE",
+                "ARTIST_ID",
+                "ESTIMATED_PRICE");
     }
-    
-    public void testListType() {
-        Expression e = ExpressionFactory.likeExp("artistName", "artist1%");
+
+    protected void createArtistsDataSet() throws Exception {
+        tArtist.insert(33001, "artist11");
+        tArtist.insert(33002, "artist12");
+        tArtist.insert(33003, "artist13");
+        tArtist.insert(33004, "artist14");
+        tArtist.insert(33005, "artist15");
+        tArtist.insert(33006, "artist16");
+        tArtist.insert(33007, "artist21");
+    }
+
+    protected void createArtistsAndPaintingsDataSet() throws Exception {
+        createArtistsDataSet();
+
+        tPaining.insert(33001, "P_artist11", 33001, 1000);
+        tPaining.insert(33002, "P_artist12", 33002, 2000);
+        tPaining.insert(33003, "P_artist13", 33003, 3000);
+        tPaining.insert(33004, "P_artist14", 33004, 4000);
+        tPaining.insert(33005, "P_artist15", 33005, 5000);
+        tPaining.insert(33006, "P_artist16", 33006, 11000);
+        tPaining.insert(33007, "P_artist21", 33007, 21000);
+    }
+
+    public void testListType() throws Exception {
+
+        createArtistsDataSet();
+
+        Expression e = ExpressionFactory.likeExp(Artist.ARTIST_NAME_PROPERTY, "artist1%");
         SelectQuery q = new SelectQuery("Artist", e);
         q.setPageSize(4);
 
@@ -53,49 +109,58 @@ public class SimpleIdIncrementalFaultLis
      * Test that all queries specified in prefetch are executed with a single prefetch
      * path.
      */
-    public void testPrefetch1() {
+    public void testPrefetch1() throws Exception {
+
+        createArtistsAndPaintingsDataSet();
 
         Expression e = ExpressionFactory.likeExp("artistName", "artist1%");
         SelectQuery q = new SelectQuery("Artist", e);
         q.addPrefetch("paintingArray");
-        q.setPageSize(4);
+        q.setPageSize(3);
 
-        IncrementalFaultList result = (IncrementalFaultList) context.performQuery(q);
+        final IncrementalFaultList<?> result = (IncrementalFaultList) context
+                .performQuery(q);
 
-        assertEquals(11, result.size());
+        assertEquals(6, result.size());
 
         // currently queries with prefetch do not resolve their first page
         assertEquals(result.size(), result.getUnfetchedObjects());
 
-        // go through the second page objects and count queries
-        getDomain().restartQueryCounter();
-        for (int i = 4; i < 8; i++) {
-            result.get(i);
+        int count = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
 
-            // within the same page only one query should've been executed
-            assertEquals(1, getDomain().getQueryCount());
-        }
+            public void execute() {
+                // go through the second page objects and count queries
+                for (int i = 3; i < 6; i++) {
+                    result.get(i);
+                }
+            }
+        });
+
+        // within the same page only one query should've been executed
+        assertEquals(1, count);
     }
 
     /**
      * Test that a to-many relationship is initialized.
      */
-    public void testPrefetch3() {
+    public void testPrefetch3() throws Exception {
+
+        createArtistsAndPaintingsDataSet();
 
         Expression e = ExpressionFactory.likeExp("artistName", "artist1%");
         SelectQuery q = new SelectQuery("Artist", e);
         q.addPrefetch("paintingArray");
-        q.setPageSize(4);
+        q.setPageSize(3);
 
         IncrementalFaultList result = (IncrementalFaultList) context.performQuery(q);
 
-        assertEquals(11, result.size());
+        assertEquals(6, result.size());
 
         // currently queries with prefetch do not resolve their first page
         assertEquals(result.size(), result.getUnfetchedObjects());
 
         // go through the second page objects and check their to many
-        for (int i = 4; i < 8; i++) {
+        for (int i = 3; i < 6; i++) {
             Artist a = (Artist) result.get(i);
 
             List paintings = a.getPaintingArray();
@@ -107,33 +172,32 @@ public class SimpleIdIncrementalFaultLis
     /**
      * Test that a to-one relationship is initialized.
      */
-    public void testPrefetch4() {
+    public void testPrefetch4() throws Exception {
 
-        SelectQuery q = new SelectQuery("Painting");
-        q.setPageSize(4);
+        createArtistsAndPaintingsDataSet();
+
+        SelectQuery q = new SelectQuery(Painting.class);
+        q.setPageSize(3);
         q.addPrefetch("toArtist");
 
-        IncrementalFaultList result = (IncrementalFaultList) context.performQuery(q);
+        IncrementalFaultList<?> result = (IncrementalFaultList) context.performQuery(q);
 
         // get an objects from the second page
-        DataObject p1 = (DataObject) result.get(q.getPageSize());
-
-        blockQueries();
+        final DataObject p1 = (DataObject) result.get(q.getPageSize());
 
-        try {
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
 
-            Object toOnePrefetch = p1.readNestedProperty("toArtist");
-            assertNotNull(toOnePrefetch);
-            assertTrue(
-                    "Expected DataObject, got: " + toOnePrefetch.getClass().getName(),
-                    toOnePrefetch instanceof DataObject);
-
-            DataObject a1 = (DataObject) toOnePrefetch;
-            assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
-        }
-        finally {
-            unblockQueries();
-        }
+            public void execute() {
+                Object toOnePrefetch = p1.readNestedProperty("toArtist");
+                assertNotNull(toOnePrefetch);
+                assertTrue(
+                        "Expected DataObject, got: " + toOnePrefetch.getClass().getName(),
+                        toOnePrefetch instanceof DataObject);
+
+                DataObject a1 = (DataObject) toOnePrefetch;
+                assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
+            }
+        });
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListTest.java?rev=955148&r1=955147&r2=955148&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListTest.java Wed Jun 16 07:38:40 2010
@@ -84,17 +84,17 @@ public class SimpleIdIncrementalFaultLis
 
     public void testSize() throws Exception {
         prepareList(6);
-        assertEquals(DataContextTest.artistCount, list.size());
+        assertEquals(25, list.size());
     }
 
     public void testSmallList() throws Exception {
         prepareList(49);
-        assertEquals(DataContextTest.artistCount, list.size());
+        assertEquals(25, list.size());
     }
 
     public void testOnePageList() throws Exception {
-        prepareList(DataContextTest.artistCount);
-        assertEquals(DataContextTest.artistCount, list.size());
+        prepareList(25);
+        assertEquals(25, list.size());
     }
 
     public void testIterator() throws Exception {
@@ -139,7 +139,7 @@ public class SimpleIdIncrementalFaultLis
                 context,
                 q);
 
-        assertSame(newArtist, list.get(DataContextTest.artistCount));
+        assertSame(newArtist, list.get(25));
     }
 
     public void testListIterator() throws Exception {
@@ -183,9 +183,9 @@ public class SimpleIdIncrementalFaultLis
 
     public void testUnfetchedObjects() throws Exception {
         prepareList(6);
-        assertEquals(DataContextTest.artistCount, list.getUnfetchedObjects());
+        assertEquals(25, list.getUnfetchedObjects());
         list.get(7);
-        assertEquals(DataContextTest.artistCount - 6, list.getUnfetchedObjects());
+        assertEquals(25 - 6, list.getUnfetchedObjects());
         list.resolveAll();
         assertEquals(0, list.getUnfetchedObjects());
     }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java (from r954855, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryBlocker.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryBlocker.java&r1=954855&r2=955148&rev=955148&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryBlocker.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java Wed Jun 16 07:38:40 2010
@@ -20,7 +20,9 @@ package org.apache.cayenne.unit.di.serve
 
 import org.apache.cayenne.unit.di.UnitTestClosure;
 
-public interface DataChannelQueryBlocker {
+public interface DataChannelQueryInterceptor {
 
     void runWithQueriesBlocked(UnitTestClosure closure);
+    
+    int runWithQueryCounter(UnitTestClosure closure);
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java?rev=955148&r1=955147&r2=955148&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java Wed Jun 16 07:38:40 2010
@@ -21,6 +21,7 @@ package org.apache.cayenne.unit.di.serve
 import javax.sql.DataSource;
 
 import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.dba.DbAdapter;
@@ -74,8 +75,8 @@ public class ServerCase extends DICase {
                 binder.bind(AccessStackAdapter.class).toProviderInstance(
                         new CayenneResourcesAccessStackAdapterProvider(resources));
                 binder.bind(DataNode.class).toProvider(ServerCaseDataNodeProvider.class);
-                binder.bind(DataChannelQueryBlocker.class).to(
-                        ServerCaseDataChannelQueryBlocker.class);
+                binder.bind(DataChannelQueryInterceptor.class).to(
+                        ServerCaseDataChannelQueryInterceptor.class);
 
                 // test-scoped objects
                 binder
@@ -85,6 +86,8 @@ public class ServerCase extends DICase {
                 binder.bind(ServerRuntime.class).toProviderInstance(
                         new ServerRuntimeProvider(resources)).in(testScope);
                 binder.bind(ObjectContext.class).toProvider(
+                        ServerCaseObjectContextProvider.class).in(testScope);
+                binder.bind(DataContext.class).toProvider(
                         ServerCaseDataContextProvider.class).in(testScope);
                 binder
                         .bind(DBHelper.class)

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java (from r954855, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryBlocker.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryBlocker.java&r1=954855&r2=955148&rev=955148&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryBlocker.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java Wed Jun 16 07:38:40 2010
@@ -24,7 +24,7 @@ import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Provider;
 import org.apache.cayenne.unit.di.UnitTestClosure;
 
-public class ServerCaseDataChannelQueryBlocker implements DataChannelQueryBlocker {
+public class ServerCaseDataChannelQueryInterceptor implements DataChannelQueryInterceptor {
 
     @Inject
     // injecting provider to make this provider independent from scoping of ServerRuntime
@@ -44,4 +44,22 @@ public class ServerCaseDataChannelQueryB
             channel.setBlockingQueries(false);
         }
     }
+
+    public int runWithQueryCounter(UnitTestClosure closure) {
+
+        UnitTestDomain channel = (UnitTestDomain) serverRuntimeProvider
+                .get()
+                .getChannel();
+
+        int start = channel.getQueryCount();
+        int end;
+        try {
+            closure.execute();
+        }
+        finally {
+            end = channel.getQueryCount();
+        }
+
+        return end - start;
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java?rev=955148&r1=955147&r2=955148&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java Wed Jun 16 07:38:40 2010
@@ -20,17 +20,16 @@ package org.apache.cayenne.unit.di.serve
 
 import org.apache.cayenne.ConfigurationException;
 import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Provider;
 
-public class ServerCaseDataContextProvider implements Provider<ObjectContext> {
+public class ServerCaseDataContextProvider implements Provider<DataContext> {
 
     @Inject
-    // injecting provider to make this provider independent from scoping of ServerRuntime
-    protected Provider<ServerRuntime> serverRuntimeProvider;
+    protected Provider<ObjectContext> objectContextProvider;
 
-    public ObjectContext get() throws ConfigurationException {
-        return serverRuntimeProvider.get().getContext();
+    public DataContext get() throws ConfigurationException {
+        return (DataContext) objectContextProvider.get();
     }
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseObjectContextProvider.java (from r954855, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseObjectContextProvider.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseObjectContextProvider.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java&r1=954855&r2=955148&rev=955148&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseObjectContextProvider.java Wed Jun 16 07:38:40 2010
@@ -24,7 +24,7 @@ import org.apache.cayenne.configuration.
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Provider;
 
-public class ServerCaseDataContextProvider implements Provider<ObjectContext> {
+public class ServerCaseObjectContextProvider implements Provider<ObjectContext> {
 
     @Inject
     // injecting provider to make this provider independent from scoping of ServerRuntime



Mime
View raw message