db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1224858 - in /db/torque/torque4/trunk/torque-runtime/src: main/java/org/apache/torque/criteria/Criterion.java test/java/org/apache/torque/criteria/CriterionTest.java test/java/org/apache/torque/criteria/JoinTest.java
Date Tue, 27 Dec 2011 02:22:15 GMT
Author: tfischer
Date: Tue Dec 27 02:22:14 2011
New Revision: 1224858

URL: http://svn.apache.org/viewvc?rev=1224858&view=rev
Log:
fix Criterion.toString()
simple tests for Criterion and Join

Added:
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/JoinTest.java
Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriterionTest.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java?rev=1224858&r1=1224857&r2=1224858&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java
Tue Dec 27 02:22:14 2011
@@ -350,17 +350,17 @@ public class Criterion implements Serial
             {
                 if (!first)
                 {
-                    if (part.isComposite())
-                    {
-                        sb.append('(');
-                    }
                     sb.append(conjunction);
-                    if (part.isComposite())
-                    {
-                        sb.append(')');
-                    }
                 }
-                sb.append(part);
+                if (part.isComposite())
+                {
+                    sb.append('(');
+                }
+                part.appendTo(sb);
+                if (part.isComposite())
+                {
+                      sb.append(')');
+                }
                 first = false;
             }
         }

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriterionTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriterionTest.java?rev=1224858&r1=1224857&r2=1224858&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriterionTest.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriterionTest.java
Tue Dec 27 02:22:14 2011
@@ -43,4 +43,33 @@ public class CriterionTest extends BaseT
         assertEquals(criterion.hashCode(), compareToCriterion.hashCode());
         assertEquals(criterion, compareToCriterion);
     }
+
+    public void testToStringSingleCriterion()
+    {
+        Criterion criterion = new Criterion(
+                new ColumnImpl("myTable", "myColumn"),
+                "myValue");
+        assertEquals("myTable.myColumn=myValue",
+                criterion.toString());
+    }
+
+    public void testToStringCompositeCriterion()
+    {
+        Criterion criterion = new Criterion(
+                new ColumnImpl("myTable", "myColumn"),
+                "myValue");
+        Criterion innerCriterion = (new Criterion(
+                new ColumnImpl("myTable", "myColumn2"),
+                "myColumn2<abs(myValue2)",
+                SqlEnum.CUSTOM));
+        innerCriterion.and(new Criterion(
+                new ColumnImpl("myTable", "myColumn3"),
+                3,
+                SqlEnum.GREATER_EQUAL));
+        criterion.or(innerCriterion);
+        assertEquals("myTable.myColumn=myValue "
+                + "OR (myColumn2<abs(myValue2) "
+                + "AND myTable.myColumn3>=3)",
+            criterion.toString());
+    }
 }

Added: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/JoinTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/JoinTest.java?rev=1224858&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/JoinTest.java
(added)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/JoinTest.java
Tue Dec 27 02:22:14 2011
@@ -0,0 +1,57 @@
+package org.apache.torque.criteria;
+
+/*
+ * 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.BaseTestCase;
+import org.apache.torque.ColumnImpl;
+
+/**
+ * Test for the Join class.
+ *
+ * @version $Id: $
+ */
+public class JoinTest extends BaseTestCase
+{
+    public void testHashCodeAndEquals()
+    {
+        Join join = new Join(
+                new ColumnImpl("myTable1", "myColumn1"),
+                new ColumnImpl("myTable2", "myColumn2"),
+                Criteria.LEFT_JOIN);
+        Join compareToJoin = new Join(
+                new ColumnImpl("myTable1", "myColumn1"),
+                new ColumnImpl("myTable2", "myColumn2"),
+                Criteria.LEFT_JOIN);
+        assertEquals(join.hashCode(), compareToJoin.hashCode());
+        assertEquals(join, compareToJoin);
+    }
+
+
+    public void testToString()
+    {
+        Join join = new Join(
+                new ColumnImpl("myTable1", "myColumn1"),
+                new ColumnImpl("myTable2", "myColumn2"),
+                Criteria.LEFT_JOIN);
+        assertEquals(" LEFT JOIN  : myTable1.myColumn1=myTable2.myColumn2 "
+                + "(ignoreCase not considered)",
+                join.toString());
+    }
+}



---------------------------------------------------------------------
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