You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2011/04/22 22:12:24 UTC

svn commit: r1096016 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test: java/org/apache/cayenne/access/ resources/dml/

Author: aadamchik
Date: Fri Apr 22 20:12:24 2011
New Revision: 1096016

URL: http://svn.apache.org/viewvc?rev=1096016&view=rev
Log:
CAY-1560

patches by Dzmitry Kazimirchyk:
DataContextPaginatedQueryTest.patch

Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextPaginatedQueryTest.xml
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextExtrasTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextExtrasTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextExtrasTest.java?rev=1096016&r1=1096015&r2=1096016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextExtrasTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextExtrasTest.java Fri Apr 22 20:12:24 2011
@@ -59,8 +59,9 @@ public class DataContextExtrasTest exten
 
     @Override
     protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("ARTIST");
+        dbHelper.deleteAll("PAINTING_INFO");
         dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST");
 
         tArtist = new TableHelper(dbHelper, "ARTIST");
         tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java?rev=1096016&r1=1096015&r2=1096016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java Fri Apr 22 20:12:24 2011
@@ -37,8 +37,6 @@ import org.apache.cayenne.testdo.testmap
 import org.apache.cayenne.testdo.testmap.Gallery;
 import org.apache.cayenne.unit.CayenneCase;
 
-/**
- */
 public class DataContextFlattenedAttributesTest extends CayenneCase {
 
     final int artistCount = 4;
@@ -132,9 +130,10 @@ public class DataContextFlattenedAttribu
             assertEquals("CompoundPainting.getPaintingTitle(): "
                     + painting.getPaintingTitle(), "painting" + id, painting
                     .getPaintingTitle());
-            if (painting.getToPaintingInfo()==null){
+            if (painting.getToPaintingInfo() == null) {
                 assertNull(painting.getTextReview());
-            }else{
+            }
+            else {
                 assertEquals("CompoundPainting.getTextReview(): "
                         + painting.getTextReview(), "painting review" + id, painting
                         .getTextReview());
@@ -155,7 +154,8 @@ public class DataContextFlattenedAttribu
         }
     }
 
-    // TODO: andrus 1/5/2007 -  CAY-952: SelectQuery uses INNER JOIN for flattened attributes, while
+    // TODO: andrus 1/5/2007 - CAY-952: SelectQuery uses INNER JOIN for flattened
+    // attributes, while
     // EJBQLQuery does an OUTER JOIN... which seems like a better idea...
     // 14/01/2010 now it uses LEFT JOIN
     public void testSelectCompound2() throws Exception {
@@ -172,7 +172,7 @@ public class DataContextFlattenedAttribu
         for (Iterator<?> i = objects.iterator(); i.hasNext();) {
             CompoundPainting painting = (CompoundPainting) i.next();
             assertEquals(PersistenceState.COMMITTED, painting.getPersistenceState());
-            
+
             assertEquals(
                     "CompoundPainting.getArtistName(): " + painting.getArtistName(),
                     "artist2",
@@ -185,22 +185,19 @@ public class DataContextFlattenedAttribu
     }
 
     /**
-     * Emulates the situation when flattened attribute has unusual(long) name,
-     *  that puts this attribute property to the top of PersistentDescriptor.declaredProperties map,
-     *  {@link PersistentDescriptor}[105]
-     *  
-     *  That forced an error during the building of the SelectQuery statement, CAY-1484
-     *  
+     * Emulates the situation when flattened attribute has unusual(long) name, that puts
+     * this attribute property to the top of PersistentDescriptor.declaredProperties map,
+     * {@link PersistentDescriptor}[105] That forced an error during the building of the
+     * SelectQuery statement, CAY-1484
      */
     public void testSelectCompoundLongNames() throws Exception {
         populateTables();
         SelectQuery query = new SelectQuery(CompoundPaintingLongNames.class);
-         // the error was thrown on query execution
+        // the error was thrown on query execution
         List<?> objects = context.performQuery(query);
         assertNotNull(objects);
     }
 
-    
     public void testSelectEJQBQL() throws Exception {
         populateTables();
         EJBQLQuery query = new EJBQLQuery(
@@ -217,88 +214,87 @@ public class DataContextFlattenedAttribu
             assertEquals(PersistenceState.COMMITTED, painting.getPersistenceState());
         }
     }
-    
+
     public void testSelectEJQBQLCollectionTheta() throws Exception {
         populateTables();
-        EJBQLQuery query = new EJBQLQuery("SELECT DISTINCT a FROM CompoundPainting cp, Artist a "
-                + "WHERE a.artistName=cp.artistName ORDER BY a.artistName");
-               
+        EJBQLQuery query = new EJBQLQuery(
+                "SELECT DISTINCT a FROM CompoundPainting cp, Artist a "
+                        + "WHERE a.artistName=cp.artistName ORDER BY a.artistName");
+
         List<?> objects = context.performQuery(query);
 
         assertNotNull(objects);
         assertEquals(4, objects.size());
         Iterator<?> i = objects.iterator();
-        int index=1;
+        int index = 1;
         while (i.hasNext()) {
             Artist artist = (Artist) i.next();
             assertEquals("artist" + index, artist.getArtistName());
             index++;
         }
     }
-    
+
     public void testSelectEJQBQLLike() throws Exception {
         populateTables();
         EJBQLQuery query = new EJBQLQuery(
-                "SELECT a FROM CompoundPainting a WHERE a.artistName LIKE 'artist%' " +
-                "ORDER BY a.paintingTitle");
-               
+                "SELECT a FROM CompoundPainting a WHERE a.artistName LIKE 'artist%' "
+                        + "ORDER BY a.paintingTitle");
+
         List<?> objects = context.performQuery(query);
 
         assertNotNull(objects);
         assertEquals(8, objects.size());
         Iterator<?> i = objects.iterator();
-        int index=1;
+        int index = 1;
         while (i.hasNext()) {
             CompoundPainting painting = (CompoundPainting) i.next();
             assertEquals("painting" + index, painting.getPaintingTitle());
             index++;
         }
     }
-    
+
     public void testSelectEJQBQLBetween() throws Exception {
         populateTables();
-        EJBQLQuery query = new EJBQLQuery(
-                "SELECT a FROM CompoundPainting a " +
-                "WHERE a.artistName BETWEEN 'artist1' AND 'artist4' " +
-                "ORDER BY a.paintingTitle");
-               
+        EJBQLQuery query = new EJBQLQuery("SELECT a FROM CompoundPainting a "
+                + "WHERE a.artistName BETWEEN 'artist1' AND 'artist4' "
+                + "ORDER BY a.paintingTitle");
+
         List<?> objects = context.performQuery(query);
 
         assertNotNull(objects);
         assertEquals(8, objects.size());
         Iterator<?> i = objects.iterator();
-        int index=1;
+        int index = 1;
         while (i.hasNext()) {
             CompoundPainting painting = (CompoundPainting) i.next();
             assertEquals("painting" + index, painting.getPaintingTitle());
             index++;
         }
     }
-    
+
     public void testSelectEJQBQLSubquery() throws Exception {
         populateTables();
         EJBQLQuery query = new EJBQLQuery(
-                "SELECT g FROM Gallery g WHERE " +
-                "(SELECT COUNT(cp) FROM CompoundPainting cp WHERE g.galleryName=cp.galleryName) = 4");
-                
+                "SELECT g FROM Gallery g WHERE "
+                        + "(SELECT COUNT(cp) FROM CompoundPainting cp WHERE g.galleryName=cp.galleryName) = 4");
+
         List<?> objects = context.performQuery(query);
 
         assertNotNull(objects);
         assertEquals(1, objects.size());
         Gallery gallery = (Gallery) objects.get(0);
         assertEquals("gallery2", gallery.getGalleryName());
-        
+
     }
-    
+
     public void testSelectEJQBQLHaving() throws Exception {
         populateTables();
         EJBQLQuery query = new EJBQLQuery(
-                "SELECT cp.galleryName, COUNT(a) from  Artist a, CompoundPainting cp "+
-                "WHERE cp.artistName = a.artistName "+
-                "GROUP BY cp.galleryName " +
-                "HAVING cp.galleryName LIKE 'gallery1'");
-                
-               
+                "SELECT cp.galleryName, COUNT(a) from  Artist a, CompoundPainting cp "
+                        + "WHERE cp.artistName = a.artistName "
+                        + "GROUP BY cp.galleryName "
+                        + "HAVING cp.galleryName LIKE 'gallery1'");
+
         List<Object[]> objects = context.performQuery(query);
 
         assertNotNull(objects);
@@ -307,7 +303,7 @@ public class DataContextFlattenedAttribu
         assertEquals("gallery1", galleryItem[0]);
         assertEquals(3L, galleryItem[1]);
     }
