db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1337000 - in /db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque: generated/peer/SelectFunctionTest.java util/SummaryHelperTest.java
Date Fri, 11 May 2012 01:51:26 GMT
Author: tfischer
Date: Fri May 11 01:51:25 2012
New Revision: 1337000

URL: http://svn.apache.org/viewvc?rev=1337000&view=rev
Log:
TORQUE-177: Tests for function re-works

Added:
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectFunctionTest.java
Modified:
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/util/SummaryHelperTest.java

Added: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectFunctionTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectFunctionTest.java?rev=1337000&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectFunctionTest.java
(added)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectFunctionTest.java
Fri May 11 01:51:25 2012
@@ -0,0 +1,197 @@
+package org.apache.torque.generated.peer;
+
+/*
+ * 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.
+ */
+
+import org.apache.torque.BaseDatabaseTestCase;
+import org.apache.torque.criteria.Criteria;
+import org.apache.torque.om.mapper.IntegerMapper;
+import org.apache.torque.test.Summarize1;
+import org.apache.torque.test.Summarize1Peer;
+import org.apache.torque.util.BasePeer;
+import org.apache.torque.util.functions.Avg;
+import org.apache.torque.util.functions.Count;
+import org.apache.torque.util.functions.Max;
+import org.apache.torque.util.functions.Min;
+import org.apache.torque.util.functions.Sum;
+
+/**
+ * Tests selects using functions.
+ *
+ * @version $Id: $
+ */
+public class SelectFunctionTest extends BaseDatabaseTestCase
+{
+    private static final int[] INT_VALUES  = {
+        1, 1, 1, 5
+    };
+
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+
+        // Clean up any previous failures
+        Summarize1Peer.doDelete(new Criteria());
+
+        // Create some test data
+        for (int i = 0; i < INT_VALUES.length; i++)
+        {
+            Summarize1 rec = new Summarize1();
+            rec.setInt1(INT_VALUES[i] );
+            rec.save();
+        }
+    }
+
+
+    /**
+     * Tests a select using the Avg function.
+     *
+     * @throws Exception if the test fails
+     */
+    public void testSelectAvg() throws Exception
+    {
+        Criteria criteria = new Criteria().addSelectColumn(
+                new Avg(Summarize1Peer.INT_1));
+        Integer avg = BasePeer.doSelectSingleRecord(
+                criteria,
+                new IntegerMapper(),
+                Summarize1Peer.getTableMap());
+
+        assertEquals(new Integer(2), avg);
+    }
+
+    /**
+     * Tests a select using the Avg function with distinct.
+     *
+     * @throws Exception if the test fails
+     */
+    public void testSelectAvgDistinct() throws Exception
+    {
+        Criteria criteria = new Criteria().addSelectColumn(
+                new Avg(Summarize1Peer.INT_1, true));
+        Integer avg = BasePeer.doSelectSingleRecord(
+                criteria,
+                new IntegerMapper(),
+                Summarize1Peer.getTableMap());
+
+        assertEquals(new Integer(3), avg);
+    }
+
+    /**
+     * Tests a select using the count function.
+     *
+     * @throws Exception if the test fails
+     */
+    public void testSelectCount() throws Exception
+    {
+        Criteria criteria = new Criteria().addSelectColumn(new Count("*"));
+        Integer count = BasePeer.doSelectSingleRecord(
+                criteria,
+                new IntegerMapper(),
+                Summarize1Peer.getTableMap());
+
+        assertEquals(new Integer(4), count);
+    }
+
+    /**
+     * Tests a select using the count function with distinct.
+     *
+     * @throws Exception if the test fails
+     */
+    public void testSelectCountDistinct() throws Exception
+    {
+        Criteria criteria = new Criteria().addSelectColumn(
+                new Count(Summarize1Peer.INT_1, true));
+        Integer count = BasePeer.doSelectSingleRecord(
+                criteria,
+                new IntegerMapper(),
+                Summarize1Peer.getTableMap());
+
+        assertEquals(new Integer(2), count);
+    }
+
+    /**
+     * Tests a select using the min function.
+     *
+     * @throws Exception if the test fails
+     */
+    public void testSelectMin() throws Exception
+    {
+        Criteria criteria = new Criteria().addSelectColumn(
+                new Min(Summarize1Peer.INT_1));
+        Integer min = BasePeer.doSelectSingleRecord(
+                criteria,
+                new IntegerMapper(),
+                Summarize1Peer.getTableMap());
+
+        assertEquals(new Integer(1), min);
+    }
+    /**
+
+     * Tests a select using the max function.
+     *
+     * @throws Exception if the test fails
+     */
+    public void testSelectMax() throws Exception
+    {
+        Criteria criteria = new Criteria().addSelectColumn(
+                new Max(Summarize1Peer.INT_1));
+        Integer max = BasePeer.doSelectSingleRecord(
+                criteria,
+                new IntegerMapper(),
+                Summarize1Peer.getTableMap());
+
+        assertEquals(new Integer(5), max);
+    }
+
+   /**
+    * Tests a select using the sum function.
+    *
+    * @throws Exception if the test fails
+    */
+   public void testSelectSum() throws Exception
+   {
+       Criteria criteria = new Criteria().addSelectColumn(
+               new Sum(Summarize1Peer.INT_1));
+       Integer sum = BasePeer.doSelectSingleRecord(
+               criteria,
+               new IntegerMapper(),
+               Summarize1Peer.getTableMap());
+
+       assertEquals(new Integer(8), sum);
+   }
+
+   /**
+    * Tests a select using the sum function with distinct.
+    *
+    * @throws Exception if the test fails
+    */
+   public void testSelectSumDistinct() throws Exception
+   {
+       Criteria criteria = new Criteria().addSelectColumn(
+               new Sum(Summarize1Peer.INT_1, true));
+       Integer sum = BasePeer.doSelectSingleRecord(
+               criteria,
+               new IntegerMapper(),
+               Summarize1Peer.getTableMap());
+
+       assertEquals(new Integer(6), sum);
+   }
+}

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/util/SummaryHelperTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/util/SummaryHelperTest.java?rev=1337000&r1=1336999&r2=1337000&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/util/SummaryHelperTest.java
(original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/util/SummaryHelperTest.java
Fri May 11 01:51:25 2012
@@ -30,7 +30,11 @@ import org.apache.torque.criteria.Criter
 import org.apache.torque.criteria.SqlEnum;
 import org.apache.torque.test.Summarize1;
 import org.apache.torque.test.Summarize1Peer;
-import org.apache.torque.util.functions.FunctionFactory;
+import org.apache.torque.util.functions.Avg;
+import org.apache.torque.util.functions.Count;
+import org.apache.torque.util.functions.Max;
+import org.apache.torque.util.functions.Min;
+import org.apache.torque.util.functions.Sum;
 
 /**
  * Test code for SummaryHelper.
@@ -52,18 +56,13 @@ public class SummaryHelperTest extends B
         "A2","B2","C2","D2"
     };
 
-    private Criteria criteria;
-
+    @Override
     public void setUp() throws Exception
     {
         super.setUp();
 
         // Clean up any previous failures
-
-        criteria = new Criteria();
-        criteria.add( Summarize1Peer.ID, -99, SqlEnum.GREATER_THAN);
-        Summarize1Peer.doDelete(criteria);
-        criteria = null;
+        Summarize1Peer.doDelete(new Criteria());
 
         // Create some test data
         for (int i = 0; i < TEST_GROUPBY1.length; i++)
@@ -80,6 +79,7 @@ public class SummaryHelperTest extends B
         }
     }
 
+    @Override
     public void tearDown() throws Exception
     {
         // Delete the test data
@@ -109,40 +109,31 @@ public class SummaryHelperTest extends B
         summary.addGroupBy ( Summarize1Peer.GROUP_BY1 );
         returnTypes.add(String.class);
 
-        summary.addAggregate("COUNT_RECS",
-                                FunctionFactory.count(Summarize1Peer.ID));
+        summary.addAggregate("COUNT_RECS", new Count(Summarize1Peer.ID));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("AVG_INT1",
-                                FunctionFactory.avg(Summarize1Peer.INT_1));
+        summary.addAggregate("AVG_INT1", new Avg(Summarize1Peer.INT_1));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("MIN_INT1",
-                                FunctionFactory.min(Summarize1Peer.INT_1));
+        summary.addAggregate("MIN_INT1", new Min(Summarize1Peer.INT_1));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("MAX_INT1",
-                                FunctionFactory.max(Summarize1Peer.INT_1));
+        summary.addAggregate("MAX_INT1", new Max(Summarize1Peer.INT_1));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("SUM_INT1",
-                                FunctionFactory.sum(Summarize1Peer.INT_1));
+        summary.addAggregate("SUM_INT1", new Sum(Summarize1Peer.INT_1));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("AVG_FLOAT1",
-                                FunctionFactory.avg(Summarize1Peer.FLOAT1));
+        summary.addAggregate("AVG_FLOAT1", new Avg(Summarize1Peer.FLOAT1));
         returnTypes.add(Float.class);
 
-        summary.addAggregate("MIN_FLOAT1",
-                                FunctionFactory.min(Summarize1Peer.FLOAT1));
+        summary.addAggregate("MIN_FLOAT1", new Min(Summarize1Peer.FLOAT1));
         returnTypes.add(Float.class);
 
-        summary.addAggregate("MAX_FLOAT1",
-                                FunctionFactory.max(Summarize1Peer.FLOAT1));
+        summary.addAggregate("MAX_FLOAT1", new Max(Summarize1Peer.FLOAT1));
         returnTypes.add(Float.class);
 
-        summary.addAggregate("SUM_FLOAT1",
-                                FunctionFactory.sum(Summarize1Peer.FLOAT1));
+        summary.addAggregate("SUM_FLOAT1", new Sum(Summarize1Peer.FLOAT1));
         returnTypes.add(Float.class);
 
         List<ListOrderedMapCI> results = summary.summarize(c, returnTypes);
@@ -197,40 +188,31 @@ public class SummaryHelperTest extends B
         summary.setExcludeExprColumns(true);
         List<Class<?>> returnTypes = new ArrayList<Class<?>>();
 
-        summary.addAggregate("COUNT_RECS",
-                                FunctionFactory.count(Summarize1Peer.ID));
+        summary.addAggregate("COUNT_RECS", new Count(Summarize1Peer.ID));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("AVG_INT1",
-                                FunctionFactory.avg(Summarize1Peer.INT_1));
+        summary.addAggregate("AVG_INT1", new Avg(Summarize1Peer.INT_1));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("MIN_INT1",
-                                FunctionFactory.min(Summarize1Peer.INT_1));
+        summary.addAggregate("MIN_INT1", new Min(Summarize1Peer.INT_1));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("MAX_INT1",
-                                FunctionFactory.max(Summarize1Peer.INT_1));
+        summary.addAggregate("MAX_INT1", new Max(Summarize1Peer.INT_1));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("SUM_INT1",
-                                FunctionFactory.sum(Summarize1Peer.INT_1));
+        summary.addAggregate("SUM_INT1", new Sum(Summarize1Peer.INT_1));
         returnTypes.add(Integer.class);
 
-        summary.addAggregate("AVG_FLOAT1",
-                FunctionFactory.avg(Summarize1Peer.FLOAT1));
+        summary.addAggregate("AVG_FLOAT1", new Avg(Summarize1Peer.FLOAT1));
         returnTypes.add(Float.class);
 
-        summary.addAggregate("MIN_FLOAT1",
-                FunctionFactory.min(Summarize1Peer.FLOAT1));
+        summary.addAggregate("MIN_FLOAT1", new Min(Summarize1Peer.FLOAT1));
         returnTypes.add(Float.class);
 
-        summary.addAggregate("MAX_FLOAT1",
-                FunctionFactory.max(Summarize1Peer.FLOAT1));
+        summary.addAggregate("MAX_FLOAT1", new Max(Summarize1Peer.FLOAT1));
         returnTypes.add(Float.class);
 
-        summary.addAggregate("SUM_FLOAT1",
-                FunctionFactory.sum(Summarize1Peer.FLOAT1));
+        summary.addAggregate("SUM_FLOAT1", new Sum(Summarize1Peer.FLOAT1));
         returnTypes.add(Float.class);
 
         List<ListOrderedMapCI> results = summary.summarize(c, returnTypes);



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message