KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > joins > untyped > STOrUTestCase


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.joins.untyped;
22 import com.db4o.query.*;
23
24
25 public class STOrUTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
26
27     public Object JavaDoc orInt;
28     public Object JavaDoc orString;
29
30     public STOrUTestCase() {
31     }
32
33     private STOrUTestCase(int a_int, String JavaDoc a_string) {
34         orInt = new Integer JavaDoc(a_int);
35         orString = a_string;
36     }
37     
38     private STOrUTestCase(Object JavaDoc a_int, String JavaDoc a_string) {
39         orInt = a_int;
40         orString = a_string;
41     }
42     
43
44     public String JavaDoc toString() {
45         return "STOr: int:" + orInt + " str:" + orString;
46     }
47
48     public Object JavaDoc[] createData() {
49         return new Object JavaDoc[] {
50             new STOrUTestCase(0, "hi"),
51             new STOrUTestCase(5, null),
52             new STOrUTestCase(1000, "joho"),
53             new STOrUTestCase(30000, "osoo"),
54             new STOrUTestCase(Integer.MAX_VALUE - 1, null),
55             };
56     }
57     
58     
59     public void testSmallerGreater() {
60         Query q = newQuery();
61         q.constrain(new STOrUTestCase());
62         Query sub = q.descend("orInt");
63         sub.constrain(new Integer JavaDoc(30000)).greater().or(
64             sub.constrain(new Integer JavaDoc(5)).smaller());
65         
66         expect(q, new int[] { 0, 4 });
67     }
68
69     public void testGreaterGreater() {
70         Query q = newQuery();
71         q.constrain(new STOrUTestCase());
72         Query sub = q.descend("orInt");
73         sub.constrain(new Integer JavaDoc(30000)).greater().or(
74             sub.constrain(new Integer JavaDoc(5)).greater());
75         
76         expect(q, new int[] { 2, 3, 4 });
77     }
78
79     public void testGreaterEquals() {
80         Query q = newQuery();
81         q.constrain(new STOrUTestCase());
82         Query sub = q.descend("orInt");
83         sub.constrain(new Integer JavaDoc(1000)).greater().or(
84             sub.constrain(new Integer JavaDoc(0)));
85         
86         expect(q, new int[] { 0, 3, 4 });
87     }
88
89     public void testEqualsNull() {
90         Query q = newQuery();
91         q.constrain(new STOrUTestCase(1000, null));
92         q.descend("orInt").constraints().or(
93             q.descend("orString").constrain(null));
94         
95         expect(q, new int[] { 1, 2, 4 });
96     }
97
98
99     public void testAndOrAnd() {
100         Query q = newQuery();
101         q.constrain(new STOrUTestCase(null, null));
102         (
103             q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
104             q.descend("orString").constrain(null))
105         ).or(
106             q.descend("orInt").constrain(new Integer JavaDoc(1000)).and(
107             q.descend("orString").constrain("joho"))
108         );
109         
110         expect(q, new int[] { 1, 2});
111     }
112     
113     public void testOrAndOr() {
114         Query q = newQuery();
115         q.constrain(new STOrUTestCase(null, null));
116         (
117             q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
118             q.descend("orString").constrain(null))
119         ).and(
120             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
121             q.descend("orString").constrain("joho"))
122         );
123         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[4]);
124     }
125     
126     public void testOrOrAnd() {
127         Query q = newQuery();
128         q.constrain(new STOrUTestCase());
129         (
130             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
131             q.descend("orString").constrain("joho"))
132         ).or(
133             q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
134             q.descend("orString").constrain(null))
135         );
136         
137         expect(q, new int[] { 1, 2, 4});
138     }
139     
140     public void testMultiOrAnd(){
141         Query q = newQuery();
142         q.constrain(new STOrUTestCase());
143         (
144             (
145                 q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
146                 q.descend("orString").constrain("joho"))
147             ).or(
148                 q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
149                 q.descend("orString").constrain("joho"))
150             )
151         ).or(
152             (
153                 q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
154                 q.descend("orString").constrain(null))
155             ).and(
156                 q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
157                 q.descend("orString").constrain(null))
158             )
159         );
160         
161         expect(q, new int[] {1, 2, 4});
162     }
163     
164     public void testNotSmallerGreater() {
165         Query q = newQuery();
166         q.constrain(new STOrUTestCase());
167         Query sub = q.descend("orInt");
168         (sub.constrain(new Integer JavaDoc(30000)).greater().or(
169             sub.constrain(new Integer JavaDoc(5)).smaller())).not();
170         
171         expect(q, new int[] { 1, 2, 3 });
172     }
173
174     public void testNotGreaterGreater() {
175         Query q = newQuery();
176         q.constrain(new STOrUTestCase());
177         Query sub = q.descend("orInt");
178         (sub.constrain(new Integer JavaDoc(30000)).greater().or(
179             sub.constrain(new Integer JavaDoc(5)).greater())).not();
180         
181         expect(q, new int[] { 0, 1});
182     }
183
184     public void testNotGreaterEquals() {
185         Query q = newQuery();
186         q.constrain(new STOrUTestCase());
187         Query sub = q.descend("orInt");
188         (sub.constrain(new Integer JavaDoc(1000)).greater().or(
189             sub.constrain(new Integer JavaDoc(0)))).not();
190         
191         expect(q, new int[] { 1, 2});
192     }
193
194     public void testNotEqualsNull() {
195         Query q = newQuery();
196         q.constrain(new STOrUTestCase(1000, null));
197         (q.descend("orInt").constraints().or(
198             q.descend("orString").constrain(null))).not();
199         
200         expect(q, new int[] { 0, 3});
201     }
202
203     public void testNotAndOrAnd() {
204         Query q = newQuery();
205         q.constrain(new STOrUTestCase());
206         (
207             q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
208             q.descend("orString").constrain(null))
209         ).or(
210             q.descend("orInt").constrain(new Integer JavaDoc(1000)).and(
211             q.descend("orString").constrain("joho"))
212         ).not();
213         
214         expect(q, new int[] { 0, 3, 4});
215     }
216     
217     public void testNotOrAndOr() {
218         Query q = newQuery();
219         q.constrain(new STOrUTestCase());
220         (
221             q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
222             q.descend("orString").constrain(null))
223         ).and(
224             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
225             q.descend("orString").constrain("joho"))
226         ).not();
227         
228         expect(q, new int[] { 0, 1, 2, 3});
229     }
230     
231     public void testNotOrOrAnd() {
232         Query q = newQuery();
233         q.constrain(new STOrUTestCase());
234         (
235             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
236             q.descend("orString").constrain("joho"))
237         ).or(
238             q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
239             q.descend("orString").constrain(null))
240         ).not();
241         
242         expect(q, new int[] { 0, 3});
243     }
244     
245     public void testNotMultiOrAnd(){
246         Query q = newQuery();
247         q.constrain(new STOrUTestCase());
248         (
249             (
250                 q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
251                 q.descend("orString").constrain("joho"))
252             ).or(
253                 q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
254                 q.descend("orString").constrain("joho"))
255             )
256         ).or(
257             (
258                 q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
259                 q.descend("orString").constrain(null))
260             ).and(
261                 q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
262                 q.descend("orString").constrain(null))
263             )
264         ).not();
265         
266         expect(q, new int[] {0, 3});
267     }
268     
269     public void testOrNotAndOr() {
270         Query q = newQuery();
271         q.constrain(new STOrUTestCase());
272         (
273             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
274             q.descend("orString").constrain("joho"))
275         ).not().and(
276             q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
277             q.descend("orString").constrain(null))
278         );
279         
280         expect(q, new int[] { 1});
281     }
282     
283     public void testAndNotAndAnd() {
284         Query q = newQuery();
285         q.constrain(new STOrUTestCase());
286         (
287             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).and(
288             q.descend("orString").constrain(null))
289         ).not().and(
290             q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
291             q.descend("orString").constrain("osoo"))
292         );
293         
294         expect(q, new int[] { 1, 3});
295     }
296     
297 }
298
Popular Tags