cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r956338 [2/3] - in /cayenne/main/trunk: build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ framework/cayenne-jdk1.5-unpublished/src/te...
Date Sun, 20 Jun 2010 09:27:38 GMT
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRefreshingTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRefreshingTest.java?rev=956338&r1=956337&r2=956338&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRefreshingTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRefreshingTest.java Sun Jun 20 09:27:37 2010
@@ -21,280 +21,344 @@ package org.apache.cayenne.access;
 
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.List;
 
-import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.query.SQLTemplate;
+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.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;
 
 /**
  * Test suite covering possible scenarios of refreshing updated objects. This includes
  * refreshing relationships and attributes changed outside of Cayenne with and without
  * prefetching.
  */
-public class DataContextRefreshingTest extends DataContextCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextRefreshingTest extends ServerCase {
+
+    @Inject
+    protected DataContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Inject
+    protected DataChannelQueryInterceptor queryInterceptor;
+
+    protected TableHelper tArtist;
+    protected TableHelper tPainting;
+
+    @Override
+    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",
+                "PAINTING_TITLE",
+                "ARTIST_ID",
+                "ESTIMATED_PRICE");
+    }
+
+    protected void createSingleArtistDataSet() throws Exception {
+        tArtist.insert(5, "artist2");
+    }
+
+    protected void createSingleArtistAndPaintingDataSet() throws Exception {
+        createSingleArtistDataSet();
+        tPainting.insert(4, "p", 5, 1000);
+    }
+
+    protected void createSingleArtistAndUnrelatedPaintingDataSet() throws Exception {
+        createSingleArtistDataSet();
+        tPainting.insert(4, "p", null, 1000);
+    }
+
+    protected void createTwoArtistsAndPaintingDataSet() throws Exception {
+        tArtist.insert(5, "artist2");
+        tArtist.insert(6, "artist3");
+        tPainting.insert(4, "p", 5, 1000);
+    }
 
     public void testRefetchRootWithUpdatedAttributes() throws Exception {
+
+        createSingleArtistDataSet();
+
         String nameBefore = "artist2";
         String nameAfter = "not an artist";
 
-        Artist artist = fetchArtist(nameBefore, false);
-        assertNotNull(artist);
+        SelectQuery queryBefore = new SelectQuery(Artist.class, ExpressionFactory
+                .matchExp("artistName", nameBefore));
+
+        Artist artist = (Artist) context.performQuery(queryBefore).get(0);
         assertEquals(nameBefore, artist.getArtistName());
 
-        // update via DataNode directly
-        updateRow(artist.getObjectId(), "ARTIST_NAME", nameAfter);
+        assertEquals(1, tArtist.update().set("ARTIST_NAME", nameAfter).execute());
 
         // fetch into the same context
-        artist = fetchArtist(nameBefore, false);
-        assertNull(artist);
+        List<Artist> artists = context.performQuery(queryBefore);
+        assertEquals(0, artists.size());
 
-        artist = fetchArtist(nameAfter, false);
+        SelectQuery queryAfter = new SelectQuery(Artist.class, ExpressionFactory
+                .matchExp("artistName", nameAfter));
+
+        artist = (Artist) context.performQuery(queryAfter).get(0);
         assertNotNull(artist);
         assertEquals(nameAfter, artist.getArtistName());
     }
 
     public void testRefetchRootWithNullifiedToOne() throws Exception {
-        Painting painting = insertPaintingInContext("p");
+        createSingleArtistAndPaintingDataSet();
+
+        Painting painting = (Painting) context.performQuery(
+                new SelectQuery(Painting.class)).get(0);
+
         assertNotNull(painting.getToArtist());
+        assertEquals("artist2", painting.getToArtist().getArtistName());
 
-        // update via DataNode directly
-        updateRow(painting.getObjectId(), "ARTIST_ID", null);
+        assertEquals(1, tPainting.update().set("ARTIST_ID", null).execute());
 
         // select without prefetch
-        painting = fetchPainting(painting.getPaintingTitle(), false);
+        painting = (Painting) context
+                .performQuery(new SelectQuery(Painting.class))
+                .get(0);
         assertNotNull(painting);
         assertNull(painting.getToArtist());
     }
 
     public void testRefetchRootWithChangedToOneTarget() throws Exception {
-        Painting painting = insertPaintingInContext("p");
+        createTwoArtistsAndPaintingDataSet();
+
+        Painting painting = (Painting) context.performQuery(
+                new SelectQuery(Painting.class)).get(0);
+
         Artist artistBefore = painting.getToArtist();
         assertNotNull(artistBefore);
+        assertEquals("artist2", artistBefore.getArtistName());
 
-        Artist artistAfter = fetchArtist("artist3", false);
-        assertNotNull(artistAfter);
-        assertNotSame(artistBefore, artistAfter);
-
-        // update via DataNode directly
-        updateRow(painting.getObjectId(), "ARTIST_ID", artistAfter
-                .getObjectId()
-                .getIdSnapshot()
-                .get("ARTIST_ID"));
+        assertEquals(1, tPainting.update().set("ARTIST_ID", 6).execute());
 
         // select without prefetch
-        painting = fetchPainting(painting.getPaintingTitle(), false);
+        painting = (Painting) context
+                .performQuery(new SelectQuery(Painting.class))
+                .get(0);
         assertNotNull(painting);
-        assertSame(artistAfter, painting.getToArtist());
+        assertEquals("artist3", painting.getToArtist().getArtistName());
     }
 
     public void testRefetchRootWithNullToOneTargetChangedToNotNull() throws Exception {
-        Painting painting = insertPaintingInContext("p");
-        painting.setToArtist(null);
-        context.commitChanges();
+        createSingleArtistAndUnrelatedPaintingDataSet();
 
-        assertNull(painting.getToArtist());
+        Painting painting = (Painting) context.performQuery(
+                new SelectQuery(Painting.class)).get(0);
 
-        Artist artistAfter = fetchArtist("artist3", false);
-        assertNotNull(artistAfter);
+        assertNull(painting.getToArtist());
 
-        // update via DataNode directly
-        updateRow(painting.getObjectId(), "ARTIST_ID", artistAfter
-                .getObjectId()
-                .getIdSnapshot()
-                .get("ARTIST_ID"));
+        assertEquals(1, tPainting.update().set("ARTIST_ID", 5).execute());
 
         // select without prefetch
-        painting = fetchPainting(painting.getPaintingTitle(), false);
+        painting = (Painting) context
+                .performQuery(new SelectQuery(Painting.class))
+                .get(0);
         assertNotNull(painting);
-        assertSame(artistAfter, painting.getToArtist());
+        assertEquals("artist2", painting.getToArtist().getArtistName());
     }
 
     public void testRefetchRootWithDeletedToMany() throws Exception {
-        Painting painting = insertPaintingInContext("p");
-        Artist artist = painting.getToArtist();
+        createSingleArtistAndPaintingDataSet();
+
+        Artist artist = (Artist) context.performQuery(new SelectQuery(Artist.class)).get(
+                0);
         assertEquals(artist.getPaintingArray().size(), 1);
 
-        deleteRow(painting.getObjectId());
+        assertEquals(1, tPainting
+                .delete()
+                .where(Painting.PAINTING_ID_PK_COLUMN, 4)
+                .execute());
 
         // select without prefetch
-        artist = fetchArtist(artist.getArtistName(), false);
+        artist = (Artist) context.performQuery(new SelectQuery(Artist.class)).get(0);
         assertEquals(artist.getPaintingArray().size(), 1);
 
         // select using relationship prefetching
-        artist = fetchArtist(artist.getArtistName(), true);
+        SelectQuery query = new SelectQuery(Artist.class);
+        query.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);
+        artist = (Artist) context.performQuery(query).get(0);
         assertEquals(0, artist.getPaintingArray().size());
     }
 
     public void testRefetchRootWithAddedToMany() throws Exception {
-        Artist artist = fetchArtist("artist2", false);
+
+        createSingleArtistDataSet();
+
+        Artist artist = (Artist) context.performQuery(new SelectQuery(Artist.class)).get(
+                0);
         assertEquals(artist.getPaintingArray().size(), 0);
 
-        createTestData("P2");
+        tPainting.insert(5, "p", 5, 1000);
 
         // select without prefetch
-        artist = fetchArtist(artist.getArtistName(), false);
+        SelectQuery query = new SelectQuery(Artist.class);
+        artist = (Artist) context.performQuery(query).get(0);
         assertEquals(artist.getPaintingArray().size(), 0);
 
         // select using relationship prefetching
-        artist = fetchArtist(artist.getArtistName(), true);
+        query.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);
+        artist = (Artist) context.performQuery(query).get(0);
         assertEquals(artist.getPaintingArray().size(), 1);
     }
 
     public void testInvalidateRootWithUpdatedAttributes() throws Exception {
+        createSingleArtistDataSet();
+
         String nameBefore = "artist2";
         String nameAfter = "not an artist";
 
-        Artist artist = fetchArtist(nameBefore, false);
+        Artist artist = (Artist) context.performQuery(new SelectQuery(Artist.class)).get(
+                0);
         assertNotNull(artist);
         assertEquals(nameBefore, artist.getArtistName());
 
         // update via DataNode directly
-        updateRow(artist.getObjectId(), "ARTIST_NAME", nameAfter);
+        assertEquals(1, tArtist.update().set("ARTIST_NAME", nameAfter).execute());
 
         context.invalidateObjects(Collections.singletonList(artist));
         assertEquals(nameAfter, artist.getArtistName());
     }
 
     public void testInvalidateRootWithNullifiedToOne() throws Exception {
-        Painting painting = insertPaintingInContext("p");
+
+        createSingleArtistAndPaintingDataSet();
+
+        Painting painting = (Painting) context.performQuery(
+                new SelectQuery(Painting.class)).get(0);
+
         assertNotNull(painting.getToArtist());
+        assertEquals("artist2", painting.getToArtist().getArtistName());
 
-        // update via DataNode directly
-        updateRow(painting.getObjectId(), "ARTIST_ID", null);
+        assertEquals(1, tPainting.update().set("ARTIST_ID", null).execute());
 
         context.invalidateObjects(Collections.singletonList(painting));
         assertNull(painting.getToArtist());
     }
 
     public void testInvalidateRootWithChangedToOneTarget() throws Exception {
-        Painting painting = insertPaintingInContext("p");
+        createTwoArtistsAndPaintingDataSet();
+
+        Painting painting = (Painting) context.performQuery(
+                new SelectQuery(Painting.class)).get(0);
         Artist artistBefore = painting.getToArtist();
         assertNotNull(artistBefore);
+        assertEquals("artist2", artistBefore.getArtistName());
 
-        Artist artistAfter = fetchArtist("artist3", false);
-        assertNotNull(artistAfter);
-        assertNotSame(artistBefore, artistAfter);
-
-        // update via DataNode directly
-        updateRow(painting.getObjectId(), "ARTIST_ID", artistAfter
-                .getObjectId()
-                .getIdSnapshot()
-                .get("ARTIST_ID"));
+        assertEquals(1, tPainting.update().set("ARTIST_ID", 6).execute());
 
         context.invalidateObjects(Collections.singletonList(painting));
-        assertSame(artistAfter, painting.getToArtist());
+        assertNotSame(artistBefore, painting.getToArtist());
+        assertEquals("artist3", painting.getToArtist().getArtistName());
     }
 
     public void testInvalidateRootWithNullToOneTargetChangedToNotNull() throws Exception {
-        Painting painting = insertPaintingInContext("p");
-        painting.setToArtist(null);
-        context.commitChanges();
+        createSingleArtistAndUnrelatedPaintingDataSet();
 
+        Painting painting = (Painting) context.performQuery(
+                new SelectQuery(Painting.class)).get(0);
         assertNull(painting.getToArtist());
 
-        Artist artistAfter = fetchArtist("artist3", false);
-        assertNotNull(artistAfter);
-
-        // update via DataNode directly
-        updateRow(painting.getObjectId(), "ARTIST_ID", artistAfter
-                .getObjectId()
-                .getIdSnapshot()
-                .get("ARTIST_ID"));
+        assertEquals(1, tPainting.update().set("ARTIST_ID", 5).execute());
 
         context.invalidateObjects(Collections.singletonList(painting));
-        assertSame(artistAfter, painting.getToArtist());
+        assertNotNull(painting.getToArtist());
+        assertEquals("artist2", painting.getToArtist().getArtistName());
     }
 
     public void testInvalidateRootWithDeletedToMany() throws Exception {
-        Painting painting = insertPaintingInContext("p");
-        Artist artist = painting.getToArtist();
+        createSingleArtistAndPaintingDataSet();
+
+        Artist artist = (Artist) context.performQuery(new SelectQuery(Artist.class)).get(
+                0);
         assertEquals(artist.getPaintingArray().size(), 1);
 
-        deleteRow(painting.getObjectId());
+        assertEquals(1, tPainting.delete().execute());
 
         context.invalidateObjects(Collections.singletonList(artist));
         assertEquals(artist.getPaintingArray().size(), 0);
     }
 
     public void testInvaliateRootWithAddedToMany() throws Exception {
-        Artist artist = fetchArtist("artist2", false);
+
+        createSingleArtistDataSet();
+
+        Artist artist = (Artist) context.performQuery(new SelectQuery(Artist.class)).get(
+                0);
         assertEquals(artist.getPaintingArray().size(), 0);
 
-        createTestData("P2");
+        tPainting.insert(4, "p", 5, 1000);
+
         assertEquals(artist.getPaintingArray().size(), 0);
         context.invalidateObjects(Collections.singletonList(artist));
         assertEquals(artist.getPaintingArray().size(), 1);
     }
 
     public void testInvalidateThenModify() throws Exception {
-        Artist artist = fetchArtist("artist2", false);
+
+        createSingleArtistDataSet();
+
+        final Artist artist = (Artist) context
+                .performQuery(new SelectQuery(Artist.class))
+                .get(0);
         assertNotNull(artist);
 
         context.invalidateObjects(Collections.singletonList(artist));
         assertEquals(PersistenceState.HOLLOW, artist.getPersistenceState());
 
-        // this must trigger a fetch
-        artist.setArtistName("new name");
+        int queries = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
+
+            public void execute() {
+                // this must trigger a fetch
+                artist.setArtistName("new name");
+            }
+        });
+
+        assertEquals(1, queries);
         assertEquals(PersistenceState.MODIFIED, artist.getPersistenceState());
     }
 
     public void testModifyHollow() throws Exception {
-        createTestData("P2");
 
-        // reset context
-        context = createDataContext();
+        createSingleArtistAndPaintingDataSet();
 
-        Painting painting = fetchPainting("P_artist2", false);
-        Artist artist = painting.getToArtist();
+        Painting painting = (Painting) context.performQuery(
+                new SelectQuery(Painting.class)).get(0);
+        final Artist artist = painting.getToArtist();
         assertEquals(PersistenceState.HOLLOW, artist.getPersistenceState());
         assertNull(artist.readPropertyDirectly("artistName"));
 
-        // this must trigger a fetch
-        artist.setDateOfBirth(new Date());
-        assertEquals(PersistenceState.MODIFIED, artist.getPersistenceState());
-        assertNotNull(artist.readPropertyDirectly("artistName"));
-    }
+        int queries = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
 
