KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > classes > typedhierarchy > STTH1TestCase


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