1 21 package com.db4o.db4ounit.common.soda.wrapper.untyped; 22 import com.db4o.*; 23 import com.db4o.query.*; 24 25 26 public class STStringUTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase { 27 28 public Object str; 29 30 public STStringUTestCase() { 31 } 32 33 public STStringUTestCase(String str) { 34 this.str = str; 35 } 36 37 public Object [] createData() { 38 return new Object [] { 39 new STStringUTestCase(null), 40 new STStringUTestCase("aaa"), 41 new STStringUTestCase("bbb"), 42 new STStringUTestCase("dod")}; 43 } 44 45 public void testEquals() { 46 Query q = newQuery(); 47 q.constrain(_array[2]); 48 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[2]); 49 } 50 51 public void testNotEquals() { 52 Query q = newQuery(); 53 q.constrain(_array[2]); 54 q.descend("str").constraints().not(); 55 56 expect(q, new int[] { 0, 1, 3 }); 57 } 58 59 public void testDescendantEquals() { 60 Query q = newQuery(); 61 q.constrain(new STStringUTestCase()); 62 q.descend("str").constrain("bbb"); 63 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase("bbb")); 64 } 65 66 public void testContains() { 67 Query q = newQuery(); 68 q.constrain(new STStringUTestCase("od")); 69 q.descend("str").constraints().contains(); 70 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase("dod")); 71 } 72 73 public void testNotContains() { 74 Query q = newQuery(); 75 q.constrain(new STStringUTestCase("od")); 76 q.descend("str").constraints().contains().not(); 77 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect( 78 q, 79 new Object [] { new STStringUTestCase(null), new STStringUTestCase("aaa"), new STStringUTestCase("bbb")}); 80 } 81 82 public void testLike() { 83 Query q = newQuery(); 84 q.constrain(new STStringUTestCase("do")); 85 q.descend("str").constraints().like(); 86 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase("dod")); 87 q = newQuery(); 88 q.constrain(new STStringUTestCase("od")); 89 q.descend("str").constraints().like(); 90 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,_array[3]); 91 } 92 93 public void testNotLike() { 94 Query q = newQuery(); 95 q.constrain(new STStringUTestCase("aaa")); 96 q.descend("str").constraints().like().not(); 97 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect( 98 q, 99 new Object [] { new STStringUTestCase(null), new STStringUTestCase("bbb"), new STStringUTestCase("dod")}); 100 q = newQuery(); 101 q.constrain(new STStringUTestCase("xxx")); 102 q.descend("str").constraints().like(); 103 expect(q, new int[] {}); 104 } 105 106 public void testIdentity() { 107 Query q = newQuery(); 108 q.constrain(new STStringUTestCase("aaa")); 109 ObjectSet set = q.execute(); 110 STStringUTestCase identityConstraint = (STStringUTestCase) set.next(); 111 identityConstraint.str = "hihs"; 112 q = newQuery(); 113 q.constrain(identityConstraint).identity(); 114 identityConstraint.str = "aaa"; 115 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase("aaa")); 116 } 117 118 public void testNotIdentity() { 119 Query q = newQuery(); 120 q.constrain(new STStringUTestCase("aaa")); 121 ObjectSet set = q.execute(); 122 STStringUTestCase identityConstraint = (STStringUTestCase) set.next(); 123 identityConstraint.str = null; 124 q = newQuery(); 125 q.constrain(identityConstraint).identity().not(); 126 identityConstraint.str = "aaa"; 127 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect( 128 q, 129 new Object [] { new STStringUTestCase(null), new STStringUTestCase("bbb"), new STStringUTestCase("dod")}); 130 } 131 132 public void testNull() { 133 Query q = newQuery(); 134 q.constrain(new STStringUTestCase(null)); 135 q.descend("str").constrain(null); 136 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase(null)); 137 } 138 139 public void testNotNull() { 140 Query q = newQuery(); 141 q.constrain(new STStringUTestCase(null)); 142 q.descend("str").constrain(null).not(); 143 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect( 144 q, 145 new Object [] { new STStringUTestCase("aaa"), new STStringUTestCase("bbb"), new STStringUTestCase("dod")}); 146 } 147 148 public void testConstraints() { 149 Query q = newQuery(); 150 q.constrain(new STStringUTestCase("aaa")); 151 q.constrain(new STStringUTestCase("bbb")); 152 Constraints cs = q.constraints(); 153 Constraint[] csa = cs.toArray(); 154 if (csa.length != 2) { 155 db4ounit.Assert.fail("Constraints not returned"); 156 } 157 } 158 159 } 160 | Popular Tags |