-    /**
-     * Helper method to update a single column in a database row.
-     */
-    private void updateRow(ObjectId id, String dbAttribute, Object newValue) {
-        SQLTemplate updateQuery = new SQLTemplate(
-                id.getEntityName(),
-                "UPDATE $table SET $column = #bind($value) "
-                        + "WHERE $idColumn = #bind($id)");
-
-        ObjEntity entity = getDomain().getEntityResolver().getObjEntity(
-                id.getEntityName());
-        Map<String, Object> parameters = new HashMap<String, Object>();
-        parameters.put("table", entity.getDbEntityName());
-        parameters.put("column", dbAttribute);
-        parameters.put("value", newValue);
-        parameters.put("idColumn", id.getIdSnapshot().keySet().iterator().next());
-        parameters.put("id", id.getIdSnapshot().values().iterator().next());
-        updateQuery.setParameters(parameters);
-
-        getDomain().onQuery(null, updateQuery);
-    }
-
-    private void deleteRow(ObjectId id) {
-        SQLTemplate deleteQuery = new SQLTemplate(
-                id.getEntityName(),
-                "DELETE FROM $table " + "WHERE $idColumn = #bind($id)");
-
-        ObjEntity entity = getDomain().getEntityResolver().getObjEntity(
-                id.getEntityName());
-        Map<String, Object> parameters = new HashMap<String, Object>();
-        parameters.put("table", entity.getDbEntityName());
-        parameters.put("idColumn", id.getIdSnapshot().keySet().iterator().next());
-        parameters.put("id", id.getIdSnapshot().values().iterator().next());
-        deleteQuery.setParameters(parameters);
+            public void execute() {
+                // this must trigger a fetch
+                artist.setDateOfBirth(new Date());
+            }
+        });
 
