KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > wrapper > untyped > STIntegerWUTestCase


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

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 STIntegerWUTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements Serializable{
29     
30     public Object JavaDoc i_int;
31     
32     public STIntegerWUTestCase(){
33     }
34     
35     private STIntegerWUTestCase(int a_int){
36         i_int = new Integer JavaDoc(a_int);
37     }
38     
39     public Object JavaDoc[] createData() {
40         return new Object JavaDoc[]{
41             new STIntegerWUTestCase(0),
42             new STIntegerWUTestCase(1),
43             new STIntegerWUTestCase(99),
44             new STIntegerWUTestCase(909)
45         };
46     }
47     
48     public void testEquals(){
49         Query q = newQuery();
50         q.constrain(new STIntegerWUTestCase(0));
51         
52         // Primitive default values are ignored, so we need an
53
// additional constraint:
54
q.descend("i_int").constrain(new Integer JavaDoc(0));
55         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[0]);
56     }
57     
58     public void testNotEquals(){
59         Query q = newQuery();
60         
61         q.constrain(new STIntegerWUTestCase());
62         q.descend("i_int").constrain(new Integer JavaDoc(0)).not();
63         expect(q, new int[] {1, 2, 3});
64     }
65     
66     public void testGreater(){
67         Query q = newQuery();
68         q.constrain(new STIntegerWUTestCase(9));
69         q.descend("i_int").constraints().greater();
70         
71         expect(q, new int[] {2, 3});
72     }
73     
74     public void testSmaller(){
75         Query q = newQuery();
76         q.constrain(new STIntegerWUTestCase(1));
77         q.descend("i_int").constraints().smaller();
78         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[0]);
79     }
80     
81     public void testContains(){
82         Query q = newQuery();
83         q.constrain(new STIntegerWUTestCase(9));
84         q.descend("i_int").constraints().contains();
85         
86         expect(q, new int[] {2, 3});
87     }
88     
89     public void testNotContains(){
90         Query q = newQuery();
91         q.constrain(new STIntegerWUTestCase());
92         q.descend("i_int").constrain(new Integer JavaDoc(0)).contains().not();
93         
94         expect(q, new int[] {1, 2});
95     }
96     
97     public void testLike(){
98         Query q = newQuery();
99         q.constrain(new STIntegerWUTestCase(90));
100         q.descend("i_int").constraints().like();
101         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STIntegerWUTestCase(909));
102         q = newQuery();
103         q.constrain(new STIntegerWUTestCase(10));
104         q.descend("i_int").constraints().like();
105         expect(q, new int[] {});
106     }
107     
108     public void testNotLike(){
109         Query q = newQuery();
110         q.constrain(new STIntegerWUTestCase(1));
111         q.descend("i_int").constraints().like().not();
112         
113         expect(q, new int[] {0, 2, 3});
114     }
115     
116     public void testIdentity(){
117         Query q = newQuery();
118         q.constrain(new STIntegerWUTestCase(1));
119         ObjectSet set = q.execute();
120         STIntegerWUTestCase identityConstraint = (STIntegerWUTestCase)set.next();
121         identityConstraint.i_int = new Integer JavaDoc(9999);
122         q = newQuery();
123         q.constrain(identityConstraint).identity();
124         identityConstraint.i_int = new Integer JavaDoc(1);
125         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,_array[1]);
126     }
127     
128     public void testNotIdentity(){
129         Query q = newQuery();
130         q.constrain(new STIntegerWUTestCase(1));
131         ObjectSet set = q.execute();
132         STIntegerWUTestCase identityConstraint = (STIntegerWUTestCase)set.next();
133         identityConstraint.i_int = new Integer JavaDoc(9080);
134         q = newQuery();
135         q.constrain(identityConstraint).identity().not();
136         identityConstraint.i_int = new Integer JavaDoc(1);
137         
138         expect(q, new int[] {0, 2, 3});
139     }
140     
141     public void testConstraints(){
142         Query q = newQuery();
143         q.constrain(new STIntegerWUTestCase(1));
144         q.constrain(new STIntegerWUTestCase(0));
145         Constraints cs = q.constraints();
146         Constraint[] csa = cs.toArray();
147         if(csa.length != 2){
148             db4ounit.Assert.fail("Constraints not returned");
149         }
150     }
151     
152     public void testEvaluation(){
153         Query q = newQuery();
154         q.constrain(new STIntegerWUTestCase());
155         q.constrain(new Evaluation() {
156             public void evaluate(Candidate candidate) {
157                 STIntegerWUTestCase sti = (STIntegerWUTestCase)candidate.getObject();
158                 candidate.include((((Integer JavaDoc)sti.i_int).intValue() + 2) > 100);
159             }
160         });
161         
162         expect(q, new int[] {2, 3});
163     }
164     
165 }
166
167
Popular Tags