KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > classes > simple > STIntegerTestCase


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.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 JavaDoc[] createData() {
38         return new Object JavaDoc[]{
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         // Primitive default values are ignored, so we need an
51
// additional constraint:
52
q.descend("i_int").constrain(new Integer JavaDoc(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 JavaDoc(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 JavaDoc(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