-        getDomain().onQuery(null, deleteQuery);
+        assertEquals(1, queries);
+
+        assertEquals(PersistenceState.MODIFIED, artist.getPersistenceState());
+        assertNotNull(artist.readPropertyDirectly("artistName"));
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java?rev=956338&r1=956337&r2=956338&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java Sun Jun 20 09:27:37 2010
@@ -26,42 +26,99 @@ import java.util.Map;
 
 import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.DataRow;
-import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.dba.frontbase.FrontBaseAdapter;
 import org.apache.cayenne.dba.openbase.OpenBaseAdapter;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.EntityResult;
 import org.apache.cayenne.map.SQLResult;
 import org.apache.cayenne.query.CapsStrategy;
 import org.apache.cayenne.query.SQLTemplate;
+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.CompoundFkTestEntity;
 import org.apache.cayenne.testdo.testmap.CompoundPkTestEntity;
 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;
+import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
 
-/**
- */
-public class DataContextSQLTemplateTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextSQLTemplateTest extends ServerCase {
 
+    @Inject
     protected DataContext context;
 
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Inject
+    protected SQLTemplateCustomizer sqlTemplateCustomizer;
+
+    protected TableHelper tPainting;
+    protected TableHelper tArtist;
+    protected TableHelper tCompoundPkTest;
+    protected TableHelper tCompoundFkTest;
+
     @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        deleteTestData();
-        context = createDataContext();
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST");
+        dbHelper.deleteAll("COMPOUND_FK_TEST");
+        dbHelper.deleteAll("COMPOUND_PK_TEST");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+        tPainting = new TableHelper(dbHelper, "PAINTING");
+        tPainting.setColumns(
+                "PAINTING_ID",
+                "PAINTING_TITLE",
+                "ARTIST_ID",
+                "ESTIMATED_PRICE");
+
+        tCompoundPkTest = new TableHelper(dbHelper, "COMPOUND_PK_TEST");
+        tCompoundPkTest.setColumns("KEY1", "KEY2");
+
+        tCompoundFkTest = new TableHelper(dbHelper, "COMPOUND_FK_TEST");
+        tCompoundFkTest.setColumns("PKEY", "F_KEY1", "F_KEY2");
+    }
+
+    protected void createFourArtists() throws Exception {
+        tArtist.insert(11, "artist2");
+        tArtist.insert(101, "artist3");
+        tArtist.insert(201, "artist4");
+        tArtist.insert(3001, "artist5");
+    }
+
+    protected void createFourArtistsAndThreePaintingsDataSet() throws Exception {
+        createFourArtists();
+
+        tPainting.insert(6, "p_artist3", 11, 1000);
+        tPainting.insert(7, "p_artist2", 101, 2000);
+        tPainting.insert(8, "p_artist4", null, 3000);
+    }
+
+    protected void createTwoCompoundPKsAndCompoundFKsDataSet() throws Exception {
+        tCompoundPkTest.insert("a1", "a2");
+        tCompoundPkTest.insert("b1", "b2");
+
+        tCompoundFkTest.insert(6, "a1", "a2");
+        tCompoundFkTest.insert(7, "b1", "b2");
     }
 
     public void testSQLResultSetMappingMixed() throws Exception {
-        createTestData("prepare");
+        createFourArtistsAndThreePaintingsDataSet();
 
         String sql = "SELECT #result('t0.ARTIST_ID' 'long' 'X'), #result('t0.ARTIST_NAME' 'String' 'Y'), #result('t0.DATE_OF_BIRTH' 'Date' 'Z'), #result('count(t1.PAINTING_ID)' 'int' 'C') "
                 + "FROM ARTIST t0 LEFT JOIN PAINTING t1 ON (t0.ARTIST_ID = t1.ARTIST_ID) "
                 + "GROUP BY t0.ARTIST_ID, t0.ARTIST_NAME, t0.DATE_OF_BIRTH "
                 + "ORDER BY t0.ARTIST_ID";
 
-        DataMap map = getDomain().getMap("testmap");
+        DataMap map = context.getEntityResolver().getDataMap("testmap");
         SQLTemplate query = new SQLTemplate(map, sql, false);
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
 
@@ -75,7 +132,7 @@ public class DataContextSQLTemplateTest 
         rsMap.addColumnResult("C");
         query.setResult(rsMap);
 
-        List objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(4, objects.size());
 
         Object o1 = objects.get(0);
@@ -97,11 +154,11 @@ public class DataContextSQLTemplateTest 
     }
 
     public void testSQLResultSetMappingScalar() throws Exception {
-        createTestData("testSQLResultSetMappingScalar");
+        createFourArtists();
 
         String sql = "SELECT count(1) AS X FROM ARTIST";
 
-        DataMap map = getDomain().getMap("testmap");
+        DataMap map = context.getEntityResolver().getDataMap("testmap");
         SQLTemplate query = new SQLTemplate(map, sql, false);
         query.setTemplate(
                 FrontBaseAdapter.class.getName(),
@@ -115,7 +172,7 @@ public class DataContextSQLTemplateTest 
         rsMap.addColumnResult("X");
         query.setResult(rsMap);
 
-        List objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Object o = objects.get(0);
@@ -124,11 +181,11 @@ public class DataContextSQLTemplateTest 
     }
 
     public void testSQLResultSetMappingScalarArray() throws Exception {
-        createTestData("testSQLResultSetMappingScalar");
+        createFourArtists();
 
         String sql = "SELECT count(1) AS X, 77 AS Y FROM ARTIST";
 
-        DataMap map = getDomain().getMap("testmap");
+        DataMap map = context.getEntityResolver().getDataMap("testmap");
         SQLTemplate query = new SQLTemplate(map, sql, false);
         query.setTemplate(
                 FrontBaseAdapter.class.getName(),
@@ -143,7 +200,7 @@ public class DataContextSQLTemplateTest 
         rsMap.addColumnResult("Y");
         query.setResult(rsMap);
 
-        List objects = createDataContext().performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Object o = objects.get(0);
@@ -157,82 +214,77 @@ public class DataContextSQLTemplateTest 
     }
 
     public void testColumnNamesCapitalization() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtistsAndThreePaintingsDataSet();
 
         String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
         SQLTemplate query = new SQLTemplate(Artist.class, template);
         query.setColumnNamesCapitalization(CapsStrategy.LOWER);
         query.setFetchingDataRows(true);
 
-        List rows = context.performQuery(query);
+        List<DataRow> rows = context.performQuery(query);
 
-        DataRow row1 = (DataRow) rows.get(0);
+        DataRow row1 = rows.get(0);
         assertFalse(row1.containsKey("ARTIST_ID"));
         assertTrue(row1.containsKey("artist_id"));
 
-        DataRow row2 = (DataRow) rows.get(1);
+        DataRow row2 = rows.get(1);
         assertFalse(row2.containsKey("ARTIST_ID"));
         assertTrue(row2.containsKey("artist_id"));
 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
 
-        List rowsUpper = context.performQuery(query);
+        List<DataRow> rowsUpper = context.performQuery(query);
 
-        DataRow row3 = (DataRow) rowsUpper.get(0);
+        DataRow row3 = rowsUpper.get(0);
         assertFalse(row3.containsKey("artist_id"));
         assertTrue(row3.containsKey("ARTIST_ID"));
 
-        DataRow row4 = (DataRow) rowsUpper.get(1);
+        DataRow row4 = rowsUpper.get(1);
         assertFalse(row4.containsKey("artist_id"));
         assertTrue(row4.containsKey("ARTIST_ID"));
     }
 
     public void testFetchDataRows() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
         SQLTemplate query = new SQLTemplate(Artist.class, template);
 
-        getSQLTemplateBuilder().updateSQLTemplate(query);
+        sqlTemplateCustomizer.updateSQLTemplate(query);
 
         query.setFetchingDataRows(true);
 
-        List rows = context.performQuery(query);
-        assertEquals(DataContextCase.artistCount, rows.size());
-        assertTrue(
-                "Expected DataRow, got this: " + rows.get(1),
-                rows.get(1) instanceof DataRow);
+        List<DataRow> rows = context.performQuery(query);
+        assertEquals(4, rows.size());
 
-        DataRow row2 = (DataRow) rows.get(1);
+        DataRow row2 = rows.get(1);
         assertEquals(3, row2.size());
         Object id = row2.get("ARTIST_ID");
-        assertEquals(new Integer(33002), new Integer(id.toString()));
+        assertEquals(new Integer(101), new Integer(id.toString()));
     }
 
     public void testFetchObjects() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
