KickJava   Java API By Example, From Geeks To Geeks.

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


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