db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r519508 - in /db/ojb/branches/OJB_1_0_RELEASE/src: schema/ojbtest-schema.xml test/org/apache/ojb/broker/AllTests.java test/org/apache/ojb/broker/FunctionTest.java test/org/apache/ojb/repository_junit.xml
Date Sun, 18 Mar 2007 01:48:15 GMT
Author: arminw
Date: Sat Mar 17 18:48:15 2007
New Revision: 519508

URL: http://svn.apache.org/viewvc?view=rev&rev=519508
Log:
add test for OJB-133

Added:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java
Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml?view=diff&rev=519508&r1=519507&r2=519508
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml Sat Mar 17 18:48:15 2007
@@ -2046,5 +2046,75 @@
         </foreign-key>
     </table>
 
+    <table name="FUNCTION_TEST_KEY">
+		<column
+		   name="IDENTITY_"
+		   type="INTEGER"
+		   primaryKey="true"/>
+		<column
+		   name="MOD_"
+		   type="INTEGER"
+		   primaryKey="true"
+		   />
+		<column
+		   name="MAX_"
+		   type="INTEGER"
+		   primaryKey="true"
+		   />
+		<column
+		   name="AVG_"
+		   type="INTEGER"
+		   primaryKey="true"
+		   />
+		<column
+		   name="DISTINCT_"
+		   type="INTEGER"
+		   primaryKey="true"
+		   />
+		<column
+		   name="HOUR_"
+		   type="VARCHAR"
+		   primaryKey="true"
+		   />
+		<column
+		   name="AS_"
+		   type="VARCHAR"
+		   primaryKey="true"
+		   />
+		<column
+		   name="NAME_"
+		   type="VARCHAR"/>
+		<column
+		   name="FK_ONE_"
+		   type="INTEGER"/>
+		<foreign-key foreignTable="FUNCTION_TEST_ONE">
+			<reference local="FK_ONE_" foreign="ABS_"/>
+		</foreign-key>
+	</table>
+
+	<table name="FUNCTION_TEST_ONE">
+		<column
+		   name="ABS_"
+		   type="INTEGER"
+		   primaryKey="true"
+		   />
+		<column
+		   name="NAME_"
+		   type="VARCHAR"/>
+	</table>
+
+	<table name="FUNCTION_TEST_MANY">
+		<column
+		   name="SUM_"
+		   type="INTEGER"
+		   primaryKey="true"
+		   />
+		<column
+		   name="NAME_"
+		   type="VARCHAR"/>
+		<column
+		   name="FK_ONE_"
+		   type="INTEGER"/>
+	</table>
 
 </database>

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java?view=diff&rev=519508&r1=519507&r2=519508
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java Sat Mar 17
18:48:15 2007
@@ -137,6 +137,10 @@
         suite.addTestSuite(DatabaseIdentityMySqlTest.class);
         suite.addTestSuite(DatabaseIdentityMaxDBTest.class);
         suite.addTestSuite(SeqManMultiHsqlTest.class);
+        /*
+        arminw: comment in after 1.0.5 release
+        */
+        //suite.addTestSuite(FunctionTest.class);
 
         // BRJ: ensure shutdown of hsqldb
         suite.addTestSuite(HsqldbShutdown.class);

