KickJava   Java API By Example, From Geeks To Geeks.

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


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 STShortWUTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements Serializable{
29     
30     final static String JavaDoc DESCENDANT = "i_short";
31     
32     public Object JavaDoc i_short;
33     
34     public STShortWUTestCase(){
35     }
36     
37     private STShortWUTestCase(short a_short){
38         i_short = new Short JavaDoc(a_short);
39     }
40     
41     public Object JavaDoc[] createData() {
42         return new Object JavaDoc[]{
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         // Primitive default values are ignored, so we need an
55
// additional constraint:
56
q.descend(DESCENDANT).constrain(new Short JavaDoc((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 JavaDoc((short)9999);
124         q = newQuery();
125         q.constrain(identityConstraint).identity();
126         identityConstraint.i_short = new Short JavaDoc((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 JavaDoc((short)9080);
136         q = newQuery();
137         q.constrain(identityConstraint).identity().not();
138         identityConstraint.i_short = new Short JavaDoc((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 JavaDoc)sts.i_short).shortValue() + 2) > 100);
161             }
162         });
163         
164         expect(q, new int[] {2, 3});
165     }
166     
167 }
168
169
Popular Tags