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