1 21 package com.db4o.test.legacy.soda.classes.simple; 22 23 import com.db4o.*; 24 import com.db4o.query.*; 25 import com.db4o.test.legacy.soda.*; 26 import com.db4o.test.legacy.soda.arrays.typed.*; 27 28 29 public class STString implements STClass1, STInterface { 30 31 public static transient SodaTest st; 32 33 public String str; 34 35 public STString() { 36 } 37 38 public STString(String str) { 39 this.str = str; 40 } 41 42 43 public Object returnSomething() { 44 return str; 45 } 46 47 public Object [] store() { 48 return new Object [] { 49 new STString(null), 50 new STString("aaa"), 51 new STString("bbb"), 52 new STString("dod")}; 53 } 54 55 public void testEquals() { 56 Query q = st.query(); 57 q.constrain(store()[2]); 58 st.expectOne(q, store()[2]); 59 } 60 61 public void testNotEquals() { 62 Query q = st.query(); 63 Constraint c = q.constrain(store()[2]); 64 q.descend("str").constraints().not(); 65 Object [] r = store(); 66 st.expect(q, new Object [] { r[0], r[1], r[3] }); 67 } 68 69 public void testDescendantEquals() { 70 Query q = st.query(); 71 q.constrain(new STString()); 72 q.descend("str").constrain("bbb"); 73 st.expectOne(q, new STString("bbb")); 74 } 75 76 public void testContains() { 77 Query q = st.query(); 78 Constraint c = q.constrain(new STString("od")); 79 q.descend("str").constraints().contains(); 80 st.expectOne(q, new STString("dod")); 81 } 82 83 public void testNotContains() { 84 Query q = st.query(); 85 Constraint c = q.constrain(new STString("od")); 86 q.descend("str").constraints().contains().not(); 87 st.expect( 88 q, 89 new Object [] { new STString(null), new STString("aaa"), new STString("bbb")}); 90 } 91 92 public void testLike() { 93 Query q = st.query(); 94 Constraint c = q.constrain(new STString("do")); 95 q.descend("str").constraints().like(); 96 st.expectOne(q, new STString("dod")); 97 q = st.query(); 98 c = q.constrain(new STString("od")); 99 q.descend("str").constraints().like(); 100 101 st.expectOne(q,store()[3]); 102 } 103 104 public void testStartsWith() { 105 Query q = st.query(); 106 Constraint c = q.constrain(new STString("do")); 107 q.descend("str").constraints().startsWith(true); 108 st.expectOne(q, new STString("dod")); 109 q = st.query(); 110 c = q.constrain(new STString("od")); 111 q.descend("str").constraints().startsWith(true); 112 st.expectNone(q); 113 } 114 115 public void testEndsWith() { 116 Query q = st.query(); 117 Constraint c = q.constrain(new STString("do")); 118 q.descend("str").constraints().endsWith(true); 119 st.expectNone(q); 120 q = st.query(); 121 c = q.constrain(new STString("od")); 122 q.descend("str").constraints().endsWith(true); 123 st.expectOne(q, new STString("dod")); 124 q = st.query(); 125 c = q.constrain(new STString("D")); 126 q.descend("str").constraints().endsWith(false); 127 st.expectOne(q, new STString("dod")); 128 } 129 130 public void testNotLike() { 131 Query q = st.query(); 132 Constraint c = q.constrain(new STString("aaa")); 133 q.descend("str").constraints().like().not(); 134 st.expect( 135 q, 136 new Object [] { new STString(null), new STString("bbb"), new STString("dod")}); 137 q = st.query(); 138 c = q.constrain(new STString("xxx")); 139 q.descend("str").constraints().like(); 140 st.expectNone(q); 141 } 142 143 public void testIdentity() { 144 Query q = st.query(); 145 Constraint c = q.constrain(new STString("aaa")); 146 ObjectSet set = q.execute(); 147 STString identityConstraint = (STString) set.next(); 148 identityConstraint.str = "hihs"; 149 q = st.query(); 150 q.constrain(identityConstraint).identity(); 151 identityConstraint.str = "aaa"; 152 st.expectOne(q, new STString("aaa")); 153 } 154 155 public void testNotIdentity() { 156 Query q = st.query(); 157 Constraint c = q.constrain(new STString("aaa")); 158 ObjectSet set = q.execute(); 159 STString identityConstraint = (STString) set.next(); 160 identityConstraint.str = null; 161 q = st.query(); 162 q.constrain(identityConstraint).identity().not(); 163 identityConstraint.str = "aaa"; 164 st.expect( 165 q, 166 new Object [] { new STString(null), new STString("bbb"), new STString("dod")}); 167 } 168 169 public void testNull() { 170 Query q = st.query(); 171 Constraint c = q.constrain(new STString(null)); 172 q.descend("str").constrain(null); 173 st.expectOne(q, new STString(null)); 174 } 175 176 public void testNotNull() { 177 Query q = st.query(); 178 Constraint c = q.constrain(new STString(null)); 179 q.descend("str").constrain(null).not(); 180 st.expect( 181 q, 182 new Object [] { new STString("aaa"), new STString("bbb"), new STString("dod")}); 183 } 184 185 public void testConstraints() { 186 Query q = st.query(); 187 q.constrain(new STString("aaa")); 188 q.constrain(new STString("bbb")); 189 Constraints cs = q.constraints(); 190 Constraint[] csa = cs.toArray(); 191 if (csa.length != 2) { 192 st.error("Constraints not returned"); 193 } 194 } 195 196 public void testEvaluation() { 197 Query q = st.query(); 198 q.constrain(new STString(null)); 199 q.constrain(new Evaluation() { 200 public void evaluate(Candidate candidate) { 201 STString sts = (STString) candidate.getObject(); 202 candidate.include(sts.str.indexOf("od") == 1); 203 } 204 }); 205 st.expectOne(q, new STString("dod")); 206 } 207 208 public void testCaseInsenstiveContains() { 209 Query q = st.query(); 210 q.constrain(STString.class); 211 q.constrain(new Evaluation() { 212 public void evaluate(Candidate candidate) { 213 STString sts = (STString) candidate.getObject(); 214 candidate.include(sts.str.toLowerCase().indexOf("od") >= 0); 215 } 216 }); 217 st.expectOne(q, new STString("dod")); 218 } 219 220 } 221 | Popular Tags |