-        SQLTemplate query = getSQLTemplateBuilder().createSQLTemplate(
+        SQLTemplate query = sqlTemplateCustomizer.createSQLTemplate(
                 Artist.class,
                 template);
 
         query.setFetchingDataRows(false);
 
-        List objects = context.performQuery(query);
-        assertEquals(DataContextCase.artistCount, objects.size());
+        List<?> objects = context.performQuery(query);
+        assertEquals(4, objects.size());
         assertTrue(objects.get(1) instanceof Artist);
 
         Artist artist2 = (Artist) objects.get(1);
-        assertEquals("artist2", artist2.getArtistName());
+        assertEquals("artist3", artist2.getArtistName());
     }
 
     public void testBindObjectEqualShort() throws Exception {
-        createTestData("prepare");
-
-        ObjectContext context = createDataContext();
+        createFourArtistsAndThreePaintingsDataSet();
 
-        Artist a = Cayenne.objectForPK(context, Artist.class, 33002);
+        Artist a = Cayenne.objectForPK(context, Artist.class, 101);
 
         String template = "SELECT * FROM PAINTING "
                 + "WHERE #bindObjectEqual($a) ORDER BY PAINTING_ID";
@@ -240,19 +292,17 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("a", a));
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Painting p = (Painting) objects.get(0);
-        assertEquals(33002, Cayenne.intPKForObject(p));
+        assertEquals(7, Cayenne.intPKForObject(p));
     }
 
     public void testBindObjectNotEqualShort() throws Exception {
-        createTestData("prepare");
+        createFourArtistsAndThreePaintingsDataSet();
 
-        ObjectContext context = createDataContext();
-
-        Artist a = Cayenne.objectForPK(context, Artist.class, 33002);
+        Artist a = Cayenne.objectForPK(context, Artist.class, 101);
 
         String template = "SELECT * FROM PAINTING "
                 + "WHERE #bindObjectNotEqual($a) ORDER BY PAINTING_ID";
@@ -260,22 +310,20 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("a", a));
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
 
         // null comparison is unpredictable across DB's ... some would return true on null
         // <> value, some - false
         assertTrue(objects.size() == 1 || objects.size() == 2);
 
         Painting p = (Painting) objects.get(0);
-        assertEquals(33001, Cayenne.intPKForObject(p));
+        assertEquals(6, Cayenne.intPKForObject(p));
     }
 
     public void testBindObjectEqualFull() throws Exception {
-        createTestData("prepare");
-
-        ObjectContext context = createDataContext();
+        createFourArtistsAndThreePaintingsDataSet();
 
-        Artist a = Cayenne.objectForPK(context, Artist.class, 33002);
+        Artist a = Cayenne.objectForPK(context, Artist.class, 101);
 
         String template = "SELECT * FROM PAINTING t0"
                 + " WHERE #bindObjectEqual($a [ 't0.ARTIST_ID' ] [ 'ARTIST_ID' ] ) ORDER BY PAINTING_ID";
@@ -283,19 +331,17 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("a", a));
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Painting p = (Painting) objects.get(0);
-        assertEquals(33002, Cayenne.intPKForObject(p));
+        assertEquals(7, Cayenne.intPKForObject(p));
     }
 
     public void testBindObjectEqualFullNonArray() throws Exception {
-        createTestData("prepare");
+        createFourArtistsAndThreePaintingsDataSet();
 
-        ObjectContext context = createDataContext();
-
-        Artist a = Cayenne.objectForPK(context, Artist.class, 33002);
+        Artist a = Cayenne.objectForPK(context, Artist.class, 101);
 
         String template = "SELECT * FROM PAINTING t0"
                 + " WHERE #bindObjectEqual($a 't0.ARTIST_ID' 'ARTIST_ID' ) ORDER BY PAINTING_ID";
@@ -303,17 +349,15 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("a", a));
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Painting p = (Painting) objects.get(0);
-        assertEquals(33002, Cayenne.intPKForObject(p));
+        assertEquals(7, Cayenne.intPKForObject(p));
     }
 
     public void testBindObjectEqualNull() throws Exception {
-        createTestData("prepare");
-
-        ObjectContext context = createDataContext();
+        createFourArtistsAndThreePaintingsDataSet();
 
         String template = "SELECT * FROM PAINTING t0"
                 + " WHERE #bindObjectEqual($a [ 't0.ARTIST_ID' ] [ 'ARTIST_ID' ] ) ORDER BY PAINTING_ID";
@@ -321,19 +365,17 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("a", null));
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
         Painting p = (Painting) objects.get(0);
-        assertEquals(33003, Cayenne.intPKForObject(p));
+        assertEquals(8, Cayenne.intPKForObject(p));
     }
 
     public void testBindObjectNotEqualFull() throws Exception {
-        createTestData("prepare");
+        createFourArtistsAndThreePaintingsDataSet();
 
-        ObjectContext context = createDataContext();
-
-        Artist a = Cayenne.objectForPK(context, Artist.class, 33002);
+        Artist a = Cayenne.objectForPK(context, Artist.class, 101);
 
         String template = "SELECT * FROM PAINTING t0"
                 + " WHERE #bindObjectNotEqual($a [ 't0.ARTIST_ID' ] [ 'ARTIST_ID' ] ) ORDER BY PAINTING_ID";
@@ -341,19 +383,17 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("a", a));
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         // null comparison is unpredictable across DB's ... some would return true on null
         // <> value, some - false
         assertTrue(objects.size() == 1 || objects.size() == 2);
 
         Painting p = (Painting) objects.get(0);
-        assertEquals(33001, Cayenne.intPKForObject(p));
+        assertEquals(6, Cayenne.intPKForObject(p));
     }
 
     public void testBindObjectEqualCompound() throws Exception {
-        createTestData("testBindObjectEqualCompound");
-
-        ObjectContext context = createDataContext();
+        createTwoCompoundPKsAndCompoundFKsDataSet();
 
         Map<String, String> pk = new HashMap<String, String>();
         pk.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "a1");
@@ -370,17 +410,15 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("a", a));
 
-        List objects = context.performQuery(query);
+        List<CompoundFkTestEntity> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
-        CompoundFkTestEntity p = (CompoundFkTestEntity) objects.get(0);
-        assertEquals(33001, Cayenne.intPKForObject(p));
+        CompoundFkTestEntity p = objects.get(0);
+        assertEquals(6, Cayenne.intPKForObject(p));
     }
 
     public void testBindObjectNotEqualCompound() throws Exception {
-        createTestData("testBindObjectEqualCompound");
-
-        ObjectContext context = createDataContext();
+        createTwoCompoundPKsAndCompoundFKsDataSet();
 
         Map<String, String> pk = new HashMap<String, String>();
         pk.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "a1");
@@ -397,17 +435,15 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("a", a));
 
-        List objects = context.performQuery(query);
+        List<CompoundFkTestEntity> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
-        CompoundFkTestEntity p = (CompoundFkTestEntity) objects.get(0);
-        assertEquals(33002, Cayenne.intPKForObject(p));
+        CompoundFkTestEntity p = objects.get(0);
+        assertEquals(7, Cayenne.intPKForObject(p));
     }
 
     public void testBindObjectNotEqualNull() throws Exception {
-        createTestData("prepare");
-
-        ObjectContext context = createDataContext();
+        createFourArtistsAndThreePaintingsDataSet();
 
         String template = "SELECT * FROM PAINTING t0"
                 + " WHERE #bindObjectNotEqual($a [ 't0.ARTIST_ID' ] [ 'ARTIST_ID' ] ) ORDER BY PAINTING_ID";
@@ -415,20 +451,18 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("a", null));
 
-        List objects = context.performQuery(query);
+        List<Painting> objects = context.performQuery(query);
         assertEquals(2, objects.size());
 
-        Painting p1 = (Painting) objects.get(0);
-        assertEquals(33001, Cayenne.intPKForObject(p1));
+        Painting p1 = objects.get(0);
+        assertEquals(6, Cayenne.intPKForObject(p1));
 
-        Painting p2 = (Painting) objects.get(1);
-        assertEquals(33002, Cayenne.intPKForObject(p2));
+        Painting p2 = objects.get(1);
+        assertEquals(7, Cayenne.intPKForObject(p2));
     }
-    
-    public void testBindEqualNull() throws Exception {
-        createTestData("prepare");
 
-        ObjectContext context = createDataContext();
+    public void testBindEqualNull() throws Exception {
+        createFourArtistsAndThreePaintingsDataSet();
 
         String template = "SELECT * FROM PAINTING t0"
                 + " WHERE t0.ARTIST_ID #bindEqual($id) ORDER BY PAINTING_ID";
@@ -436,105 +470,104 @@ public class DataContextSQLTemplateTest 
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("id", null));
 
-        List objects = context.performQuery(query);
+        List<Painting> objects = context.performQuery(query);
         assertEquals(1, objects.size());
 
-        Painting p = (Painting) objects.get(0);
-        assertEquals(33003, Cayenne.intPKForObject(p));
+        Painting p = objects.get(0);
+        assertEquals(8, Cayenne.intPKForObject(p));
     }
 
     public void testFetchLimit() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
