KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > classes > untypedhierarchy > STUH1TestCase


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.untypedhierarchy;
22 import com.db4o.db4ounit.common.soda.classes.typedhierarchy.*;
23 import com.db4o.query.*;
24
25
26
27
28 /** UH: Untyped Hierarchy */
29 public class STUH1TestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
30
31     public Object JavaDoc h2;
32     public Object JavaDoc foo1;
33
34     public STUH1TestCase() {
35     }
36
37     public STUH1TestCase(STUH2 a2) {
38         h2 = a2;
39     }
40
41     public STUH1TestCase(String JavaDoc str) {
42         foo1 = str;
43     }
44
45     public STUH1TestCase(STUH2 a2, String JavaDoc str) {
46         h2 = a2;
47         foo1 = str;
48     }
49
50     public Object JavaDoc[] createData() {
51         return new Object JavaDoc[] {
52             new STUH1TestCase(),
53             new STUH1TestCase("str1"),
54             new STUH1TestCase(new STUH2()),
55             new STUH1TestCase(new STUH2("str2")),
56             new STUH1TestCase(new STUH2(new STUH3("str3"))),
57             new STUH1TestCase(new STUH2(new STUH3("str3"), "str2")),
58             };
59     }
60
61     public void testStrNull() {
62         Query q = newQuery();
63         q.constrain(new STUH1TestCase());
64         q.descend("foo1").constrain(null);
65         
66         expect(q, new int[] { 0, 2, 3, 4, 5 });
67     }
68
69     public void testBothNull() {
70         Query q = newQuery();
71         q.constrain(new STUH1TestCase());
72         q.descend("foo1").constrain(null);
73         q.descend("h2").constrain(null);
74         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[0]);
75     }
76
77     public void testDescendantNotNull() {
78         Query q = newQuery();
79         
80         q.constrain(new STUH1TestCase());
81         q.descend("h2").constrain(null).not();
82         expect(q, new int[] { 2, 3, 4, 5 });
83     }
84
85     public void testDescendantDescendantNotNull() {
86         Query q = newQuery();
87         
88         q.constrain(new STUH1TestCase());
89         q.descend("h2").descend("h3").constrain(null).not();
90         expect(q, new int[] { 4, 5 });
91     }
92
93     public void testDescendantExists() {
94         Query q = newQuery();
95         
96         q.constrain(_array[2]);
97         expect(q, new int[] { 2, 3, 4, 5 });
98     }
99
100     public void testDescendantValue() {
101         Query q = newQuery();
102         
103         q.constrain(_array[3]);
104         expect(q, new int[] { 3, 5 });
105     }
106
107     public void testDescendantDescendantExists() {
108         Query q = newQuery();
109         
110         q.constrain(new STUH1TestCase(new STUH2(new STUH3())));
111         expect(q, new int[] { 4, 5 });
112     }
113
114     public void testDescendantDescendantValue() {
115         Query q = newQuery();
116         
117         q.constrain(new STUH1TestCase(new STUH2(new STUH3("str3"))));
118         expect(q, new int[] { 4, 5 });
119     }
120
121     public void testDescendantDescendantStringPath() {
122         Query q = newQuery();
123         
124         q.constrain(new STUH1TestCase());
125         q.descend("h2").descend("h3").descend("foo3").constrain("str3");
126         expect(q, new int[] { 4, 5 });
127     }
128
129     public void testSequentialAddition() {
130         Query q = newQuery();
131         q.constrain(new STUH1TestCase());
132         
133         Query cur = q.descend("h2");
134         cur.constrain(new STUH2());
135         cur.descend("foo2").constrain("str2");
136         cur = cur.descend("h3");
137         cur.constrain(new STUH3());
138         cur.descend("foo3").constrain("str3");
139         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[5]);
140     }
141
142     public void testTwoLevelOr() {
143         Query q = newQuery();
144         
145         q.constrain(new STUH1TestCase("str1"));
146         q.descend("foo1").constraints().or(
147             q.descend("h2").descend("h3").descend("foo3").constrain("str3"));
148         expect(q, new int[] { 1, 4, 5 });
149     }
150
151     public void testThreeLevelOr() {
152         Query q = newQuery();
153         
154         q.constrain(new STUH1TestCase("str1"));
155         q.descend("foo1").constraints().or(
156             q.descend("h2").descend("foo2").constrain("str2")).or(
157             q.descend("h2").descend("h3").descend("foo3").constrain("str3"));
158
159         expect(q, new int[] { 1, 3, 4, 5 });
160     }
161
162     public void testNonExistentDescendant() {
163         Query q = newQuery();
164         STUH1TestCase constraint = new STUH1TestCase();
165         constraint.foo1 = new STETH2();
166         q.constrain(constraint);
167         expect(q, new int[] {});
168     }
169
170 }
171
Popular Tags