KickJava   Java API By Example, From Geeks To Geeks.

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


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 STByteWUTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements Serializable{
29     
30     final static String JavaDoc DESCENDANT = "i_byte";
31     
32     public Object JavaDoc i_byte;
33     
34     public STByteWUTestCase(){
35     }
36     
37     private STByteWUTestCase(byte a_byte){
38         i_byte = new Byte JavaDoc(a_byte);
39     }
40     
41     public Object JavaDoc[] createData() {
42         return new Object JavaDoc[]{
43             new STByteWUTestCase((byte)0),
44             new STByteWUTestCase((byte)1),
45             new STByteWUTestCase((byte)99),
46             new STByteWUTestCase((byte)113),
47         };
48     }
49     
50     public void testEquals(){
51         Query q = newQuery();
52         q.constrain(new STByteWUTestCase((byte)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(DESCENDANT).constraints().not();
61         expect(q, new int[] {1, 2, 3});
62     }
63     
64     public void testGreater(){
65         Query q = newQuery();
66         q.constrain(new STByteWUTestCase((byte)9));
67         q.descend(DESCENDANT).constraints().greater();
68         
69         expect(q, new int[] {2, 3});
70     }
71     
72     public void testSmaller(){
73         Query q = newQuery();
74         q.constrain(new STByteWUTestCase((byte)1));
75         q.descend(DESCENDANT).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 STByteWUTestCase((byte)9));
82         q.descend(DESCENDANT).constraints().contains();
83         
84         expect(q, new int[] {2});
85     }
86     
87     public void testNotContains(){
88         Query q = newQuery();
89         q.constrain(new STByteWUTestCase((byte)0));
90         q.descend(DESCENDANT).constraints().contains().not();
91         
92         expect(q, new int[] {1, 2, 3});
93     }
94     
95     public void testLike(){
96         Query q = newQuery();
97         q.constrain(new STByteWUTestCase((byte)11));
98         q.descend(DESCENDANT).constraints().like();
99         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STByteWUTestCase((byte)113));
100         q = newQuery();
101         q.constrain(new STByteWUTestCase((byte)10));
102         q.descend(DESCENDANT).constraints().like();
103         expect(q, new int[] {});
104     }
105     
106     public void testNotLike(){
107         Query q = newQuery();
108         q.constrain(new STByteWUTestCase((byte)1));
109         q.descend(DESCENDANT).constraints().like().not();
110         
111         expect(q, new int[] {0, 2});
112     }
113     
114     public void testIdentity(){
115         Query q = newQuery();
116         q.constrain(new STByteWUTestCase((byte)1));
117         ObjectSet set = q.execute();
118         STByteWUTestCase identityConstraint = (STByteWUTestCase)set.next();
119         identityConstraint.i_byte = new Byte JavaDoc((byte)102);
120         q = newQuery();
121         q.constrain(identityConstraint).identity();
122         identityConstraint.i_byte = new Byte JavaDoc((byte)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 STByteWUTestCase((byte)1));
129         ObjectSet set = q.execute();
130         STByteWUTestCase identityConstraint = (STByteWUTestCase)set.next();
131         identityConstraint.i_byte = new Byte JavaDoc((byte)102);
132         q = newQuery();
133         q.constrain(identityConstraint).identity().not();
134         identityConstraint.i_byte = new Byte JavaDoc((byte)1);
135         
136         expect(q, new int[] {0, 2, 3});
137     }
138     
139     public void testConstraints(){
140         Query q = newQuery();
141         q.constrain(new STByteWUTestCase((byte)1));
142         q.constrain(new STByteWUTestCase((byte)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     public void testNull(){
151         
152     }
153     
154     public void testEvaluation(){
155         Query q = newQuery();
156         q.constrain(new STByteWUTestCase());
157         q.constrain(new Evaluation() {
158             public void evaluate(Candidate candidate) {
159                 STByteWUTestCase sts = (STByteWUTestCase)candidate.getObject();
160                 candidate.include((((Byte JavaDoc)sts.i_byte).byteValue() + 2) > 100);
161             }
162         });
163         
164         expect(q, new int[] {2, 3});
165     }
166     
167 }
168
169
Popular Tags