KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > joins > typed > STOrTTestCase


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