KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > jre12 > soda > deepOR > STOrContainsTestCase


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.jre12.soda.deepOR;
22 import java.util.*;
23
24 import com.db4o.query.*;
25
26
27 public class STOrContainsTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
28
29     String JavaDoc name;
30     ArrayList al1;
31     ArrayList al2;
32     
33     public STOrContainsTestCase() {
34     }
35     
36     public STOrContainsTestCase(String JavaDoc name, Object JavaDoc[] l1, Object JavaDoc[] l2) {
37         this.name = name;
38         al1 = new ArrayList();
39         if(l1 != null){
40             for (int i = 0; i < l1.length; i++) {
41                 al1.add(l1[i]);
42             }
43         }
44         al2 = new ArrayList();
45         if(l2 != null){
46             for (int i = 0; i < l2.length; i++) {
47                 al2.add(l2[i]);
48             }
49         }
50         
51     }
52
53     public Object JavaDoc[] createData() {
54         return new Object JavaDoc[] {
55             new STOrContainsTestCase("one", new Object JavaDoc[] {
56                 new Named("Marcus"),
57                 new Named("8"),
58                 new Named("Woohaa")
59             }, new Object JavaDoc[] {
60                 new Named("one"),
61                 new Named("two"),
62                 new Named("three")
63             }),
64             new STOrContainsTestCase("two", new Object JavaDoc[] {
65                 new Named("one"),
66                 new Named("two"),
67                 new Named("three")
68             }, new Object JavaDoc[] {
69                 new Named("Marcus"),
70                 new Named("8"),
71                 new Named("Woohaa")
72             }),
73             new STOrContainsTestCase("three", new Object JavaDoc[] {
74                 new Named("is"),
75                 new Named("this"),
76                 new Named("true")
77             }, new Object JavaDoc[] {
78                 new Named("no"),
79                 new Named("ho"),
80                 new Named("wo")
81             })
82             };
83     }
84
85     public void testNoneFound() {
86         Query q = newQuery();
87         q.constrain(STOrContainsTestCase.class);
88         Query name1 = q.descend("al1").descend("name");
89         Query name2 = q.descend("al2").descend("name");
90         name1.constrain("hugolo").or(name2.constrain("hugoli"));
91         
92         expect(q, new int[] {});
93     }
94     
95     public void testOneFound() {
96         Query q = newQuery();
97         q.constrain(STOrContainsTestCase.class);
98         Query name1 = q.descend("al1").descend("name");
99         Query name2 = q.descend("al2").descend("name");
100         name1.constrain("Woohaa").or(name2.constrain("Woohaa"));
101         
102         expect(q, new int[] { 0, 1 });
103     }
104     
105     public void testBothFound() {
106         Query q = newQuery();
107         q.constrain(STOrContainsTestCase.class);
108         Query name1 = q.descend("al1").descend("name");
109         Query name2 = q.descend("al2").descend("name");
110         name1.constrain("Marcus").or(name2.constrain("three"));
111         
112         expect(q, new int[] { 0});
113     }
114     
115     
116     public void testMoreOr1(){
117         Query q = newQuery();
118         q.constrain(STOrContainsTestCase.class);
119         Query name1 = q.descend("al1").descend("name");
120         Query name2 = q.descend("al2").descend("name");
121         name1.constrain("Marcus")
122         .or(name2.constrain("three"))
123         .or(q.descend("name").constrain("three"));
124         
125         expect(q, new int[] { 0, 2});
126     }
127     
128     public void testMoreOr2(){
129         Query q = newQuery();
130         q.constrain(STOrContainsTestCase.class);
131         Query name1 = q.descend("al1").descend("name");
132         Query name2 = q.descend("al2").descend("name");
133         name1.constrain("Marcus")
134         .or(name2.constrain("wo"))
135         .or(q.descend("name").constrain("three"));
136         
137         expect(q, new int[] { 0, 2});
138     }
139     
140     public static class Named{
141         String JavaDoc name;
142         
143         public Named(){
144         }
145         
146         public Named(String JavaDoc name){
147             this.name = name;
148         }
149     }
150
151 }
152
153
154
Popular Tags