KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > classes > simple > STStringTestCase


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.simple;
22 import com.db4o.*;
23 import com.db4o.db4ounit.common.soda.*;
24 import com.db4o.query.*;
25
26
27
28
29 public class STStringTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements STInterface {
30     
31     public String JavaDoc str;
32
33     public STStringTestCase() {
34     }
35
36     public STStringTestCase(String JavaDoc str) {
37         this.str = str;
38     }
39
40     /** needed for STInterface test */
41     public Object JavaDoc returnSomething() {
42         return str;
43     }
44
45     public Object JavaDoc[] createData() {
46         return new Object JavaDoc[] {
47             new STStringTestCase(null),
48             new STStringTestCase("aaa"),
49             new STStringTestCase("bbb"),
50             new STStringTestCase("dod")};
51     }
52     
53     public void testEquals() {
54         Query q = newQuery();
55         q.constrain(_array[2]);
56         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[2]);
57     }
58
59     public void testNotEquals() {
60         Query q = newQuery();
61         q.constrain(_array[2]);
62         q.descend("str").constraints().not();
63         
64         expect(q, new int[] { 0, 1, 3 });
65     }
66
67     public void testDescendantEquals() {
68         Query q = newQuery();
69         q.constrain(new STStringTestCase());
70         q.descend("str").constrain("bbb");
71         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase("bbb"));
72     }
73
74     public void testContains() {
75         Query q = newQuery();
76         q.constrain(new STStringTestCase("od"));
77         q.descend("str").constraints().contains();
78         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase("dod"));
79     }
80
81     public void testNotContains() {
82         Query q = newQuery();
83         q.constrain(new STStringTestCase("od"));
84         q.descend("str").constraints().contains().not();
85         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(
86             q,
87             new Object JavaDoc[] { new STStringTestCase(null), new STStringTestCase("aaa"), new STStringTestCase("bbb")});
88     }
89
90     public void testLike() {
91         Query q = newQuery();
92         q.constrain(new STStringTestCase("do"));
93         q.descend("str").constraints().like();
94         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase("dod"));
95         q = newQuery();
96         q.constrain(new STStringTestCase("od"));
97         q.descend("str").constraints().like();
98         
99         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,_array[3]);
100     }
101
102     public void testStartsWith() {
103         Query q = newQuery();
104         q.constrain(new STStringTestCase("do"));
105         q.descend("str").constraints().startsWith(true);
106         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase("dod"));
107         q = newQuery();
108         q.constrain(new STStringTestCase("od"));
109         q.descend("str").constraints().startsWith(true);
110         expect(q, new int[] {});
111     }
112
113     public void testEndsWith() {
114         Query q = newQuery();
115         q.constrain(new STStringTestCase("do"));
116         q.descend("str").constraints().endsWith(true);
117         expect(q, new int[] {});
118         q = newQuery();
119         q.constrain(new STStringTestCase("od"));
120         q.descend("str").constraints().endsWith(true);
121         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase("dod"));
122         q = newQuery();
123         q.constrain(new STStringTestCase("D"));
124         q.descend("str").constraints().endsWith(false);
125         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase("dod"));
126     }
127
128     public void testNotLike() {
129         Query q = newQuery();
130         q.constrain(new STStringTestCase("aaa"));
131         q.descend("str").constraints().like().not();
132         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(
133             q,
134             new Object JavaDoc[] { new STStringTestCase(null), new STStringTestCase("bbb"), new STStringTestCase("dod")});
135         q = newQuery();
136         q.constrain(new STStringTestCase("xxx"));
137         q.descend("str").constraints().like();
138         expect(q, new int[] {});
139     }
140
141     public void testIdentity() {
142         Query q = newQuery();
143         q.constrain(new STStringTestCase("aaa"));
144         ObjectSet set = q.execute();
145         STStringTestCase identityConstraint = (STStringTestCase) set.next();
146         identityConstraint.str = "hihs";
147         q = newQuery();
148         q.constrain(identityConstraint).identity();
149         identityConstraint.str = "aaa";
150         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase("aaa"));
151     }
152
153     public void testNotIdentity() {
154         Query q = newQuery();
155         q.constrain(new STStringTestCase("aaa"));
156         ObjectSet set = q.execute();
157         STStringTestCase identityConstraint = (STStringTestCase) set.next();
158         identityConstraint.str = null;
159         q = newQuery();
160         q.constrain(identityConstraint).identity().not();
161         identityConstraint.str = "aaa";
162         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(
163             q,
164             new Object JavaDoc[] { new STStringTestCase(null), new STStringTestCase("bbb"), new STStringTestCase("dod")});
165     }
166
167     public void testNull() {
168         Query q = newQuery();
169         q.constrain(new STStringTestCase(null));
170         q.descend("str").constrain(null);
171         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase(null));
172     }
173
174     public void testNotNull() {
175         Query q = newQuery();
176         q.constrain(new STStringTestCase(null));
177         q.descend("str").constrain(null).not();
178         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(
179             q,
180             new Object JavaDoc[] { new STStringTestCase("aaa"), new STStringTestCase("bbb"), new STStringTestCase("dod")});
181     }
182
183     public void testConstraints() {
184         Query q = newQuery();
185         q.constrain(new STStringTestCase("aaa"));
186         q.constrain(new STStringTestCase("bbb"));
187         Constraints cs = q.constraints();
188         Constraint[] csa = cs.toArray();
189         if (csa.length != 2) {
190             db4ounit.Assert.fail("Constraints not returned");
191         }
192     }
193
194     public void testEvaluation() {
195         Query q = newQuery();
196         q.constrain(new STStringTestCase(null));
197         q.constrain(new Evaluation() {
198             public void evaluate(Candidate candidate) {
199                 STStringTestCase sts = (STStringTestCase) candidate.getObject();
200                 candidate.include(sts.str.indexOf("od") == 1);
201             }
202         });
203         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase("dod"));
204     }
205     
206     public void testCaseInsenstiveContains() {
207         Query q = newQuery();
208         q.constrain(STStringTestCase.class);
209         q.constrain(new Evaluation() {
210             public void evaluate(Candidate candidate) {
211                 STStringTestCase sts = (STStringTestCase) candidate.getObject();
212                 candidate.include(sts.str.toLowerCase().indexOf("od") >= 0);
213             }
214         });
215         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringTestCase("dod"));
216     }
217
218 }
219
Popular Tags