-        int fetchLimit = 3;
+        int fetchLimit = 2;
 
         // sanity check
-        assertTrue(fetchLimit < DataContextCase.artistCount);
+        assertTrue(fetchLimit < 4);
         String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
-        SQLTemplate query = getSQLTemplateBuilder().createSQLTemplate(
+        SQLTemplate query = sqlTemplateCustomizer.createSQLTemplate(
                 Artist.class,
                 template);
         query.setFetchLimit(fetchLimit);
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(fetchLimit, objects.size());
         assertTrue(objects.get(0) instanceof Artist);
     }
 
     public void testFetchOffset() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
-        int fetchOffset = 3;
+        int fetchOffset = 2;
 
         // sanity check
-        assertTrue(fetchOffset < DataContextCase.artistCount);
+        assertTrue(fetchOffset < 4);
         String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
-        SQLTemplate query = getSQLTemplateBuilder().createSQLTemplate(
+        SQLTemplate query = sqlTemplateCustomizer.createSQLTemplate(
                 Artist.class,
                 template);
         query.setFetchOffset(fetchOffset);
 
-        List objects = context.performQuery(query);
-        assertEquals(DataContextCase.artistCount - fetchOffset, objects.size());
+        List<?> objects = context.performQuery(query);
+        assertEquals(4 - fetchOffset, objects.size());
         assertTrue(objects.get(0) instanceof Artist);
     }
 
     public void testFetchOffsetFetchLimit() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
-        SQLTemplate query = getSQLTemplateBuilder().createSQLTemplate(
+        SQLTemplate query = sqlTemplateCustomizer.createSQLTemplate(
                 Artist.class,
                 template);
         query.setFetchOffset(1);
         query.setFetchLimit(2);
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(2, objects.size());
         assertTrue(objects.get(0) instanceof Artist);
     }
 
     public void testPageSize() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         int pageSize = 3;
 
         // sanity check
-        assertTrue(pageSize < DataContextCase.artistCount);
+        assertTrue(pageSize < 4);
 
         String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
-        SQLTemplate query = getSQLTemplateBuilder().createSQLTemplate(
+        SQLTemplate query = sqlTemplateCustomizer.createSQLTemplate(
                 Artist.class,
                 template);
 
         query.setPageSize(pageSize);
 
-        List objects = context.performQuery(query);
-        
-        assertEquals(DataContextCase.artistCount, objects.size());
+        List<?> objects = context.performQuery(query);
+
+        assertEquals(4, objects.size());
         assertTrue(objects.get(0) instanceof Artist);
 
-        assertTrue(objects instanceof IncrementalFaultList);
-        IncrementalFaultList pagedList = (IncrementalFaultList) objects;
-        assertEquals(DataContextCase.artistCount - pageSize, pagedList
-                .getUnfetchedObjects());
+        assertTrue(objects instanceof IncrementalFaultList<?>);
+        IncrementalFaultList<?> pagedList = (IncrementalFaultList<?>) objects;
+        assertEquals(4 - pageSize, pagedList.getUnfetchedObjects());
 
         // check if we can resolve subsequent pages
         Artist artist = (Artist) objects.get(pageSize);
 
-        int expectUnresolved = DataContextCase.artistCount - pageSize - pageSize;
+        int expectUnresolved = 4 - pageSize - pageSize;
         if (expectUnresolved < 0) {
             expectUnresolved = 0;
         }
         assertEquals(expectUnresolved, pagedList.getUnfetchedObjects());
-        assertEquals("artist" + (pageSize + 1), artist.getArtistName());
+        assertEquals("artist" + (pageSize + 2), artist.getArtistName());
     }
 
     public void testIteratedQuery() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
-        SQLTemplate query = getSQLTemplateBuilder().createSQLTemplate(
+        SQLTemplate query = sqlTemplateCustomizer.createSQLTemplate(
                 Artist.class,
                 template);
 
@@ -548,31 +581,30 @@ public class DataContextSQLTemplateTest 
 
                 DataRow row = (DataRow) it.nextRow();
                 assertEquals(3, row.size());
-                Object id = row.get("ARTIST_ID");
-                assertEquals(new Integer((int) (33000 + i)), new Integer(id.toString()));
+                assertEquals("artist" + (1 + i), row.get("ARTIST_NAME"));
             }
 
-            assertEquals(DataContextCase.artistCount, i);
+            assertEquals(4, i);
         }
         finally {
             it.close();
         }
     }
 
-    public void testQueryWithLineBreakAfterMacroCAY726() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+    public void testQueryWithLineBreakAfterMacro() throws Exception {
+        createFourArtists();
 
         // see CAY-726 for details
         String template = "SELECT #result('count(*)' 'int' 'X')"
                 + System.getProperty("line.separator")
                 + "FROM ARTIST";
-        SQLTemplate query = getSQLTemplateBuilder().createSQLTemplate(
+        SQLTemplate query = sqlTemplateCustomizer.createSQLTemplate(
                 Artist.class,
                 template);
         query.setFetchingDataRows(true);
 
-        List result = context.performQuery(query);
+        List<?> result = context.performQuery(query);
 
-        assertEquals(new Integer(25), ((Map) result.get(0)).get("X"));
+        assertEquals(4, ((DataRow) result.get(0)).get("X"));
     }
 }

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=956338&r1=956337&r2=956338&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 Sun Jun 20 09:27:37 2010
@@ -78,7 +78,7 @@ public class DataContextTest extends Ser
     protected TableHelper tArtist;
     protected TableHelper tExhibit;
     protected TableHelper tGallery;
