1 21 package com.db4o.test.legacy.soda.wrapper.typed; 22 23 import com.db4o.*; 24 import com.db4o.query.*; 25 import com.db4o.test.legacy.soda.*; 26 27 public class STShortWT implements STClass{ 28 29 final static String DESCENDANT = "i_short"; 30 31 public static transient SodaTest st; 32 33 Short i_short; 34 35 36 public STShortWT(){ 37 } 38 39 private STShortWT(short a_short){ 40 i_short = new Short (a_short); 41 } 42 43 public Object [] store() { 44 return new Object []{ 45 new STShortWT((short)0), 46 new STShortWT((short)1), 47 new STShortWT((short)99), 48 new STShortWT((short)909) 49 }; 50 } 51 52 public void testEquals(){ 53 Query q = st.query(); 54 q.constrain(new STShortWT((short)0)); 55 56 q.descend(DESCENDANT).constrain(new Short ((short)0)); 59 st.expectOne(q, store()[0]); 60 } 61 62 public void testNotEquals(){ 63 Query q = st.query(); 64 Object [] r = store(); 65 Constraint c = q.constrain(r[0]); 66 q.descend(DESCENDANT).constraints().not(); 67 st.expect(q, new Object [] {r[1], r[2], r[3]}); 68 } 69 70 public void testGreater(){ 71 Query q = st.query(); 72 Constraint c = q.constrain(new STShortWT((short)9)); 73 q.descend(DESCENDANT).constraints().greater(); 74 Object [] r = store(); 75 st.expect(q, new Object [] {r[2], r[3]}); 76 } 77 78 public void testSmaller(){ 79 Query q = st.query(); 80 Constraint c = q.constrain(new STShortWT((short)1)); 81 q.descend(DESCENDANT).constraints().smaller(); 82 st.expectOne(q, store()[0]); 83 } 84 85 public void testContains(){ 86 Query q = st.query(); 87 Constraint c = q.constrain(new STShortWT((short)9)); 88 q.descend(DESCENDANT).constraints().contains(); 89 Object [] r = store(); 90 st.expect(q, new Object [] {r[2], r[3]}); 91 } 92 93 public void testNotContains(){ 94 Query q = st.query(); 95 Constraint c = q.constrain(new STShortWT((short)0)); 96 q.descend(DESCENDANT).constraints().contains().not(); 97 Object [] r = store(); 98 st.expect(q, new Object [] {r[1], r[2]}); 99 } 100 101 public void testLike(){ 102 Query q = st.query(); 103 Constraint c = q.constrain(new STShortWT((short)90)); 104 q.descend(DESCENDANT).constraints().like(); 105 st.expectOne(q, store()[3]); 106 q = st.query(); 107 c = q.constrain(new STShortWT((short)10)); 108 q.descend(DESCENDANT).constraints().like(); 109 st.expectNone(q); 110 } 111 112 public void testNotLike(){ 113 Query q = st.query(); 114 Constraint c = q.constrain(new STShortWT((short)1)); 115 q.descend(DESCENDANT).constraints().like().not(); 116 Object [] r = store(); 117 st.expect(q, new Object [] {r[0], r[2], r[3]}); 118 } 119 120 public void testIdentity(){ 121 Query q = st.query(); 122 Constraint c = q.constrain(new STShortWT((short)1)); 123 ObjectSet set = q.execute(); 124 STShortWT identityConstraint = (STShortWT)set.next(); 125 identityConstraint.i_short = new Short ((short)9999); 126 q = st.query(); 127 q.constrain(identityConstraint).identity(); 128 identityConstraint.i_short = new Short ((short)1); 129 st.expectOne(q,store()[1]); 130 } 131 132 public void testNotIdentity(){ 133 Query q = st.query(); 134 Constraint c = q.constrain(new STShortWT((short)1)); 135 ObjectSet set = q.execute(); 136 STShortWT identityConstraint = (STShortWT)set.next(); 137 identityConstraint.i_short = new Short ((short)9080); 138 q = st.query(); 139 q.constrain(identityConstraint).identity().not(); 140 identityConstraint.i_short = new Short ((short)1); 141 Object [] r = store(); 142 st.expect(q, new Object [] {r[0], r[2], r[3]}); 143 } 144 145 public void testConstraints(){ 146 Query q = st.query(); 147 q.constrain(new STShortWT((short)1)); 148 q.constrain(new STShortWT((short)0)); 149 Constraints cs = q.constraints(); 150 Constraint[] csa = cs.toArray(); 151 if(csa.length != 2){ 152 st.error("Constraints not returned"); 153 } 154 } 155 156 public void testEvaluation(){ 157 Query q = st.query(); 158 q.constrain(new STShortWT()); 159 q.constrain(new Evaluation() { 160 public void evaluate(Candidate candidate) { 161 STShortWT sts = (STShortWT)candidate.getObject(); 162 candidate.include((sts.i_short.shortValue() + 2) > 100); 163 } 164 }); 165 Object [] r = store(); 166 st.expect(q, new Object [] {r[2], r[3]}); 167 } 168 169 } 170 171 | Popular Tags |