KickJava   Java API By Example, From Geeks To Geeks.

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


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