-    protected TableHelper tPaining;
+    protected TableHelper tPainting;
 
     @Override
     protected void setUpAfterInjection() throws Exception {
@@ -98,8 +98,8 @@ public class DataContextTest extends Ser
         tGallery = new TableHelper(dbHelper, "GALLERY");
         tGallery.setColumns("GALLERY_ID", "GALLERY_NAME");
 
-        tPaining = new TableHelper(dbHelper, "PAINTING");
-        tPaining.setColumns(
+        tPainting = new TableHelper(dbHelper, "PAINTING");
+        tPainting.setColumns(
                 "PAINTING_ID",
                 "PAINTING_TITLE",
                 "ARTIST_ID",
@@ -144,13 +144,13 @@ public class DataContextTest extends Ser
     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);
+        tPainting.insert(33001, "P_artist1", 33001, 1000);
+        tPainting.insert(33002, "P_artist2", 33002, 2000);
+        tPainting.insert(33003, "P_artist3", 33003, 3000);
+        tPainting.insert(33004, "P_artist4", 33004, 4000);
+        tPainting.insert(33005, "P_artist5", 33005, 5000);
+        tPainting.insert(33006, "P_artist11", 33006, 11000);
+        tPainting.insert(33007, "P_artist21", 33007, 21000);
     }
 
     public void testCurrentSnapshot1() throws Exception {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataNodeQueriesTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataNodeQueriesTest.java?rev=956338&r1=956337&r2=956338&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataNodeQueriesTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataNodeQueriesTest.java Sun Jun 20 09:27:37 2010
@@ -19,37 +19,56 @@
 
 package org.apache.cayenne.access;
 
-import java.sql.Connection;
 import java.sql.Date;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.SQLAction;
 import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.CayenneCase;
-
-/**
- * DataNode test cases.
- * 
- */
-public class DataNodeQueriesTest extends CayenneCase {
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataNodeQueriesTest extends ServerCase {
+
+    @Inject
+    protected DataNode node;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Inject
+    protected SQLTemplateCustomizer sqlTemplateCustomizer;
+
+    protected TableHelper tArtist;
 
     @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");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
     }
 
-    public void testCreatePkSupportForMapEntities() throws Exception {
-        getAccessStack().createPKSupport();
+    protected void createFourArtists() throws Exception {
+        tArtist.insert(11, "artist2");
+        tArtist.insert(101, "artist3");
+        tArtist.insert(201, "artist4");
+        tArtist.insert(3001, "artist5");
+    }
 
-        DataNode node = getNode();
+    public void testCreatePkSupportForMapEntities() throws Exception {
 
         DbEntity artistEnt = node.getEntityResolver().getDbEntity("ARTIST");
         assertNotNull(node.getAdapter().getPkGenerator().generatePk(
@@ -67,118 +86,103 @@ public class DataNodeQueriesTest extends
                 + "VALUES (#bind($id), #bind($name), #bind($dob 'DATE'))";
         SQLTemplate query = new SQLTemplate(Object.class, template);
 
-        Map bindings = new HashMap();
+        Map<String, Object> bindings = new HashMap<String, Object>();
         bindings.put("id", 1l);
         bindings.put("name", "a1");
         bindings.put("dob", new Date(System.currentTimeMillis()));
         query.setParameters(bindings);
 
         MockOperationObserver observer = new MockOperationObserver();
-        getNode().performQueries(Collections.singletonList((Query) query), observer);
+        node.performQueries(Collections.singletonList((Query) query), observer);
         assertNotNull(observer.countsForQuery(query));
         assertEquals(1, observer.countsForQuery(query)[0]);
 
         // check the data
-        MockOperationObserver checkObserver = new MockOperationObserver();
-        SelectQuery checkQuery = new SelectQuery(Artist.class);
-        getDomain().performQueries(Collections.singletonList(checkQuery), checkObserver);
-        List data = checkObserver.rowsForQuery(checkQuery);
-        assertEquals(1, data.size());
-        Map row = (Map) data.get(0);
-        assertEquals(bindings.get("id"), row.get("ARTIST_ID"));
-        assertEquals(bindings.get("name"), row.get("ARTIST_NAME"));
-        // to compare dates we need to create the binding correctly
-        // assertEquals(bindings.get("dob"), row.get("DATE_OF_BIRTH"));
+
+        assertEquals(1, tArtist.getRowCount());
+        assertEquals(1l, tArtist.getLong("ARTIST_ID"));
+        assertEquals("a1", tArtist.getString("ARTIST_NAME").trim());
     }
 
     public void testPerfomQueriesSelectingSQLTemplate1() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         String template = "SELECT #result('ARTIST_ID' 'int') FROM ARTIST ORDER BY ARTIST_ID";
         SQLTemplate query = new SQLTemplate(Object.class, template);
 
         MockOperationObserver observer = new MockOperationObserver();
-        getNode().performQueries(Collections.singletonList((Query) query), observer);
+        node.performQueries(Collections.singletonList((Query) query), observer);
 
-        List data = observer.rowsForQuery(query);
-        assertEquals(DataContextCase.artistCount, data.size());
-        Map row = (Map) data.get(2);
+        List<DataRow> data = observer.rowsForQuery(query);
+        assertEquals(4, data.size());
+        DataRow row = data.get(2);
         assertEquals(1, row.size());
-        assertEquals(new Integer(33003), row.get("ARTIST_ID"));
+        assertEquals(201, row.get("ARTIST_ID"));
     }
 
     public void testPerfomQueriesSelectingSQLTemplate2() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
         SQLTemplate query = new SQLTemplate(Object.class, template);
-        getSQLTemplateBuilder().updateSQLTemplate(query);
+        sqlTemplateCustomizer.updateSQLTemplate(query);
 
         MockOperationObserver observer = new MockOperationObserver();
-        getNode().performQueries(Collections.singletonList((Query) query), observer);
+        node.performQueries(Collections.singletonList((Query) query), observer);
 
-        List data = observer.rowsForQuery(query);
-        assertEquals(DataContextCase.artistCount, data.size());
-        Map row = (Map) data.get(2);
+        List<DataRow> data = observer.rowsForQuery(query);
+        assertEquals(4, data.size());
+        DataRow row = data.get(2);
         assertEquals(3, row.size());
 
         Number id = (Number) row.get("ARTIST_ID");
         assertNotNull(id);
-        assertEquals("Can't find ARTIST_ID: " + row, 33003, id.intValue());
+        assertEquals(201, id.intValue());
     }
 
     public void testPerfomQueriesSelectingSQLTemplateAlias() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         String template = "SELECT #result('ARTIST_ID' 'int' 'A') FROM ARTIST ORDER BY ARTIST_ID";
-        SQLTemplate query = new SQLTemplate(Object.class, template);
+        Query query = new SQLTemplate(Object.class, template);
 
         MockOperationObserver observer = new MockOperationObserver();
-        getNode().performQueries(Collections.singletonList((Query) query), observer);
+        node.performQueries(Collections.singletonList(query), observer);
 
-        List data = observer.rowsForQuery(query);
-        assertEquals(DataContextCase.artistCount, data.size());
-        Map row = (Map) data.get(2);
+        List<DataRow> data = observer.rowsForQuery(query);
+        assertEquals(4, data.size());
+        DataRow row = data.get(2);
         assertEquals(1, row.size());
-        assertEquals(new Integer(33003), row.get("A"));
+        assertEquals(201, row.get("A"));
     }
 
     public void testRunMultiLineSQLTemplateUNIX() throws Exception {
         String templateString = "INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME)"
                 + "\n"
                 + "VALUES (1, 'A')";
-        runSQL(templateString);
+        Query template = new SQLTemplate(Object.class, templateString);
+        node.performQueries(
+                Collections.singletonList(template),
+                new MockOperationObserver());
     }
 
     public void testRunMultiLineSQLTemplateWindows() throws Exception {
         String templateString = "INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME)"
                 + "\r\n"
                 + "VALUES (1, 'A')";
-        runSQL(templateString);
+        Query template = new SQLTemplate(Object.class, templateString);
+        node.performQueries(
+                Collections.singletonList(template),
+                new MockOperationObserver());
     }
 
     public void testRunMultiLineSQLTemplateMac() throws Exception {
         String templateString = "INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME)"
                 + "\r"
                 + "VALUES (1, 'A')";
-        runSQL(templateString);
+        Query template = new SQLTemplate(Object.class, templateString);
+        node.performQueries(
+                Collections.singletonList(template),
+                new MockOperationObserver());
     }
-
-    /**
-     * Testing that SQLTemplate that is entered on multiple lines can be executed. CAY-269
-     * shows that some databases are very picky about it.
-     */
-    private void runSQL(String templateString) throws Exception {
-        SQLTemplate template = new SQLTemplate(Object.class, templateString);
-        SQLAction action = getNode().getAdapter().getAction(template, getNode());
-
-        Connection c = getConnection();
-        try {
-            action.performAction(c, new MockOperationObserver());
-        }
-        finally {
-            c.close();
-        }
-    }
-
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataRowUtilsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataRowUtilsTest.java?rev=956338&r1=956337&r2=956338&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataRowUtilsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataRowUtilsTest.java Sun Jun 20 09:27:37 2010
@@ -22,37 +22,65 @@ package org.apache.cayenne.access;
 import java.util.List;
 
 import org.apache.cayenne.DataRow;
-import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.reflect.ArcProperty;
 import org.apache.cayenne.reflect.ClassDescriptor;
+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.Gallery;
 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 DataRowUtilsTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataRowUtilsTest extends ServerCase {
 
+    @Inject
     protected DataContext context;
 
+    @Inject
+    protected DBHelper dbHelper;
+
+    protected TableHelper tArtist;
+    protected TableHelper tPainting;
+
     @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    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",
+                "PAINTING_TITLE",
+                "ARTIST_ID",
+                "ESTIMATED_PRICE");
+    }
+
+    protected void createOneArtist() throws Exception {
+        tArtist.insert(11, "artist2");
+    }
 
-        deleteTestData();
-        context = createDataContext();
+    protected void createOneArtistAndOnePainting() throws Exception {
+        tArtist.insert(11, "artist2");
+        tPainting.insert(6, "p_artist2", 11, 1000);
     }
 
     public void testMerge() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createOneArtist();
 
         String n1 = "changed";
         String n2 = "changed again";
 
-        SelectQuery artistQ = new SelectQuery(Artist.class, Expression
-                .fromString("artistName = 'artist1'"));
+        SelectQuery artistQ = new SelectQuery(Artist.class);
         Artist a1 = (Artist) context.performQuery(artistQ).get(0);
         a1.setArtistName(n1);
 
@@ -71,24 +99,26 @@ public class DataRowUtilsTest extends Ca
     }
 
     public void testIsToOneTargetModified() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createOneArtist();
 
         ClassDescriptor d = context.getEntityResolver().getClassDescriptor("Painting");
         ArcProperty toArtist = (ArcProperty) d.getProperty("toArtist");
 
-        SelectQuery artistQ = new SelectQuery(Artist.class, Expression
-                .fromString("artistName = 'artist2'"));
-        Artist anotherArtist = (Artist) context.performQuery(artistQ).get(0);
+        Artist artist2 = (Artist) context
+                .performQuery(new SelectQuery(Artist.class))
+                .get(0);
         Painting painting = context.newObject(Painting.class);
         painting.setPaintingTitle("PX");
-        painting.setToArtist(anotherArtist);
+        painting.setToArtist(artist2);
 
         context.commitChanges();
 
-        artistQ = new SelectQuery(Artist.class, Expression
-                .fromString("artistName = 'artist1'"));
-        Artist artist = (Artist) context.performQuery(artistQ).get(0);
-        assertNotSame(artist, painting.getToArtist());
+        tArtist.insert(119, "artist3");
+        SelectQuery query = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
+                Artist.ARTIST_NAME_PROPERTY,
+                "artist3"));
+        Artist artist3 = (Artist) context.performQuery(query).get(0);
+        assertNotSame(artist3, painting.getToArtist());
 
         ObjectDiff diff = context.getObjectStore().registerDiff(
                 painting.getObjectId(),
@@ -96,17 +126,17 @@ public class DataRowUtilsTest extends Ca
 
         assertFalse(DataRowUtils.isToOneTargetModified(toArtist, painting, diff));
 
-        painting.setToArtist(artist);
+        painting.setToArtist(artist3);
         assertTrue(DataRowUtils.isToOneTargetModified(toArtist, painting, diff));
     }
 
     public void testIsToOneTargetModifiedWithNewTarget() throws Exception {
-        createTestData("testIsToOneTargetModifiedWithNewTarget");
+        createOneArtistAndOnePainting();
 
         // add NEW gallery to painting
-        List paintings = context.performQuery(new SelectQuery(Painting.class));
+        List<Painting> paintings = context.performQuery(new SelectQuery(Painting.class));
         assertEquals(1, paintings.size());
-        Painting p1 = (Painting) paintings.get(0);
+        Painting p1 = paintings.get(0);
 
         ClassDescriptor d = context.getEntityResolver().getClassDescriptor("Painting");
         ArcProperty toGallery = (ArcProperty) d.getProperty("toGallery");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java?rev=956338&r1=956337&r2=956338&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java Sun Jun 20 09:27:37 2010
@@ -26,56 +26,98 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cayenne.access.DataContextCase;
+import javax.sql.DataSource;
+
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.MockOperationObserver;
-import org.apache.cayenne.access.QueryResult;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.JdbcAdapter;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLAction;
 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.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SQLTemplateActionTest extends ServerCase {
+
+    @Inject
+    protected DataSource dataSource;
+
+    @Inject
+    protected DataNode node;
+
+    @Inject
+    protected DbAdapter adapter;
+
+    @Inject
+    protected ObjectContext objectContext;
 
-/**
- */
-public class SQLTemplateActionTest extends CayenneCase {
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Inject
+    protected SQLTemplateCustomizer sqlTemplateCustomizer;
+
+    protected TableHelper tArtist;
 
     @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");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME", "DATE_OF_BIRTH");
+    }
+
+    protected void createFourArtists() throws Exception {
+
+        Date date = new Date(System.currentTimeMillis());
+
+        tArtist.insert(11, "artist2", date);
+        tArtist.insert(101, "artist3", date);
+        tArtist.insert(201, "artist4", date);
+        tArtist.insert(3001, "artist5", date);
     }
 
     public void testProperties() throws Exception {
         DbAdapter adapter = new JdbcAdapter();
         SQLTemplate template = new SQLTemplate(Object.class, "AAAAA");
-        SQLTemplateAction action = new SQLTemplateAction(template, adapter, getDomain()
+        SQLTemplateAction action = new SQLTemplateAction(template, adapter, objectContext
                 .getEntityResolver());
         assertSame(adapter, action.getAdapter());
         assertSame(template, action.getQuery());
     }
 
     public void testExecuteSelect() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         String templateString = "SELECT * FROM ARTIST WHERE ARTIST_ID = #bind($id)";
         SQLTemplate template = new SQLTemplate(Object.class, templateString);
-        getSQLTemplateBuilder().updateSQLTemplate(template);
+        sqlTemplateCustomizer.updateSQLTemplate(template);
 
-        Map bindings = new HashMap();
-        bindings.put("id", new Long(33005l));
+        Map<String, Object> bindings = new HashMap<String, Object>();
+        bindings.put("id", 201l);
         template.setParameters(bindings);
 
         // must ensure the right SQLTemplateAction is created
-        DbAdapter adapter = getAccessStackAdapter().getAdapter();
-        SQLAction plan = adapter.getAction(template, getNode());
+
+        SQLAction plan = adapter.getAction(template, node);
         assertTrue(plan instanceof SQLTemplateAction);
 
         MockOperationObserver observer = new MockOperationObserver();
-        Connection c = getConnection();
+        Connection c = dataSource.getConnection();
 
         try {
             plan.performAction(c, observer);
@@ -84,10 +126,10 @@ public class SQLTemplateActionTest exten
             c.close();
         }
 
-        List rows = observer.rowsForQuery(template);
+        List<DataRow> rows = observer.rowsForQuery(template);
         assertNotNull(rows);
         assertEquals(1, rows.size());
-        Map row = (Map) rows.get(0);
+        DataRow row = rows.get(0);
 
         // In the absence of ObjEntity most DB's return a Long here, except for Oracle
         // that has no BIGINT type and
@@ -95,29 +137,26 @@ public class SQLTemplateActionTest exten
         Number id = (Number) row.get("ARTIST_ID");
         assertNotNull(id);
         assertEquals(((Number) bindings.get("id")).longValue(), id.longValue());
-        assertEquals("artist5", row.get("ARTIST_NAME"));
+        assertEquals("artist4", row.get("ARTIST_NAME"));
         assertTrue(row.containsKey("DATE_OF_BIRTH"));
     }
 
     public void testSelectUtilDate() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
-        // update data set to include dates....
-        setDate(new java.util.Date(), 33006);
+        createFourArtists();
 
         String templateString = "SELECT #result('DATE_OF_BIRTH' 'java.util.Date' 'DOB') "
                 + "FROM ARTIST WHERE ARTIST_ID = #bind($id)";
         SQLTemplate template = new SQLTemplate(Object.class, templateString);
-        getSQLTemplateBuilder().updateSQLTemplate(template);
+        sqlTemplateCustomizer.updateSQLTemplate(template);
 
-        Map bindings = new HashMap();
-        bindings.put("id", new Integer(33006));
+        Map<String, Object> bindings = new HashMap<String, Object>();
+        bindings.put("id", 101);
         template.setParameters(bindings);
 
-        DbAdapter adapter = getAccessStackAdapter().getAdapter();
-        SQLAction plan = adapter.getAction(template, getNode());
+        SQLAction plan = adapter.getAction(template, node);
 
         MockOperationObserver observer = new MockOperationObserver();
-        Connection c = getConnection();
+        Connection c = dataSource.getConnection();
 
         try {
             plan.performAction(c, observer);
@@ -126,34 +165,31 @@ public class SQLTemplateActionTest exten
             c.close();
         }
 
-        List rows = observer.rowsForQuery(template);
+        List<DataRow> rows = observer.rowsForQuery(template);
         assertNotNull(rows);
         assertEquals(1, rows.size());
-        Map row = (Map) rows.get(0);
+        DataRow row = rows.get(0);
 
         assertNotNull(row.get("DOB"));
         assertEquals(java.util.Date.class, row.get("DOB").getClass());
     }
 
     public void testSelectSQLDate() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
