1 21 package com.db4o.db4ounit.common.soda.classes.untypedhierarchy; 22 import com.db4o.db4ounit.common.soda.classes.typedhierarchy.*; 23 import com.db4o.query.*; 24 25 26 27 28 29 public class STUH1TestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase { 30 31 public Object h2; 32 public Object foo1; 33 34 public STUH1TestCase() { 35 } 36 37 public STUH1TestCase(STUH2 a2) { 38 h2 = a2; 39 } 40 41 public STUH1TestCase(String str) { 42 foo1 = str; 43 } 44 45 public STUH1TestCase(STUH2 a2, String str) { 46 h2 = a2; 47 foo1 = str; 48 } 49 50 public Object [] createData() { 51 return new Object [] { 52 new STUH1TestCase(), 53 new STUH1TestCase("str1"), 54 new STUH1TestCase(new STUH2()), 55 new STUH1TestCase(new STUH2("str2")), 56 new STUH1TestCase(new STUH2(new STUH3("str3"))), 57 new STUH1TestCase(new STUH2(new STUH3("str3"), "str2")), 58 }; 59 } 60 61 public void testStrNull() { 62 Query q = newQuery(); 63 q.constrain(new STUH1TestCase()); 64 q.descend("foo1").constrain(null); 65 66 expect(q, new int[] { 0, 2, 3, 4, 5 }); 67 } 68 69 public void testBothNull() { 70 Query q = newQuery(); 71 q.constrain(new STUH1TestCase()); 72 q.descend("foo1").constrain(null); 73 q.descend("h2").constrain(null); 74 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[0]); 75 } 76 77 public void testDescendantNotNull() { 78 Query q = newQuery(); 79 80 q.constrain(new STUH1TestCase()); 81 q.descend("h2").constrain(null).not(); 82 expect(q, new int[] { 2, 3, 4, 5 }); 83 } 84 85 public void testDescendantDescendantNotNull() { 86 Query q = newQuery(); 87 88 q.constrain(new STUH1TestCase()); 89 q.descend("h2").descend("h3").constrain(null).not(); 90 expect(q, new int[] { 4, 5 }); 91 } 92 93 public void testDescendantExists() { 94 Query q = newQuery(); 95 96 q.constrain(_array[2]); 97 expect(q, new int[] { 2, 3, 4, 5 }); 98 } 99 100 public void testDescendantValue() { 101 Query q = newQuery(); 102 103 q.constrain(_array[3]); 104 expect(q, new int[] { 3, 5 }); 105 } 106 107 public void testDescendantDescendantExists() { 108 Query q = newQuery(); 109 110 q.constrain(new STUH1TestCase(new STUH2(new STUH3()))); 111 expect(q, new int[] { 4, 5 }); 112 } 113 114 public void testDescendantDescendantValue() { 115 Query q = newQuery(); 116 117 q.constrain(new STUH1TestCase(new STUH2(new STUH3("str3")))); 118 expect(q, new int[] { 4, 5 }); 119 } 120 121 public void testDescendantDescendantStringPath() { 122 Query q = newQuery(); 123 124 q.constrain(new STUH1TestCase()); 125 q.descend("h2").descend("h3").descend("foo3").constrain("str3"); 126 expect(q, new int[] { 4, 5 }); 127 } 128 129 public void testSequentialAddition() { 130 Query q = newQuery(); 131 q.constrain(new STUH1TestCase()); 132 133 Query cur = q.descend("h2"); 134 cur.constrain(new STUH2()); 135 cur.descend("foo2").constrain("str2"); 136 cur = cur.descend("h3"); 137 cur.constrain(new STUH3()); 138 cur.descend("foo3").constrain("str3"); 139 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[5]); 140 } 141 142 public void testTwoLevelOr() { 143 Query q = newQuery(); 144 145 q.constrain(new STUH1TestCase("str1")); 146 q.descend("foo1").constraints().or( 147 q.descend("h2").descend("h3").descend("foo3").constrain("str3")); 148 expect(q, new int[] { 1, 4, 5 }); 149 } 150 151 public void testThreeLevelOr() { 152 Query q = newQuery(); 153 154 q.constrain(new STUH1TestCase("str1")); 155 q.descend("foo1").constraints().or( 156 q.descend("h2").descend("foo2").constrain("str2")).or( 157 q.descend("h2").descend("h3").descend("foo3").constrain("str3")); 158 159 expect(q, new int[] { 1, 3, 4, 5 }); 160 } 161 162 public void testNonExistentDescendant() { 163 Query q = newQuery(); 164 STUH1TestCase constraint = new STUH1TestCase(); 165 constraint.foo1 = new STETH2(); 166 q.constrain(constraint); 167 expect(q, new int[] {}); 168 } 169 170 } 171 | Popular Tags |