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 2010/06/20 11:27:38 UTC

svn commit: r956338 [3/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...

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ParsedExpQualifierCompatTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ParsedExpQualifierCompatTest.java?rev=956338&r1=956337&r2=956338&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ParsedExpQualifierCompatTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ParsedExpQualifierCompatTest.java Sun Jun 20 09:27:37 2010
@@ -1,4 +1,3 @@
-
 /*****************************************************************
  *   Licensed to the Apache Software Foundation (ASF) under one
  *  or more contributor license agreements.  See the NOTICE file
@@ -24,32 +23,64 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.access.DataContextCase;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ParsedExpQualifierCompatTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
 
-/**
- */
-public class ParsedExpQualifierCompatTest extends CayenneCase {
+    @Inject
+    protected DBHelper dbHelper;
 
-    protected DataContext context;
+    protected TableHelper tArtist;
+    protected TableHelper tPainting;
 
     @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        deleteTestData();
-        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
-        context = createDataContext();
+    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 createTwentyFiveArtists() throws Exception {
+        for (int i = 1; i <= 25; i++) {
+            tArtist.insert(i, "artist" + i);
+        }
     }
 
-    private List execute(Class root, Expression qualifier) {
+    protected void createTwentyFiveArtistsAndPaintings() throws Exception {
+        createTwentyFiveArtists();
+        for (int i = 1; i <= 25; i++) {
+            tPainting.insert(i, "p_artist" + i, i, i * 1000);
+        }
+    }
+
+    private <T> List<T> execute(Class<T> root, Expression qualifier) {
         return execute(root, qualifier, null);
     }
 
-    private List execute(Class root, Expression qualifier, String prefecth) {
+    private <T> List<T> execute(Class<T> root, Expression qualifier, String prefecth) {
         SelectQuery query = new SelectQuery(root, qualifier);
         if (prefecth != null) {
             query.addPrefetch(prefecth);
@@ -59,19 +90,22 @@ public class ParsedExpQualifierCompatTes
 
     public void testOr() throws Exception {
 
-        Expression parsed =
-            Expression.fromString("artistName='artist1' or artistName='artist3'");
+        createTwentyFiveArtists();
+
+        Expression parsed = Expression
+                .fromString("artistName='artist1' or artistName='artist3'");
         assertEquals(2, execute(Artist.class, parsed).size());
 
-        parsed =
-            Expression.fromString(
-                "artistName='artist1' or artistName='artist3' or artistName='artist5'");
+        parsed = Expression
+                .fromString("artistName='artist1' or artistName='artist3' or artistName='artist5'");
         assertEquals(3, execute(Artist.class, parsed).size());
     }
 
     public void testAnd() throws Exception {
-        Expression parsed =
-            Expression.fromString("artistName='artist1' and artistName='artist1'");
+        createTwentyFiveArtists();
+
+        Expression parsed = Expression
+                .fromString("artistName='artist1' and artistName='artist1'");
         assertEquals(1, execute(Artist.class, parsed).size());
 
         parsed = Expression.fromString("artistName='artist1' and artistName='artist3'");
@@ -80,19 +114,19 @@ public class ParsedExpQualifierCompatTes
 
     public void testNot() throws Exception {
 
+        createTwentyFiveArtists();
+
         Expression parsed1 = Expression.fromString("not artistName='artist3'");
-        assertEquals(
-            DataContextCase.artistCount - 1,
-            execute(Artist.class, parsed1).size());
+        assertEquals(25 - 1, execute(Artist.class, parsed1).size());
 
         Expression parsed2 = Expression.fromString("not artistName='artist3'");
-        assertEquals(
-            DataContextCase.artistCount - 1,
-            execute(Artist.class, parsed2).size());
+        assertEquals(25 - 1, execute(Artist.class, parsed2).size());
     }
 
     public void testEqual() throws Exception {
 
+        createTwentyFiveArtists();
+
         Expression parsed1 = Expression.fromString("artistName='artist3'");
         assertEquals(1, execute(Artist.class, parsed1).size());
 
@@ -105,103 +139,96 @@ public class ParsedExpQualifierCompatTes
 
     public void testNotEqual() throws Exception {
 
+        createTwentyFiveArtists();
+
         Expression parsed1 = Expression.fromString("artistName!='artist3'");
-        assertEquals(
-            DataContextCase.artistCount - 1,
-            execute(Artist.class, parsed1).size());
+        assertEquals(25 - 1, execute(Artist.class, parsed1).size());
 
         Expression parsed2 = Expression.fromString("artistName<>'artist3'");
-        assertEquals(
-            DataContextCase.artistCount - 1,
-            execute(Artist.class, parsed2).size());
+        assertEquals(25 - 1, execute(Artist.class, parsed2).size());
     }
 
     public void testLessThan() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testPaintings", null);
+        createTwentyFiveArtistsAndPaintings();
         Expression parsed1 = Expression.fromString("estimatedPrice < 2000.0");
         assertEquals(1, execute(Painting.class, parsed1).size());
     }
 
     public void testLessThanEqualTo() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testPaintings", null);
+        createTwentyFiveArtistsAndPaintings();
         Expression parsed1 = Expression.fromString("estimatedPrice <= 2000.0");
         assertEquals(2, execute(Painting.class, parsed1).size());
     }
 
     public void testGreaterThan() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testPaintings", null);
+        createTwentyFiveArtistsAndPaintings();
         Expression parsed1 = Expression.fromString("estimatedPrice > 2000");
-        assertEquals(
-            DataContextCase.artistCount - 2,
-            execute(Painting.class, parsed1).size());
+        assertEquals(25 - 2, execute(Painting.class, parsed1).size());
     }
 
     public void testGreaterThanEqualTo() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testPaintings", null);
+        createTwentyFiveArtistsAndPaintings();
         Expression parsed1 = Expression.fromString("estimatedPrice >= 2000");
-        assertEquals(
-            DataContextCase.artistCount - 1,
-            execute(Painting.class, parsed1).size());
+        assertEquals(25 - 1, execute(Painting.class, parsed1).size());
     }
 
     public void testLike() throws Exception {
+        createTwentyFiveArtists();
         Expression parsed1 = Expression.fromString("artistName like 'artist%2'");
         assertEquals(3, execute(Artist.class, parsed1).size());
     }
 
     public void testLikeIgnoreCase() throws Exception {
-        Expression parsed1 =
-            Expression.fromString("artistName likeIgnoreCase 'artist%2'");
+        createTwentyFiveArtists();
+        Expression parsed1 = Expression
+                .fromString("artistName likeIgnoreCase 'artist%2'");
         assertEquals(3, execute(Artist.class, parsed1).size());
     }
 
     public void testNotLike() throws Exception {
+        createTwentyFiveArtists();
         Expression parsed1 = Expression.fromString("artistName not like 'artist%2'");
-        assertEquals(
-            DataContextCase.artistCount - 3,
-            execute(Artist.class, parsed1).size());
+        assertEquals(25 - 3, execute(Artist.class, parsed1).size());
     }
 
     public void testNotLikeIgnoreCase() throws Exception {
-        Expression parsed1 =
-            Expression.fromString("artistName not likeIgnoreCase 'artist%2'");
-        assertEquals(
-            DataContextCase.artistCount - 3,
-            execute(Artist.class, parsed1).size());
+        createTwentyFiveArtists();
+        Expression parsed1 = Expression
+                .fromString("artistName not likeIgnoreCase 'artist%2'");
+        assertEquals(25 - 3, execute(Artist.class, parsed1).size());
     }
 
     public void testIn() throws Exception {
-        Expression parsed1 =
-            Expression.fromString("artistName in ('artist1', 'artist3', 'artist19')");
+        createTwentyFiveArtists();
+        Expression parsed1 = Expression
+                .fromString("artistName in ('artist1', 'artist3', 'artist19')");
         assertEquals(3, execute(Artist.class, parsed1).size());
     }
 
     public void testNotIn() throws Exception {
-        Expression parsed1 =
-            Expression.fromString("artistName not in ('artist1', 'artist3', 'artist19')");
-        assertEquals(
-            DataContextCase.artistCount - 3,
-            execute(Artist.class, parsed1).size());
+        createTwentyFiveArtists();
+        Expression parsed1 = Expression
+                .fromString("artistName not in ('artist1', 'artist3', 'artist19')");
+        assertEquals(25 - 3, execute(Artist.class, parsed1).size());
     }
 
     public void testBetween() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testPaintings", null);
-        Expression parsed1 =
-            Expression.fromString("estimatedPrice between 2000.0 and 4000.0");
+        createTwentyFiveArtistsAndPaintings();
+        Expression parsed1 = Expression
+                .fromString("estimatedPrice between 2000.0 and 4000.0");
         assertEquals(3, execute(Painting.class, parsed1).size());
     }
 
     public void testNotBetween() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testPaintings", null);
-        Expression parsed1 =
-            Expression.fromString("estimatedPrice not between 2000.0 and 4000.0");
-        assertEquals(
-            DataContextCase.artistCount - 3,
-            execute(Painting.class, parsed1).size());
+        createTwentyFiveArtistsAndPaintings();
+        Expression parsed1 = Expression
+                .fromString("estimatedPrice not between 2000.0 and 4000.0");
+        assertEquals(25 - 3, execute(Painting.class, parsed1).size());
     }
 
     public void testParameter() throws Exception {
-        Map parameters = new HashMap();
+        createTwentyFiveArtists();
+        Map<String, Object> parameters = new HashMap<String, Object>();
         parameters.put("artistName", "artist5");
         Expression parsed1 = Expression.fromString("artistName=$artistName");
         parsed1 = parsed1.expWithParameters(parameters);
@@ -209,30 +236,31 @@ public class ParsedExpQualifierCompatTes
     }
 
     public void testDbExpression() throws Exception {
+        createTwentyFiveArtists();
         Expression parsed1 = Expression.fromString("db:ARTIST_NAME='artist3'");
         assertEquals(1, execute(Artist.class, parsed1).size());
     }
 
     public void testFloatExpression() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testPaintings", null);
+        createTwentyFiveArtistsAndPaintings();
         Expression parsed1 = Expression.fromString("estimatedPrice < 2001.01");
         assertEquals(2, execute(Painting.class, parsed1).size());
     }
 
     public void testNullExpression() throws Exception {
+        createTwentyFiveArtists();
 
         Expression parsed1 = Expression.fromString("artistName!=null");
-        assertEquals(
-            DataContextCase.artistCount,
-            execute(Artist.class, parsed1).size());
+        assertEquals(25, execute(Artist.class, parsed1).size());
 
         Expression parsed2 = Expression.fromString("artistName = null");
         assertEquals(0, execute(Artist.class, parsed2).size());
     }
-    
+
     public void testTrueExpression() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testPaintings", null);
-        
+
+        createTwentyFiveArtistsAndPaintings();
+
         Expression parsed1 = Expression.fromString("true");
         assertEquals(25, execute(Painting.class, parsed1).size());
 
@@ -244,16 +272,17 @@ public class ParsedExpQualifierCompatTes
     }
 
     public void testFalseExpression() throws Exception {
-        getAccessStack().createTestData(DataContextCase.class, "testPaintings", null);
-        
+        createTwentyFiveArtistsAndPaintings();
+
         Expression parsed1 = Expression.fromString("false");
         assertEquals(0, execute(Painting.class, parsed1).size());
 
-        Expression parsed2 = Expression.fromString("(estimatedPrice < 2001.01) and false");
+        Expression parsed2 = Expression
+                .fromString("(estimatedPrice < 2001.01) and false");
         assertEquals(0, execute(Painting.class, parsed2).size());
 
         Expression parsed3 = Expression.fromString("(estimatedPrice < 2001.01) or false");
-        
+
         assertEquals(2, execute(Painting.class, parsed3).size());
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesSQLTemplateCustomizerProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesSQLTemplateCustomizerProvider.java?rev=956338&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesSQLTemplateCustomizerProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesSQLTemplateCustomizerProvider.java Sun Jun 20 09:27:37 2010
@@ -0,0 +1,45 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.unit.di.server;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
+
+public class CayenneResourcesSQLTemplateCustomizerProvider implements
+        Provider<SQLTemplateCustomizer> {
+
+    protected CayenneResources resources;
+
+    @Inject
+    protected DbAdapter dbAdapter;
+
+    public CayenneResourcesSQLTemplateCustomizerProvider(CayenneResources resources) {
+        this.resources = resources;
+    }
+
+    public SQLTemplateCustomizer get() throws ConfigurationException {
+        SQLTemplateCustomizer customizer = resources.getSQLTemplateCustomizer();
+        customizer.setAdapter(dbAdapter);
+        return customizer;
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java?rev=956338&r1=956337&r2=956338&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java Sun Jun 20 09:27:37 2010
@@ -35,6 +35,7 @@ import org.apache.cayenne.unit.AccessSta
 import org.apache.cayenne.unit.CayenneResources;
 import org.apache.cayenne.unit.di.DICase;
 import org.apache.cayenne.unit.di.UnitTestLifecycleManager;
+import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
 
 public class ServerCase extends DICase {
 
@@ -77,6 +78,8 @@ public class ServerCase extends DICase {
                 binder.bind(DataNode.class).toProvider(ServerCaseDataNodeProvider.class);
                 binder.bind(DataChannelQueryInterceptor.class).to(
                         ServerCaseDataChannelQueryInterceptor.class);
+                binder.bind(SQLTemplateCustomizer.class).toProviderInstance(
+                        new CayenneResourcesSQLTemplateCustomizerProvider(resources));
 
                 // test-scoped objects
                 binder
@@ -93,6 +96,7 @@ public class ServerCase extends DICase {
                         .bind(DBHelper.class)
                         .toProvider(FlavoredDBHelperProvider.class)
                         .in(testScope);
+
             }
         };
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/util/SQLTemplateCustomizer.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/util/SQLTemplateCustomizer.java?rev=956338&r1=956337&r2=956338&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/util/SQLTemplateCustomizer.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/util/SQLTemplateCustomizer.java Sun Jun 20 09:27:37 2010
@@ -26,14 +26,13 @@ import org.apache.cayenne.query.SQLTempl
 
 /**
  * Helper class to customize SQLTemplate queries used in test cases per adapter.
- * 
  */
 public class SQLTemplateCustomizer {
 
     protected DbAdapter adapter;
-    protected Map sqlMap;
+    protected Map<String, Map<String, String>> sqlMap;
 
-    public SQLTemplateCustomizer(Map sqlMap) {
+    public SQLTemplateCustomizer(Map<String, Map<String, String>> sqlMap) {
         this.sqlMap = sqlMap;
     }
 
@@ -41,17 +40,17 @@ public class SQLTemplateCustomizer {
      * Customizes SQLTemplate, injecting the template for the current adapter.
      */
     public void updateSQLTemplate(SQLTemplate query) {
-        Map customSQL = (Map) sqlMap.get(query.getDefaultTemplate());
+        Map<String, String> customSQL = sqlMap.get(query.getDefaultTemplate());
         if (customSQL != null) {
             String key = adapter.getClass().getName();
-            String template = (String) customSQL.get(key);
+            String template = customSQL.get(key);
             if (template != null) {
                 query.setTemplate(key, template);
             }
         }
     }
 
-    public SQLTemplate createSQLTemplate(Class root, String defaultTemplate) {
+    public SQLTemplate createSQLTemplate(Class<?> root, String defaultTemplate) {
         SQLTemplate template = new SQLTemplate(root, defaultTemplate);
         updateSQLTemplate(template);
         return template;