-        // update data set to include dates....
-        setDate(new java.util.Date(), 33006);
+        createFourArtists();
 
         String templateString = "SELECT #result('DATE_OF_BIRTH' 'java.sql.Date' 'DOB') "
                 + "FROM ARTIST WHERE ARTIST_ID = #bind($id)";
         SQLTemplate template = new SQLTemplate(Object.class, templateString);
-        getSQLTemplateBuilder().updateSQLTemplate(template);
+        sqlTemplateCustomizer.updateSQLTemplate(template);
 
-        Map bindings = new HashMap();
-        bindings.put("id", new Integer(33006));
+        Map<String, Object> bindings = new HashMap<String, Object>();
+        bindings.put("id", 101);
         template.setParameters(bindings);
 
-        DbAdapter adapter = getAccessStackAdapter().getAdapter();
-        SQLAction plan = adapter.getAction(template, getNode());
+        SQLAction plan = adapter.getAction(template, node);
 
         MockOperationObserver observer = new MockOperationObserver();
-        Connection c = getConnection();
+        Connection c = dataSource.getConnection();
 
         try {
             plan.performAction(c, observer);
@@ -162,34 +198,31 @@ public class SQLTemplateActionTest exten
             c.close();
         }
 
-        List rows = observer.rowsForQuery(template);
+        List<DataRow> rows = observer.rowsForQuery(template);
         assertNotNull(rows);
         assertEquals(1, rows.size());
