| 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 27 public class STInteger implements STClass1{ 28 29 public static transient SodaTest st; 30 31 public int i_int; 32 33 public STInteger(){ 34 } 35 36 private STInteger(int a_int){ 37 i_int = a_int; 38 } 39 40 public Object [] store() { 41 return new Object []{ 42 new STInteger(0), 43 new STInteger(1), 44 new STInteger(99), 45 new STInteger(909) 46 }; 47 } 48 49 public void testEquals(){ 50 Query q = st.query(); 51 q.constrain(new STInteger(0)); 52 53 q.descend("i_int").constrain(new Integer (0)); 56 st.expectOne(q, store()[0]); 57 } 58 59 public void testNotEquals(){ 60 Query q = st.query(); 61 Object [] r = store(); 62 Constraint c = q.constrain(r[0]); 63 q.descend("i_int").constrain(new Integer (0)).not(); 64 st.expect(q, new Object [] {r[1], r[2], r[3]}); 65 } 66 67 public void testGreater(){ 68 Query q = st.query(); 69 Constraint c = q.constrain(new STInteger(9)); 70 q.descend("i_int").constraints().greater(); 71 Object [] r = store(); 72 st.expect(q, new Object [] {r[2], r[3]}); 73 } 74 75 public void testSmaller(){ 76 Query q = st.query(); 77 Constraint c = q.constrain(new STInteger(1)); 78 q.descend("i_int").constraints().smaller(); 79 st.expectOne(q, store()[0]); 80 } 81 82 public void testContains(){ 83 Query q = st.query(); 84 Constraint c = q.constrain(new STInteger(9)); 85 q.descend("i_int").constraints().contains(); 86 Object [] r = store(); 87 st.expect(q, new Object [] {r[2], r[3]}); 88 } 89 90 public void testNotContains(){ 91 Query q = st.query(); 92 Constraint c = q.constrain(new STInteger(0)); 93 q.descend("i_int").constrain(new Integer (0)).contains().not(); 94 Object [] r = store(); 95 st.expect(q, new Object [] {r[1], r[2]}); 96 } 97 98 public void testLike(){ 99 Query q = st.query(); 100 Constraint c = q.constrain(new STInteger(90)); 101 q.descend("i_int").constraints().like(); 102 st.expectOne(q, new STInteger(909)); 103 q = st.query(); 104 c = q.constrain(new STInteger(10)); 105 q.descend("i_int").constraints().like(); 106 st.expectNone(q); 107 } 108 109 public void testNotLike(){ 110 Query q = st.query(); 111 Constraint c = q.constrain(new STInteger(1)); 112 q.descend("i_int").constraints().like().not(); 113 Object [] r = store(); 114 st.expect(q, new Object [] {r[0], r[2], r[3]}); 115 } 116 117 public void testIdentity(){ 118 Query q = st.query(); 119 Constraint c = q.constrain(new STInteger(1)); 120 ObjectSet set = q.execute(); 121 STInteger identityConstraint = (STInteger)set.next(); 122 identityConstraint.i_int = 9999; 123 q = st.query(); 124 q.constrain(identityConstraint).identity(); 125 identityConstraint.i_int = 1; 126 st.expectOne(q,store()[1]); 127 } 128 129 public void testNotIdentity(){ 130 Query q = st.query(); 131 Constraint c = q.constrain(new STInteger(1)); 132 ObjectSet set = q.execute(); 133 STInteger identityConstraint = (STInteger)set.next(); 134 identityConstraint.i_int = 9080; 135 q = st.query(); 136 q.constrain(identityConstraint).identity().not(); 137 identityConstraint.i_int = 1; 138 Object [] r = store(); 139 st.expect(q, new Object [] {r[0], r[2], r[3]}); 140 } 141 142 public void testConstraints(){ 143 Query q = st.query(); 144 q.constrain(new STInteger(1)); 145 q.constrain(new STInteger(0)); 146 Constraints cs = q.constraints(); 147 Constraint[] csa = cs.toArray(); 148 if(csa.length != 2){ 149 st.error("Constraints not returned"); 150 } 151 } 152 153 } 154 155 | Popular Tags |