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