From jdo-commits-return-562-apmail-db-jdo-commits-archive=www.apache.org@db.apache.org Sun May 22 19:41:18 2005 Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 91183 invoked from network); 22 May 2005 19:41:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 May 2005 19:41:18 -0000 Received: (qmail 72137 invoked by uid 500); 22 May 2005 19:41:16 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Received: (qmail 72086 invoked by uid 99); 22 May 2005 19:41:15 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 22 May 2005 12:41:10 -0700 Received: (qmail 56855 invoked by uid 65534); 22 May 2005 18:41:07 -0000 Message-ID: <20050522184107.56854.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r171355 [23/31] - in /incubator/jdo/trunk/fostore20: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/fostore/ test/ test/conf/ test/fsuid2/ test/fsuid2/org/ test/fsuid2/org/apache/ test/fsuid2/org/apache/jdo/ test/fsuid2/org/apache/jdo/pc/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/impl/ test/java/org/apache/jdo/impl/fostore/ test/java/org/apache/jdo/pc/ test/java/org/apache/jdo/pc/appid/ test/java/org/apache/jdo/pc/empdept/ test/java/org/apache/jdo/pc/serializable/ test/java/org/apache/jdo/pc/xempdept/ test/java/org/apache/jdo/test/ test/java/org/apache/jdo/test/query/ test/java/org/apache/jdo/test/util/ test/jdo/ test/jdo/org/ test/jdo/org/apache/ test/jdo/org/apache/jdo/ test/jdo/org/apache/jdo/pc/ test/jdo/org/apache/jdo/pc/appid/ test/jdo/org/apache/jdo/pc/empdept/ test/jdo/org/apache/jdo/pc/serializable/ test/jdo/org/apache/jdo/pc/xempdept/ Date: Sun, 22 May 2005 18:40:21 -0000 To: jdo-commits@db.apache.org From: mbo@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Wea= kValueHashMap.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_WeakValueHashMap.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_WeakVa= lueHashMap.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_WeakVa= lueHashMap.java Sun May 22 11:40:13 2005 @@ -0,0 +1,572 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * TestWeakHashMap.java + * + */ + +package org.apache.jdo.test; + +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; +import org.apache.jdo.util.WeakValueHashMap; + +/** + * + * @author Markus Fuchs + */ +public class Test_WeakValueHashMap extends AbstractTest { + + static boolean verbose =3D Boolean.getBoolean("verbose"); + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_WeakValueHashMap.class); + } + =20 + /** */ + protected void setUp() { } + + /** */ + protected void tearDown() { } + + /** */ + public void testContainsKey() { + Map map =3D new WeakValueHashMap(); + + Y y11 =3D new Y("y11"); + X x11 =3D new X("x11", y11); + X x12 =3D new X("x12"); + Y y12 =3D new Y("y12", x12); + X x14 =3D new X("x14"); + Y y14 =3D new Y("y14"); + map.put(x11, y11); + map.put(x12, y12); + map.put(new X("x13"), new Y("y13")); + map.put(x14, null); + map.put(null, y14); + y11 =3D null; + y12 =3D null; + + if (verbose) System.out.println("\nTest ContainsKey:"); + if (verbose) printEntries(map); + + // check whether instances are included in map + assertTrue("FAILURE: map does not contain x11", map.containsKey(ne= w X("x11", y11))); + assertTrue("FAILURE: map does not contain x12", map.containsKey(ne= w X("x12"))); + assertTrue("FAILURE: map does not contain x13", map.containsKey(ne= w X("x13"))); + assertTrue("FAILURE: map does not contain x14", map.containsKey(ne= w X("x14"))); + assertTrue("FAILURE: map does not contain null", map.containsKey(n= ull)); + + // now gc + gc(); + + if (verbose) System.out.println("After GC:"); + if (verbose) printEntries(map); + + // check whether instances are included in map + assertTrue("FAILURE: map does not contain x11", map.containsKey(ne= w X("x11"))); + assertTrue("FAILURE: map contains x12", !map.containsKey(new X("x1= 2"))); + assertTrue("FAILURE: map contains x13", !map.containsKey(new X("x1= 3"))); + assertTrue("FAILURE: map does not contain x14", map.containsKey(ne= w X("x14"))); + assertTrue("FAILURE: map does not contain null", map.containsKey(n= ull)); + + map.clear(); + } + + /** */ + public void testContainsValue() { + Map map =3D new WeakValueHashMap(); + + Y y11 =3D new Y("y11"); + X x11 =3D new X("x11", y11); + X x12 =3D new X("x12"); + Y y12 =3D new Y("y12", x12); + X x14 =3D new X("x14"); + Y y14 =3D new Y("y14"); + map.put(x11, y11); + map.put(x12, y12); + map.put(new X("x13"), new Y("y13")); + map.put(x14, null); + map.put(null, y14); + y11 =3D null; + y12 =3D null; + + if (verbose) System.out.println("\nTest ContainsValue:"); + if (verbose) printEntries(map); + + // check whether instances are included in map + assertTrue("FAILURE: map does not contain y11", map.containsValue(= new Y("y11"))); + assertTrue("FAILURE: map does not contain y12", map.containsValue(= new Y("y12", x12))); + assertTrue("FAILURE: map does not contain y13", map.containsValue(= new Y("y13"))); + assertTrue("FAILURE: map does not contain y14", map.containsValue(= new Y("y14"))); + assertTrue("FAILURE: map does not contain null", map.containsValue= (new Y("y14"))); + + // now gc + gc(); + + if (verbose) System.out.println("After GC:"); + if (verbose) printEntries(map); + + // check whether instances are included in map + assertTrue("FAILURE: map does not contain y11", map.containsValue(= new Y("y11"))); + assertTrue("FAILURE: map contains y12", !map.containsValue(new Y("= y12", x12))); + assertTrue("FAILURE: map contains y13", !map.containsValue(new Y("= y13"))); + assertTrue("FAILURE: map does not contain y14", map.containsValue(= new Y("y14"))); + assertTrue("FAILURE: map does not contain null", map.containsValue= (null)); + + map.clear(); + } + + /** */ + public void testGet() { + Map map =3D new WeakValueHashMap(); + + Y y11 =3D new Y("y11"); + X x11 =3D new X("x11", y11); + X x12 =3D new X("x12"); + Y y12 =3D new Y("y12", x12); + X x14 =3D new X("x14"); + Y y14 =3D new Y("y14"); + map.put(x11, y11); + map.put(x12, y12); + map.put(new X("x13"), new Y("y13")); + map.put(x14, null); + map.put(null, y14); + + if (verbose) System.out.println("\nTest Get:"); + if (verbose) printEntries(map); + + // check whether instances are included in map + assertEquals("Get (x11) returns wrong value", y11, map.get(new X("= x11"))); + assertEquals("Get (x12) returns wrong value", y12, map.get(new X("= x12"))); + assertEquals("Get (x13) returns wrong value", new Y("y13"), map.ge= t(new X("x13"))); + assertNull("Get (x14) returns wrong value", map.get(new X("x14"))); + assertEquals("Get (null) returns wrong value", y14, map.get(null)); + + y11 =3D null; + y12 =3D null; + + // now gc + gc(); + + if (verbose) System.out.println("After GC:"); + if (verbose) printEntries(map); + + // check whether instances are included in map + assertNotNull("Get (x11) returns wrong value", map.get(new X("x11"= ))); + assertNull("Get (x12) returns wrong value",map.get(new X("x12"))); + assertNull("Get (x13) returns wrong value", map.get(new X("x13"))); + assertNull("Get (x14) returns wrong value", map.get(new X("x14"))); + assertNotNull("Get (null) returns wrong value", map.get(null)); + + map.clear(); + } + + /** */ + public void testSize() { + Map map =3D new WeakValueHashMap(); + + Y y11 =3D new Y("y11"); + X x11 =3D new X("x11", y11); + X x12 =3D new X("x12"); + Y y12 =3D new Y("y12", x12); + X x14 =3D new X("x14"); + Y y14 =3D new Y("y14"); + map.put(x11, y11); + map.put(x12, y12); + map.put(new X("x13"), new Y("y13")); + map.put(x14, null); + map.put(null, y14); + y11 =3D null; + y12 =3D null; + + int size1, size2, size3; + + if (verbose) System.out.println("\nTest Size:"); + if (verbose) printEntries(map); + + size1 =3D map.size(); + size2 =3D map.entrySet().size(); + size3 =3D map.values().size(); + + if (verbose) System.out.println("Size: " + size1); + + assertEquals("FAILURE: unexpected size of map", 5, size1);=20 + assertEquals("FAILURE: unexpected size of entrySet", 5, size2);=20 + assertEquals("FAILURE: unexpected size of values", 5, size3);=20 + + // now gc + gc(); + + if (verbose) System.out.println("After GC:"); + if (verbose) printEntries(map); + + size1 =3D map.size(); + size2 =3D map.entrySet().size(); + size3 =3D map.values().size(); + + if (verbose) System.out.println("After GC, size: " + size1); + + assertEquals("FAILURE: unexpected size of map", 3, size1);=20 + assertEquals("FAILURE: unexpected size of entrySet", 3, size2);=20 + assertEquals("FAILURE: unexpected size of values", 3, size3);=20 + + map.clear(); + } + + /** */ + public void testEntrySet() { + Map map =3D new WeakValueHashMap(); + + Y y11 =3D new Y("y11"); + X x11 =3D new X("x11", y11); + X x12 =3D new X("x12"); + Y y12 =3D new Y("y12", x12); + X x14 =3D new X("x14"); + Y y14 =3D new Y("y14"); + map.put(x11, y11); + map.put(x12, y12); + map.put(new X("x13"), new Y("y13")); + map.put(x14, null); + map.put(null, y14); + y11 =3D null; + y12 =3D null; + + if (verbose) System.out.println("\nTest EntrySet:"); + if (verbose) printEntries(map); + + Set entrySet =3D map.entrySet(); + + if (verbose) System.out.println("size: " + entrySet.size()); + assertEquals("Unexpected size of entrySet", 5, entrySet.size()); + if (verbose) System.out.println("isEmpty: " + entrySet.isEmpty()); + assertFalse("Unexpected empty entrySet", entrySet.isEmpty()); + if (verbose) System.out.println("hashCode: " + entrySet.hashCode()= ); + + entrySet.remove(new Entry((Object) x12, (Object) new Y("y12", x12)= )); + + if (verbose) System.out.println("After remove(x12, y12):"); + if (verbose) printEntries(map); + + if (verbose) System.out.println("size: " + entrySet.size()); + assertEquals("Unexpected size of entrySet", 4, entrySet.size()); + if (verbose) System.out.println("isEmpty: " + entrySet.isEmpty()); + assertFalse("Unexpected empty entrySet", entrySet.isEmpty()); + if (verbose) System.out.println("hashCode: " + entrySet.hashCode()= ); + + // Remove a specific entry, then print the map; the entry must be + // gone from there. + for (Iterator i =3D entrySet.iterator(); i.hasNext();) { + Map.Entry ent =3D (Map.Entry) i.next(); + if (ent.getKey() =3D=3D x11) { + i.remove(); + } =20 + } + =20 + if (verbose) System.out.println("After Iterator.remove:"); + if (verbose) printEntries(map); + + if (verbose) System.out.println("size: " + entrySet.size()); + assertEquals("Unexpected size of entrySet", 3, entrySet.size()); + if (verbose) System.out.println("isEmpty: " + entrySet.isEmpty()); + assertFalse("Unexpected empty entrySet", entrySet.isEmpty()); + if (verbose) System.out.println("hashCode: " + entrySet.hashCode()= ); + + entrySet.clear(); + if (verbose) System.out.println("After clear:"); + + if (verbose) System.out.println("size: " + entrySet.size()); + assertEquals("Unexpected size of entrySet", 0, entrySet.size()); + if (verbose) System.out.println("isEmpty: " + entrySet.isEmpty()); + assertTrue("Unexpected non empty entrySet", entrySet.isEmpty()); + if (verbose) System.out.println("hashCode: " + entrySet.hashCode()= ); + } + + /** */ + public void testValues() { + Map map =3D new WeakValueHashMap(); + + Y y11 =3D new Y("y11"); + X x11 =3D new X("x11", y11); + X x12 =3D new X("x12"); + Y y12 =3D new Y("y12", x12); + X x14 =3D new X("x14"); + Y y14 =3D new Y("y14"); + map.put(x11, y11); + map.put(x12, y12); + map.put(new X("x13"), new Y("y13")); + map.put(x14, null); + map.put(null, y14); + y11 =3D null; + y12 =3D null; + + Collection values =3D map.values(); + + if (verbose) System.out.println("\nTest Values:"); + if (verbose) printValues(map); + assertEquals("Unexpected size of values", 5, values.size()); + + // now gc + gc(); + + if (verbose) System.out.println("After GC:"); + if (verbose) printValues(map); + assertEquals("Unexpected size of values", 3, values.size()); + + values.remove(new Y("y11")); + + if (verbose) System.out.println("After remove(y11):"); + if (verbose) printValues(map); + assertEquals("Unexpected size of values", 2, values.size()); + + map.clear(); + } + + /** */ + public void testAll() { + Map weakMap =3D new WeakValueHashMap(); + + // WeakHashMap + Y y11 =3D new Y("y11"); + X x11 =3D new X("x11", y11); + X x12 =3D new X("x12"); + Y y12 =3D new Y("y12", x12); + X x14 =3D new X("x14"); + Y y14 =3D new Y("y14"); + weakMap.put(x11, y11); + weakMap.put(x12, y12); + weakMap.put(new X("x13"), new Y("y13")); + weakMap.put(x14, null); + weakMap.put(null, y14); +=20 + // Regular HashMap + Map map =3D new HashMap(); + map.put(x11, y11); + map.put(x12, y12); + map.put(new X("x13"), new Y("y13")); + map.put(x14, null); + map.put(null, y14); + + if (verbose) System.out.println("\nTest equals:"); + if (verbose) System.out.println("Weak map Map1:"); if (verbose) pr= intEntries(weakMap); + if (verbose) System.out.println("Regular map Map2:"); if (verbose)= printEntries(map); + if (verbose) System.out.println("Map2.equals(Map1): " + map.equals= (weakMap)); + assertTrue("map.equals(weakMap) should return true", map.equals(we= akMap)); + if (verbose) System.out.println("Map1.equals(Map2): " + weakMap.eq= uals(map)); + assertTrue("weakMap.equals(map) should return true", weakMap.equal= s(map)); + + weakMap.put(new X("x15"), new Y("y15")); + map.put(new X("x16"), new Y("y16")); + + if (verbose) System.out.println("\nTest equals:"); + if (verbose) System.out.println("Weak map Map1:"); if (verbose) pr= intEntries(weakMap); + if (verbose) System.out.println("Regular map Map2:"); if (verbose)= printEntries(map); + if (verbose) System.out.println("Map2.equals(Map1): " + map.equals= (weakMap)); + assertFalse("map.equals(weakMap) should return false", map.equals(= weakMap)); + if (verbose) System.out.println("Map1.equals(Map2): " + weakMap.eq= uals(map)); + assertFalse("weakMap.equals(map) should return false", weakMap.equ= als(map)); + + weakMap.remove(new X("x15")); + map.clear(); + map.put(new X("x15"), new Y("y15")); + map.put(new X("x16"), new Y("y16")); + + if (verbose) System.out.println("\nTest putAll:"); + if (verbose) System.out.println("Weak map Map1:"); if (verbose) pr= intEntries(weakMap); + if (verbose) System.out.println("Regular map Map2:"); if (verbose)= printEntries(map); + weakMap.putAll(map); + if (verbose) System.out.println("Map1.putAll(Map2):"); if (verbose= ) printEntries(weakMap); + assertEquals("Unexpected size of Weak map", 7, weakMap.size()); + weakMap.remove(new X("x15")); + weakMap.remove(new X("x16")); + + if (verbose) System.out.println("\nTest putAll:"); + if (verbose) System.out.println("Weak map Map1:"); if (verbose) pr= intEntries(weakMap); + if (verbose) System.out.println("Regular map Map2:"); if (verbose)= printEntries(map); + map.putAll(weakMap); + if (verbose) System.out.println("Map2.putAll(Map1):"); if (verbose= ) printEntries(map); + assertEquals("Unexpected size of map", 7, map.size()); + + weakMap.clear(); + } + + /* Internal class for entries */ + private static class Entry implements Map.Entry { + private Object key; + private Object value; + + Entry(Object key, Object value) { + this.key =3D key; + this.value =3D value; + } + + public Object getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object value) { + Object oldValue =3D this.value; + this.value =3D value; + return oldValue; + } + + private static boolean valEquals(Object o1, Object o2) { + return (o1 =3D=3D null) ? (o2 =3D=3D null) : o1.equals(o2); + } + + public boolean equals(Object o) { + if (!(o instanceof Map.Entry)) return false; + Map.Entry e =3D (Map.Entry) o; + return (valEquals(key, e.getKey()) + && valEquals(value, e.getValue())); + } + + public int hashCode() { + Object k; + return (((key =3D=3D null) ? 0 : key.hashCode()) + ^ ((value =3D=3D null) ? 0 : value.hashCode())); + } + + } + + private static class X { + private String name; + private Y y; + public X(String name) { this.name =3D name; } + public X(String name, Y y) { this.name =3D name; this.y =3D y; } + public String toString() { return "(" + this.name + "|" + y + ")";= } + public int hashCode() { return (name =3D=3D null) ? 0 : name.hashC= ode(); } + public boolean equals(Object o) + { + // compare by name only + if ((o =3D=3D null) || !(o instanceof X)) + return false; + else if (name =3D=3D null) + return ((X)o).name =3D=3D null; + else + return name.equals(((X)o).name); + } + } + + private static class Y implements Comparable { + private String name; + private X x; + public Y(String name) { this.name =3D name; } + public Y(String name, X x) { this.name =3D name; this.x =3D x; } + public String toString() { return "(" + this.name + "|" + x + ")";= } + public int hashCode() { return (name =3D=3D null) ? 0 : name.hashC= ode(); } + public int compareTo(Object o) { + if (o !=3D null + && o instanceof Y) { + return toString().compareTo(o.toString()); + } else { + return 1; + } + } =20 + public boolean equals(Object o) + { + // compare by name only + if ((o =3D=3D null) || !(o instanceof Y)) + return false; + else if (name =3D=3D null) + return ((Y)o).name =3D=3D null; + else + return name.equals(((Y)o).name); + } + } + + /** + * A sorted set of instances of map entries. + */ + private static class XTreeSet extends TreeSet { + private static final Comparator c =3D new Comparator() { + public int compare(Object o1, Object o2) { + if (o1 =3D=3D null) { + return -1; + } else if (o2 =3D=3D null) { + return 1; + } else { + Object s1 =3D ((Map.Entry)o1).getKey(); + Object s2 =3D ((Map.Entry)o2).getKey(); + if (s1 =3D=3D null) { + return -1; + } else if (s2 =3D=3D null) { + return 1; + } else { + return (s1.toString()).compareTo(s2.toString()= ); + } + } + } + =20 + public boolean equals(Object obj) { + return obj.equals(this); + } + }; + =20 + XTreeSet(Collection col) { + super(c); + this.addAll(col); + } + } + + private static void printEntries(Map map) { + Set entrySet =3D map.entrySet(); + TreeSet sorted =3D new XTreeSet(entrySet); + for (Iterator i =3D sorted.iterator(); i.hasNext();) { + Map.Entry ent =3D (Map.Entry) i.next(); + System.out.println("Key: " + ent.getKey() + + " Val: " + ent.getValue()); + } + } + + private static void printValues(Map map) { + TreeSet values =3D new TreeSet(map.values()); + for (Iterator i =3D values.iterator(); i.hasNext();) { + System.out.println("Val: " + i.next()); + } + } + + private static void gc() { + //System.out.print("gc: "); + Runtime rt =3D Runtime.getRuntime(); + long oldfree; + long newfree =3D rt.freeMemory(); + do { + oldfree =3D newfree; + rt.runFinalization(); rt.gc(); + newfree =3D rt.freeMemory(); + //System.out.print('.'); + } while (newfree > oldfree); + //System.out.println(); + } + +} + + Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/query/Ad= vancedTest.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/query/AdvancedTest.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/query/Advan= cedTest.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/query/Advan= cedTest.java Sun May 22 11:40:13 2005 @@ -0,0 +1,1856 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * AdvancedTest.java + * + * Created on April 10, 2000 + */ + +package org.apache.jdo.test.query; + +import java.util.*; +import java.io.*; +import java.io.PrintStream; + +import javax.jdo.*; + +import org.apache.jdo.pc.xempdept.Department; +import org.apache.jdo.pc.xempdept.Employee; +import org.apache.jdo.pc.xempdept.PrimitiveTypes; +import org.apache.jdo.pc.xempdept.Project; + +/**=20 + * + * @author Michael Bouschen + */ +public class AdvancedTest + extends PositiveTest +{ + public AdvancedTest(PersistenceManagerFactory pmf, PrintStream log) + { + super(pmf, log); + } + + protected boolean isTestMethodName(String methodName) + { + return methodName.startsWith("advanced"); + } + + // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + // Test methods + // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + + /** + * Testcase: check for null values =3D=3D + */ + public void advanced001() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("firstname =3D=3D null"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + =20 + tx.commit(); + } + + /** + * Testcase: check for null values !=3D + */ + public void advanced002() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("firstname !=3D null"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 4; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 5; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 6; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 7; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 8; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 9; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 13; + expected.add(key); + checkQueryResult(oids, expected); + =20 + tx.commit(); + } + + /** + * Testcase: serialize/deserialize non compiled query + */ + public void advanced003() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("empid =3D=3D 3"); + setEmployeeCandidates(query); + =20 + // serialize query object + ByteArrayOutputStream bout =3D new ByteArrayOutputStream (); + ObjectOutputStream oout =3D new ObjectOutputStream (bout); + oout.writeObject (query); + oout.flush (); + byte[] bytes =3D bout.toByteArray(); + oout.close (); + + // deserialize query object + ByteArrayInputStream bin =3D new ByteArrayInputStream (bytes); + ObjectInputStream oin =3D new ObjectInputStream (bin); + query =3D (Query)oin.readObject (); + oin.close (); + + // init and execute query + query =3D pm.newQuery(query); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + checkQueryResult(oids, expected); + =20 + tx.commit(); + } + + /** + * Testcase: serialize/deserialize compiled query + * checks bug report 4518967 + */ + public void advanced004() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("empid =3D=3D 3"); + setEmployeeCandidates(query); + query.compile(); + =20 + // serialize query object + ByteArrayOutputStream bout =3D new ByteArrayOutputStream (); + ObjectOutputStream oout =3D new ObjectOutputStream (bout); + oout.writeObject (query); + oout.flush (); + byte[] bytes =3D bout.toByteArray(); + oout.close (); + + // deserialize query object + ByteArrayInputStream bin =3D new ByteArrayInputStream (bytes); + ObjectInputStream oin =3D new ObjectInputStream (bin); + query =3D (Query)oin.readObject (); + oin.close (); + + // init and execute query + query =3D pm.newQuery(query); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + checkQueryResult(oids, expected); + =20 + tx.commit(); + } + + /** + * Testcase: serialize/deserialize compiled query=20 + * (using more compilated query) + * checks bug report 4518967 + */ + public void advanced005() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.declareParameters("Project p"); + query.declareVariables("Project project"); + query.setFilter("projects.contains(project) & project.projid =3D= =3D p.projid"); + setEmployeeCandidates(query); + query.compile(); + =20 + // serialize query object + ByteArrayOutputStream bout =3D new ByteArrayOutputStream (); + ObjectOutputStream oout =3D new ObjectOutputStream (bout); + oout.writeObject (query); + oout.flush (); + byte[] bytes =3D bout.toByteArray(); + oout.close (); + + // deserialize query object + ByteArrayInputStream bin =3D new ByteArrayInputStream (bytes); + ObjectInputStream oin =3D new ObjectInputStream (bin); + query =3D (Query)oin.readObject (); + oin.close (); + + // init and execute query + Project p =3D getProjectById(1L); + =20 + query =3D pm.newQuery(query); + setEmployeeCandidates(query); + Object result =3D query.execute(p); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 4; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 6; + expected.add(key); + checkQueryResult(oids, expected); + =20 + tx.commit(); + } + + /** + * Testcase: re-execute the same query w/o recompile + * checks bug report 4349720 + */ + public void advanced006() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("empid =3D=3D 6");; + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 6; + expected.add(key); + checkQueryResult(oids, expected); + + // rexecute the query + + result =3D query.execute(); + oids =3D getResultOids(result); + + // check new query result + + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: use ESCuxxxx chars in string literal + */ + public void advanced007() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("firstname =3D=3D \"\u0066irstEngOne\"");; + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } +=20 + /** + * Testcase: use ESCxxx chars in string literal + */ + public void advanced008() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("firstname =3D=3D \"\146irstEngOne\"");; + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: wildcard queries startsWith + */ + public void advanced009() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("firstname.startsWith(\"firstEng\")"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } +=20 + /** + * Testcase: wildcard queries endsWith + */ + public void advanced010() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("firstname.endsWith(\"e\")"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 5; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 9; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 13; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } +=20 + /** + * Testcase: wildcard queries startsWith with non constant arguments + */ + public void advanced011() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("firstname.startsWith(\"first\" + department.name)= "); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 4; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 5; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 6; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 7; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } +=20 + /** + * Testcase: wildcard queries endsWith with non constant arguments + */ + public void advanced012() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("firstname.endsWith(department.name + \"Five\")"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 5; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } +=20 + /** + * Testcase: wildcard queries startsWith with simple navigation + * checks bug report 4418353 + */ + public void advanced015() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("department.name.startsWith(\"Eng\")"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } +=20 + /** + * Testcase: wildcard queries endsWith with simple navigation + * checks bug report 4418353 + */ + public void advanced016() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("department.name.endsWith(\"ing\")"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 6; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 7; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: wildcard queries startsWith with collection navigation + * checks bug report 4418353 + */ + public void advanced017() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.declareImports("import org.apache.jdo.pc.xempdept.Project"); + query.declareVariables("Project p"); + query.setFilter("projects.contains(p) & p.name.startsWith(\"E\")"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 4; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 6; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } +=20 + /** + * Testcase: wildcard queries endsWith with collection navigation + * checks bug report 4418353 + */ + public void advanced018() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.declareImports("import org.apache.jdo.pc.xempdept.Project"); + query.declareVariables("Project p"); + query.setFilter("projects.contains(p) & p.name.endsWith(\"g Projec= t\")"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 4; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 6; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 7; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: no filter specified + */ + public void advanced019() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Department.class); + setDepartmentCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Department.Oid key =3D new Department.Oid(); + key.deptid =3D 1; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 2; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 3; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 4; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 11; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 12; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: filter specified as empty string + */ + public void advanced020() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Department.class); + query.setFilter(" "); + setDepartmentCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Department.Oid key =3D new Department.Oid(); + key.deptid =3D 1; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 2; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 3; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 4; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 11; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 12; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: optimize boolean constant =3D=3D boolean constant + */ + public void advanced021() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("true =3D=3D !true"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: optimize boolean constant !=3D boolean constant + */ + public void advanced022() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Department.class); + query.setFilter("true !=3D (employees =3D=3D null)"); + setDepartmentCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Department.Oid key =3D new Department.Oid(); + key.deptid =3D 1; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 2; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 3; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 4; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 11; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: optimize boolean constant =3D=3D expr + */ + public void advanced023() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("true =3D=3D (empid =3D=3D 1)"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: optimize expr =3D=3D boolean constant + * checks bug report 4444393 + */ + public void advanced024() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Department.class); + query.setFilter("employees.isEmpty() =3D=3D false"); + setDepartmentCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Department.Oid key =3D new Department.Oid(); + key.deptid =3D 1; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 2; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 3; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 4; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 11; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: optimize boolean constant !=3D expr + */ + public void advanced025() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("false !=3D firstname.startsWith(\"firstEng\")"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: optimize expr !=3D boolean constant + */ + public void advanced026() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Department.class); + query.setFilter("employees.isEmpty() !=3D true"); + setDepartmentCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Department.Oid key =3D new Department.Oid(); + key.deptid =3D 1; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 2; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 3; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 4; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 11; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: optimize expr && true + */ + public void advanced027() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("(empid =3D=3D 1) && true"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: optimize expr & false + */ + public void advanced028() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("lastname.endsWith(\"bla\") & false"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: true & expr + */ + public void advanced029() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("true & team.isEmpty()"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 5; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 7; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 9; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 13; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: false && expr + */ + public void advanced030() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("(team =3D=3D null) && (empid =3D=3D 1)"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + checkQueryResult(oids, expected); + + tx.commit(); + } + /** + * Testcase: optimize expr | true + */ + public void advanced031() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Department.class); + query.setFilter("!employees.isEmpty() | true"); + setDepartmentCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Department.Oid key =3D new Department.Oid(); + key.deptid =3D 1; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 2; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 3; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 4; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 11; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 12; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: optimize expr || false + */ + public void advanced032() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("(empid =3D=3D 1) || false"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: true || expr + */ + public void advanced033() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("true || firstname.startsWith(\"bla\")"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 4; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 5; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 6; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 7; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 8; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 9; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 13; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + =20 + /** + * Testcase: false | expr + */ + public void advanced034() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("false | (empid =3D=3D 2)"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: !true + */ + public void advanced035() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("!true"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: invert inner equality comparison,=20 + * because of outer equality comparison with constant + */ + public void advanced036() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("(empid !=3D 1) =3D=3D false"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: invert inner logical not,=20 + * because of outer equality comparison with constant + */ + public void advanced037() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("!team.isEmpty() =3D=3D false"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 3; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 5; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 7; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 9; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 13; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: multiple boolean constant expressions + */ + public void advanced038() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter(" ((empid =3D=3D 1) && !(false)) | (false && true)= || ((empid =3D=3D 2) =3D=3D true)"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 1; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 2; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: optimize constant =3D=3D constant for non boolean constan= ts + * checks bug report 4481691 + */ + public void advanced039() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Department.class); + query.setFilter("1 =3D=3D 1"); + setDepartmentCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + Department.Oid key =3D new Department.Oid(); + key.deptid =3D 1; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 2; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 3; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 4; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 11; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 12; + expected.add(key); + key =3D new Department.Oid(); + key.deptid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: optimize constant !=3D constant for non boolean constants=20 + * checks bug report 4481691 + */ + public void advanced040() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Department.class); + query.setFilter("1 !=3D 1"); + setDepartmentCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + checkQueryResult(oids, expected); + + tx.commit(); + } + + + /** + * Testcase: Method getPersistenceManager should return null=20 + * if called for a deserialized, unbound query object. + * checks bug report 4547932 + */ + public void advanced041() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("empid =3D=3D 3"); + =20 + // serialize query object + ByteArrayOutputStream bout =3D new ByteArrayOutputStream (); + ObjectOutputStream oout =3D new ObjectOutputStream (bout); + oout.writeObject (query); + oout.flush (); + byte[] bytes =3D bout.toByteArray(); + oout.close (); + + // deserialize query object + ByteArrayInputStream bin =3D new ByteArrayInputStream (bytes); + ObjectInputStream oin =3D new ObjectInputStream (bin); + query =3D (Query)oin.readObject (); + oin.close (); + + PersistenceManager otherPM =3D query.getPersistenceManager(); + if (otherPM !=3D null) + throw new Exception("Expected null PM for deserialized, unboun= d query object, pm =3D=3D " + pm); + tx.commit(); + } + + /** + * Testcase: filter uses boolean fields (booleanField =3D=3D true) + */ + public void advanced042() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("booleanNull =3D=3D true"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 1; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 3; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 5; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 11; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: use of hex literal + * checks bug report 4818832 + */ + public void advanced043() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("intNotNull =3D=3D 0x7fffffff"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 10; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: use of oct literal + * checks bug report 4818832 + */ + public void advanced044() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + // create query + =20 + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("intNotNull =3D=3D 017777777777"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 10; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: filter using Integer.MIN_VALUE + * checks bug report 4818832 + */ + public void advanced045() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + + // create and execute query + + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("longNotNull =3D=3D -2147483648"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + + Collection expected =3D new ArrayList(); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: navigation through a null valued relationship field. + * checks bug report 4833898 + */ + public void advanced046() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + + // create and execute query + + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("this.department.deptid > 3 || this.empid =3D=3D 1= 00"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 8; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 9; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 13; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: navigation through a null valued relationship field. + * checks bug report 4833898 + */ + public void advanced047() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + + // create and execute query + + Query query =3D pm.newQuery(); + query.setClass(Employee.class); + query.setFilter("this.empid =3D=3D 100 | this.department.deptid > = 3"); + setEmployeeCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + + // check query result + + Collection expected =3D new ArrayList(); + Employee.Oid key =3D new Employee.Oid(); + key.empid =3D 8; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 9; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 11; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 12; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 13; + expected.add(key); + key =3D new Employee.Oid(); + key.empid =3D 100; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } +} + Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/query/Ar= ithmeticTest.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/query/ArithmeticTest.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/query/Arith= meticTest.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/query/Arith= meticTest.java Sun May 22 11:40:13 2005 @@ -0,0 +1,324 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * ArithmeticTest.java + * + * Created on April 10, 2000 + */ + +package org.apache.jdo.test.query; + +import java.util.*; +import java.io.PrintStream; + +import javax.jdo.*; + +import org.apache.jdo.pc.xempdept.PrimitiveTypes; + +/**=20 + * + * @author Michael Bouschen + */ +public class ArithmeticTest + extends PositiveTest +{ + public ArithmeticTest(PersistenceManagerFactory pmf, PrintStream log) + { + super(pmf, log); + } + + protected boolean isTestMethodName(String methodName) + { + return methodName.startsWith("arithmetic"); + } + + // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + // Test methods + // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + =20 + /** + * Testcase: arithmetic operation=20 + * field =3D=3D literal + literal + */ + public void arithmetic001() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create and execute query + =20 + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("intNotNull =3D=3D ( 1 + 2 )"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 3; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: arithmetic operation=20 + * field - literal > literal + */ + public void arithmetic002() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create and execute query + + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("floatNotNull - 10000.0 > 10000.0"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 14; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: arithmetic operation=20 + * field * literal > literal + */ + public void arithmetic003() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create and execute query + + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("doubleNotNull * 10 > 45.0"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 5; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 14; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: arithmetic operation=20 + * field / literal < literal + */ + public void arithmetic004() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create and execute query + + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("doubleNull > 0.0 && (doubleNull / 10.0 < 0.5)"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 1; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 2; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 3; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 4; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 10; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 12; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: unary operation + + */ + public void arithmetic005() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create and execute query + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("+byteNotNull =3D=3D 1"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 1; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: unary operation - + * check bug report 4437010 + */ + public void arithmetic006() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create and execute query + + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("-byteNull =3D=3D -1"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 1; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } + + /** + * Testcase: complement operation ~ + */ + public void arithmetic007() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create and execute query + + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("~shortNotNull =3D=3D -2"); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 1; + expected.add(key); + checkQueryResult(oids, expected); + + tx.commit(); + } +=20 + /** + * Testcase: string concatenation operator + + */ + public void arithmetic008() + throws Exception + { + Transaction tx =3D pm.currentTransaction(); + tx.begin(); + =20 + // create and execute query + Query query =3D pm.newQuery(); + query.setClass(PrimitiveTypes.class); + query.setFilter("stringNull =3D=3D \"yet \" + \"another string\""); + setPrimitiveTypesCandidates(query); + Object result =3D query.execute(); + List oids =3D getResultOids(result); + Collections.sort(oids); + =20 + // check query result + =20 + Collection expected =3D new ArrayList(); + PrimitiveTypes.Oid key =3D new PrimitiveTypes.Oid(); + key.id =3D 12; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 13; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 14; + expected.add(key); + key =3D new PrimitiveTypes.Oid(); + key.id =3D 15; + expected.add(key); + checkQueryResult(oids, expected); + =20 + tx.commit(); + } + =20 +} +