-        Map row = (Map) rows.get(0);
+        DataRow row = rows.get(0);
 
         assertNotNull(row.get("DOB"));
         assertEquals(java.sql.Date.class, row.get("DOB").getClass());
     }
 
     public void testSelectSQLTimestamp() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
-        // update data set to include dates....
-        setDate(new java.util.Date(), 33006);
+        createFourArtists();
 
         String templateString = "SELECT #result('DATE_OF_BIRTH' 'java.sql.Timestamp' 'DOB') "
                 + "FROM ARTIST WHERE ARTIST_ID = #bind($id)";
         SQLTemplate template = new SQLTemplate(Object.class, templateString);
-        getSQLTemplateBuilder().updateSQLTemplate(template);
+        sqlTemplateCustomizer.updateSQLTemplate(template);
 
-        Map bindings = new HashMap();
-        bindings.put("id", new Integer(33006));
+        Map<String, Object> bindings = new HashMap<String, Object>();
+        bindings.put("id", 201);
         template.setParameters(bindings);
 
-        DbAdapter adapter = getAccessStackAdapter().getAdapter();
-        SQLAction plan = adapter.getAction(template, getNode());
+        SQLAction plan = adapter.getAction(template, node);
 
         MockOperationObserver observer = new MockOperationObserver();
-        Connection c = getConnection();
+        Connection c = dataSource.getConnection();
 
         try {
             plan.performAction(c, observer);
@@ -198,10 +231,10 @@ public class SQLTemplateActionTest exten
             c.close();
         }
 
-        List rows = observer.rowsForQuery(template);
+        List<DataRow> rows = observer.rowsForQuery(template);
         assertNotNull(rows);
         assertEquals(1, rows.size());
-        Map row = (Map) rows.get(0);
+        DataRow row = rows.get(0);
 
         assertNotNull(row.get("DOB"));
         // Sybase returns a Timestamp subclass... so can't test equality
@@ -213,16 +246,15 @@ public class SQLTemplateActionTest exten
                 + "VALUES (#bind($id), #bind($name), #bind($dob 'DATE'))";
         SQLTemplate template = new SQLTemplate(Object.class, templateString);
 
-        Map bindings = new HashMap();
+        Map<String, Object> bindings = new HashMap<String, Object>();
         bindings.put("id", new Long(1));
         bindings.put("name", "a1");
         bindings.put("dob", new Date(System.currentTimeMillis()));
         template.setParameters(bindings);
 
-        DbAdapter adapter = getAccessStackAdapter().getAdapter();
-        SQLAction action = adapter.getAction(template, getNode());
+        SQLAction action = adapter.getAction(template, node);
 
-        Connection c = getConnection();
+        Connection c = dataSource.getConnection();
         try {
             MockOperationObserver observer = new MockOperationObserver();
             action.performAction(c, observer);
@@ -236,30 +268,21 @@ public class SQLTemplateActionTest exten
             c.close();
         }
 
-        MockOperationObserver observer = new MockOperationObserver();
-        SelectQuery query = new SelectQuery(Artist.class);
-        getDomain().performQueries(Collections.singletonList(query), observer);
-
-        List data = observer.rowsForQuery(query);
-        assertEquals(1, data.size());
-        Map row = (Map) data.get(0);
-        assertEquals(bindings.get("id"), row.get("ARTIST_ID"));
-        assertEquals(bindings.get("name"), row.get("ARTIST_NAME"));
-        // to compare dates we need to create the binding correctly
-        // assertEquals(bindings.get("dob"), row.get("DATE_OF_BIRTH"));
+        assertEquals(1, tArtist.getRowCount());
+        assertEquals(1l, tArtist.getLong("ARTIST_ID"));
+        assertEquals("a1", tArtist.getString("ARTIST_NAME").trim());
     }
 
     public void testExecuteUpdateNoParameters() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+        createFourArtists();
 
         SQLTemplate template = new SQLTemplate(
                 Object.class,
                 "delete from ARTIST where ARTIST_NAME like 'a%'");
 
-        DbAdapter adapter = getAccessStackAdapter().getAdapter();
-        SQLAction action = adapter.getAction(template, getNode());
+        SQLAction action = adapter.getAction(template, node);
 
-        Connection c = getConnection();
+        Connection c = dataSource.getConnection();
         try {
             MockOperationObserver observer = new MockOperationObserver();
             action.performAction(c, observer);
@@ -267,7 +290,7 @@ public class SQLTemplateActionTest exten
             int[] batches = observer.countsForQuery(template);
             assertNotNull(batches);
             assertEquals(1, batches.length);
-            assertEquals(DataContextCase.artistCount, batches[0]);
+            assertEquals(4, batches[0]);
         }
         finally {
             c.close();
@@ -279,12 +302,12 @@ public class SQLTemplateActionTest exten
                 + "VALUES (#bind($id), #bind($name), #bind($dob 'DATE'))";
         SQLTemplate template = new SQLTemplate(Object.class, templateString);
 
-        Map bindings1 = new HashMap();
+        Map<String, Object> bindings1 = new HashMap<String, Object>();
         bindings1.put("id", new Long(1));
         bindings1.put("name", "a1");
         bindings1.put("dob", new Date(System.currentTimeMillis()));
 
-        Map bindings2 = new HashMap();
+        Map<String, Object> bindings2 = new HashMap<String, Object>();
         bindings2.put("id", new Long(33));
         bindings2.put("name", "a$$$$$");
         bindings2.put("dob", new Date(System.currentTimeMillis()));
@@ -292,15 +315,14 @@ public class SQLTemplateActionTest exten
                 bindings1, bindings2
         });
 
-        DbAdapter adapter = getAccessStackAdapter().getAdapter();
-        SQLAction genericAction = adapter.getAction(template, getNode());
+        SQLAction genericAction = adapter.getAction(template, node);
         assertTrue(genericAction instanceof SQLTemplateAction);
         SQLTemplateAction action = (SQLTemplateAction) genericAction;
 
-        assertSame(getAccessStackAdapter().getAdapter(), action.getAdapter());
+        assertSame(adapter, action.getAdapter());
         assertSame(template, action.getQuery());
 
-        Connection c = getConnection();
+        Connection c = dataSource.getConnection();
         try {
             MockOperationObserver observer = new MockOperationObserver();
             action.performAction(c, observer);
@@ -318,17 +340,17 @@ public class SQLTemplateActionTest exten
         MockOperationObserver observer = new MockOperationObserver();
         SelectQuery query = new SelectQuery(Artist.class);
         query.addOrdering("db:ARTIST_ID", SortOrder.ASCENDING);
-        getDomain().performQueries(Collections.singletonList(query), observer);
+        node.performQueries(Collections.singletonList((Query) query), observer);
 
-        List data = observer.rowsForQuery(query);
+        List<DataRow> data = observer.rowsForQuery(query);
         assertEquals(2, data.size());
-        Map row1 = (Map) data.get(0);
+        DataRow row1 = data.get(0);
         assertEquals(bindings1.get("id"), row1.get("ARTIST_ID"));
         assertEquals(bindings1.get("name"), row1.get("ARTIST_NAME"));
         // to compare dates we need to create the binding correctly
         // assertEquals(bindings1.get("dob"), row.get("DATE_OF_BIRTH"));
 
-        Map row2 = (Map) data.get(1);
+        DataRow row2 = data.get(1);
         assertEquals(bindings2.get("id"), row2.get("ARTIST_ID"));
         assertEquals(bindings2.get("name"), row2.get("ARTIST_NAME"));
         // to compare dates we need to create the binding correctly
@@ -337,26 +359,10 @@ public class SQLTemplateActionTest exten
 
     public void testExtractTemplateString() throws Exception {
         SQLTemplate template = new SQLTemplate(Artist.class, "A\nBC");
-        SQLTemplateAction action = new SQLTemplateAction(
-                template,
-                getAccessStackAdapter().getAdapter(),
-                getDomain().getEntityResolver());
+        SQLTemplateAction action = new SQLTemplateAction(template, adapter, objectContext
+                .getEntityResolver());
 
         assertEquals("A BC", action.extractTemplateString());
     }
 
-    private void setDate(java.util.Date date, int artistId) {
-        String templateString = "UPDATE ARTIST SET DATE_OF_BIRTH #bindEqual($date 'DATE') "
-                + "WHERE ARTIST_ID = #bind($id)";
-        SQLTemplate template = new SQLTemplate(Object.class, templateString);
-
-        Map map = new HashMap();
-        map.put("date", date);
-        map.put("id", new Integer(artistId));
-
-        template.setParameters(map);
-        getNode().performQueries(
-                Collections.singleton((Query) template),
-                new QueryResult());
-    }
 }



Mime
View raw message