-    
+
     public void testInsert() {
         CompoundPainting o1 = context.newObject(CompoundPainting.class);
         o1.setArtistName("A1");
@@ -318,18 +314,15 @@ public class DataContextFlattenedAttribu
 
         context.commitChanges();
 
-        Number artistCount = (Number) Cayenne.objectForQuery(
-                context,
-                new EJBQLQuery("select count(a) from Artist a"));
+        Number artistCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery(
+                "select count(a) from Artist a"));
         assertEquals(1, artistCount.intValue());
-        Number paintingCount = (Number) Cayenne.objectForQuery(
-                context,
-                new EJBQLQuery("select count(a) from Painting a"));
+        Number paintingCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery(
+                "select count(a) from Painting a"));
         assertEquals(1, paintingCount.intValue());
 
-        Number galleryCount = (Number) Cayenne.objectForQuery(
-                context,
-                new EJBQLQuery("select count(a) from Gallery a"));
+        Number galleryCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery(
+                "select count(a) from Gallery a"));
         assertEquals(1, galleryCount.intValue());
     }
 
@@ -352,18 +345,15 @@ public class DataContextFlattenedAttribu
         context.deleteObject(o1);
         context.commitChanges();
 
-        Number artistCount = (Number) Cayenne.objectForQuery(
-                context,
-                new EJBQLQuery("select count(a) from Artist a"));
+        Number artistCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery(
+                "select count(a) from Artist a"));
         assertEquals(1, artistCount.intValue());
