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