Added: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java?view=auto&rev=519508
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java (added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FunctionTest.java Sat Mar
17 18:48:15 2007
@@ -0,0 +1,382 @@
+package org.apache.ojb.broker;
+
+/* Copyright 2002-2007 The Apache Software Foundation
+ *
+ * Licensed 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 java.lang.Object;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.ojb.junit.PBTestCase;
+import org.apache.ojb.broker.query.Criteria;
+import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.ojb.broker.query.ReportQueryByCriteria;
+import org.apache.commons.lang.builder.EqualsBuilder;
+
+/**
+ * This class tests the correct detection of attributes, functions and keywords.
+ *
+ * @version $Id$
+ */
+public class FunctionTest extends PBTestCase
+{
+    public static void main(String[] args)
+    {
+        String[] arr = {FunctionTest.class.getName()};
+        junit.textui.TestRunner.main(arr);
+    }
+
+    public FunctionTest()
+    {
+    }
+
+    public FunctionTest(String name)
+    {
+        super(name);
+    }
+
+    Key createTestObject(String name)
+    {
+        Key key = new Key(name);
+        One one = new One(name);
+        Many m1 = new Many(name + "_1");
+        Many m2 = new Many(name + "_2");
+        Many m3 = new Many(name + "_3");
+        Many m4 = new Many(name + "_4");
+        key.setCurdate(one);
+        one.addSum(m1);
+        one.addSum(m2);
+        one.addSum(m3);
+        one.addSum(m4);
+        broker.beginTransaction();
+        broker.store(key);
+        broker.commitTransaction();
+
+        return key;
+    }
+
+    public void testInsert()
+    {
+        String name = "testInsert_" + System.currentTimeMillis();
+        Key key = createTestObject(name);
+
+        Identity oid = broker.serviceIdentity().buildIdentity(key);
+        broker.clearCache();
+        Key keyNew = (Key) broker.getObjectByIdentity(oid);
+
+        assertNotNull(keyNew);
+        assertEquals(key, keyNew);
+    }
+
+    public void testQuery()
+    {
+        String name = "testQuery_" + System.currentTimeMillis();
+        Key key = createTestObject(name);
+        broker.clearCache();
+
+        Integer pk = ((Many) key.getCurdate().getSum().get(0)).getSum();
+        Criteria crit = new Criteria()
+                .addEqualTo("curdate.sum.sum", pk)
+                .addGreaterThan("mod(max, mod)", new Integer(key.getMod().intValue() + 10))
+                .addGreaterThan("abs(as)", new Integer(0));
+        Query q = QueryFactory.newQuery(Key.class, crit);
+
+        Key keyNew = (Key) broker.getObjectByQuery(q);
+
+        assertNotNull(keyNew);
+        assertEquals(key, keyNew);
+    }
+
+    public void testReportQuery()
+    {
+        String name = "testReportQuery_" + System.currentTimeMillis();
+        Key key = createTestObject(name);
+        broker.clearCache();
+
+        Integer pk = ((Many) key.getCurdate().getSum().get(0)).getSum();
+        Criteria crit = new Criteria().addEqualTo("curdate.sum.sum", pk);
+        ReportQueryByCriteria q = QueryFactory.newReportQuery(Key.class, crit);
+        q.setAttributes(new String[]{"name", "sum(curdate.sum)"});
+
+        Iterator it = broker.getReportQueryIteratorByQuery(q);
+        while(it.hasNext())
+        {
+            Object[] arr =  (Object[]) it.next();
+            assertNotNull(arr[0]);
+            assertNotNull(arr[1]);
+//            System.out.println("arr[0]=" +arr[0]);
+//            System.out.println("arr[1]=" +arr[1]);
+        }
+    }
+
+    /*
+    count,min,max,avg,sum,upper,lower,distinct,as
+    */
+    /**
+     * This persistence capable class contains field names equal to
+     * sql-query function names and keywords.
+     */
+    public static class Key
+    {
+        private Integer identity;
+        private Integer mod;
+        private Integer max;
+        private Integer avg;
+        private Integer distinct;
+        private String hour;
+        private String as;
+        private String name;
+        private One curdate;
+
+
+        public Key()
+        {
+        }
+
+        public Key(String name)
+        {
+            this.name = name;
+        }
+
+        public Integer getIdentity()
+        {
+            return identity;
+        }
+
+        public void setIdentity(Integer identity)
+        {
+            this.identity = identity;
+        }
+
+        public Integer getMod()
+        {
+            return mod;
+        }
+
+        public void setMod(Integer mod)
+        {
+            this.mod = mod;
+        }
+
+        public Integer getMax()
+        {
+            return max;
+        }
+
+        public void setMax(Integer max)
+        {
+            this.max = max;
+        }
+
+        public Integer getAvg()
+        {
+            return avg;
+        }
+
+        public void setAvg(Integer avg)
+        {
+            this.avg = avg;
+        }
+
+        public Integer getDistinct()
+        {
+            return distinct;
+        }
+
+        public void setDistinct(Integer distinct)
+        {
+            this.distinct = distinct;
+        }
+
+        public String getHour()
+        {
+            return hour;
+        }
+
+        public void setHour(String hour)
+        {
+            this.hour = hour;
+        }
+
+        public String getAs()
+        {
+            return as;
+        }
+
+        public void setAs(String as)
+        {
+            this.as = as;
+        }
+
+        public String getName()
+        {
+            return name;
+        }
+
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+
+        public One getCurdate()
+        {
+            return curdate;
+        }
+
+        public void setCurdate(One curdate)
+        {
+            this.curdate = curdate;
+        }
+
+        public boolean equals(Object obj)
+        {
+            if(!(obj instanceof Key)) return false;
+            Key k = (Key) obj;
+            return new EqualsBuilder()
+                    .append(as, k.as)
+                    .append(avg, k.avg)
+                    .append(curdate, k.curdate)
+                    .append(distinct, k.distinct)
+                    .append(hour, k.hour)
+                    .append(identity, k.identity)
+                    .append(max, k.max)
+                    .append(mod, k.mod)
+                    .append(name, k.name)
+                    .isEquals();
+        }
+    }
+
+    public static class One
+    {
+        private Integer abs;
+        private String name;
+        private List sum;
+
+        public One()
+        {
+        }
+
+        public One(String name)
+        {
+            this.name = name;
+        }
+
+        public List getSum()
+        {
+            return sum;
+        }
+
+        public void setSum(List sum)
+        {
+            this.sum = sum;
+        }
+
+        public void addSum(Many many)
+        {
+            if(sum == null) sum = new ArrayList();
+            if(!sum.contains(many)) sum.add(many);
+        }
+
+        public String getName()
+        {
+            return name;
+        }
+
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+
+        public Integer getAbs()
+        {
+            return abs;
+        }
+
+        public void setAbs(Integer abs)
+        {
+            this.abs = abs;
+        }
+
+        public boolean equals(Object obj)
+        {
+            if(!(obj instanceof One)) return false;
+            One k = (One) obj;
+            return new EqualsBuilder()
+                    .append(abs, k.abs)
+                    .append(sum, k.sum)
+                    .append(name, k.name)
+                    .isEquals();
+        }
+    }
+
+    public static class Many
+    {
+        private Integer sum;
+        private String name;
+        private Integer fkOne;
+
+        public Many()
+        {
+        }
+
+        public Many(String name)
+        {
+            this.name = name;
+        }
+
+        public String getName()
+        {
+            return name;
+        }
+
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+
+        public Integer getSum()
+        {
+            return sum;
+        }
+
+        public void setSum(Integer sum)
+        {
+            this.sum = sum;
+        }
+
+        public Integer getFkOne()
+        {
+            return fkOne;
+        }
+
+        public void setFkOne(Integer fkOne)
+        {
+            this.fkOne = fkOne;
+        }
+
+        public boolean equals(Object obj)
+        {
+            if(!(obj instanceof Many)) return false;
+            Many k = (Many) obj;
+            return new EqualsBuilder()
+                    .append(fkOne, k.fkOne)
+                    .append(sum, k.sum)
+                    .append(name, k.name)
+                    .isEquals();
+        }
+    }
+}

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml?view=diff&rev=519508&r1=519507&r2=519508
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml Sat Mar 17
18:48:15 2007
@@ -3297,4 +3297,147 @@
             <runtime-argument field-ref="id"/>
         </delete-procedure>
     </class-descriptor>
+
+
+        
+    <class-descriptor
+        class="org.apache.ojb.broker.FunctionTest$Key"
+        table="FUNCTION_TEST_KEY"
+    >
+        <field-descriptor
+             name="identity"
+             column="IDENTITY_"
+             jdbc-type="INTEGER"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="mod"
+             column="MOD_"
+             jdbc-type="INTEGER"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="max"
+             column="MAX_"
+             jdbc-type="INTEGER"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="avg"
+             column="AVG_"
+             jdbc-type="INTEGER"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="distinct"
+             column="DISTINCT_"
+             jdbc-type="INTEGER"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="hour"
+             column="HOUR_"
+             jdbc-type="VARCHAR"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="as"
+             column="AS_"
+             jdbc-type="VARCHAR"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="name"
+             column="NAME_"
+             jdbc-type="VARCHAR"
+        />
+
+        <field-descriptor
+             name="fkOne"
+             column="FK_ONE_"
+             jdbc-type="INTEGER"
+             access="anonymous"
+        />
+
+        <reference-descriptor
+           name="curdate"
+           class-ref="org.apache.ojb.broker.FunctionTest$One"
+           proxy="true"
+           auto-retrieve="true"
+           auto-update="object"
+           auto-delete="object"
+       >
+           <foreignkey field-ref="fkOne"/>
+       </reference-descriptor>
+    </class-descriptor>
+
+    <class-descriptor
+        class="org.apache.ojb.broker.FunctionTest$One"
+        table="FUNCTION_TEST_ONE"
+    >
+        <field-descriptor
+             name="abs"
+             column="ABS_"
+             jdbc-type="INTEGER"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="name"
+             column="NAME_"
+             jdbc-type="VARCHAR"
+        />
+
+        <collection-descriptor
+         name="sum"
+         element-class-ref="org.apache.ojb.broker.FunctionTest$Many"
+         proxy="true"
+         auto-retrieve="true"
+         auto-update="object"
+         auto-delete="object"
+      >
+         <inverse-foreignkey field-ref="fkOne"/>
+      </collection-descriptor>
+    </class-descriptor>
+
+    <class-descriptor
+        class="org.apache.ojb.broker.FunctionTest$Many"
+        table="FUNCTION_TEST_MANY"
+    >
+        <field-descriptor
+             name="sum"
+             column="SUM_"
+             jdbc-type="INTEGER"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="name"
+             column="NAME_"
+             jdbc-type="VARCHAR"
+        />
+
+        <field-descriptor
+             name="fkOne"
+             column="FK_ONE_"
+             jdbc-type="INTEGER"
+        />
+    </class-descriptor>
+
 <!-- Mapping of classes used in junit tests and tutorials ends here -->



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


Mime
View raw message