-        Number paintingCount = (Number) Cayenne.objectForQuery(
-                context,
-                new EJBQLQuery("select count(a) from Painting a"));
+        Number paintingCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery(
+                "select count(a) from Painting a"));
         assertEquals(0, paintingCount.intValue());
 
-        Number galleryCount = (Number) Cayenne.objectForQuery(
-                context,
-                new EJBQLQuery("select count(a) from Gallery a"));
+        Number galleryCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery(
+                "select count(a) from Gallery a"));
         assertEquals(0, galleryCount.intValue());
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java?rev=1096016&r1=1096015&r2=1096016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java Fri Apr 22 20:12:24 2011
@@ -20,19 +20,55 @@ package org.apache.cayenne.access;
 
 import java.util.List;
 
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.QueryCacheStrategy;
 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;
 
-public class DataContextPaginatedQueryTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextPaginatedQueryTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    protected TableHelper tArtist;
+
+    @Override
+    public 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");
+    }
+
+    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, "artist6");
+        tArtist.insert(33007, "artist7");
+        tArtist.insert(33008, "artist8");
+        tArtist.insert(33009, "artist9");
+        tArtist.insert(33010, "artist10");
+    }
 
     public void testLocalCache() throws Exception {
-        deleteTestData();
-        createTestData("testLocalCache");
 
-        DataContext context = createDataContext();
+        createArtistsDataSet();
 
         SelectQuery query = new SelectQuery(Artist.class);
         query.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
@@ -45,12 +81,12 @@ public class DataContextPaginatedQueryTe
         List<?> results2 = context.performQuery(query);
         assertNotNull(results2);
         assertSame(results1, results2);
-        
+
         results1.get(1);
         List<?> results3 = context.performQuery(query);
         assertNotNull(results3);
         assertSame(results1, results3);
-        
+
         results1.get(7);
         List<?> results4 = context.performQuery(query);
         assertNotNull(results4);