KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > wrapper > untyped > STStringUTestCase


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.wrapper.untyped;
22 import com.db4o.*;
23 import com.db4o.query.*;
24
25
26 public class STStringUTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
27
28     public Object JavaDoc str;
29
30     public STStringUTestCase() {
31     }
32
33     public STStringUTestCase(String JavaDoc str) {
34         this.str = str;
35     }
36
37     public Object JavaDoc[] createData() {
38         return new Object JavaDoc[] {
39             new STStringUTestCase(null),
40             new STStringUTestCase("aaa"),
41             new STStringUTestCase("bbb"),
42             new STStringUTestCase("dod")};
43     }
44
45     public void testEquals() {
46         Query q = newQuery();
47         q.constrain(_array[2]);
48         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[2]);
49     }
50
51     public void testNotEquals() {
52         Query q = newQuery();
53         q.constrain(_array[2]);
54         q.descend("str").constraints().not();
55         
56         expect(q, new int[] { 0, 1, 3 });
57     }
58
59     public void testDescendantEquals() {
60         Query q = newQuery();
61         q.constrain(new STStringUTestCase());
62         q.descend("str").constrain("bbb");
63         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase("bbb"));
64     }
65
66     public void testContains() {
67         Query q = newQuery();
68         q.constrain(new STStringUTestCase("od"));
69         q.descend("str").constraints().contains();
70         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase("dod"));
71     }
72
73     public void testNotContains() {
74         Query q = newQuery();
75         q.constrain(new STStringUTestCase("od"));
76         q.descend("str").constraints().contains().not();
77         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(
78             q,
79             new Object JavaDoc[] { new STStringUTestCase(null), new STStringUTestCase("aaa"), new STStringUTestCase("bbb")});
80     }
81
82     public void testLike() {
83         Query q = newQuery();
84         q.constrain(new STStringUTestCase("do"));
85         q.descend("str").constraints().like();
86         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase("dod"));
87         q = newQuery();
88         q.constrain(new STStringUTestCase("od"));
89         q.descend("str").constraints().like();
90         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,_array[3]);
91     }
92
93     public void testNotLike() {
94         Query q = newQuery();
95         q.constrain(new STStringUTestCase("aaa"));
96         q.descend("str").constraints().like().not();
97         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(
98             q,
99             new Object JavaDoc[] { new STStringUTestCase(null), new STStringUTestCase("bbb"), new STStringUTestCase("dod")});
100         q = newQuery();
101         q.constrain(new STStringUTestCase("xxx"));
102         q.descend("str").constraints().like();
103         expect(q, new int[] {});
104     }
105
106     public void testIdentity() {
107         Query q = newQuery();
108         q.constrain(new STStringUTestCase("aaa"));
109         ObjectSet set = q.execute();
110         STStringUTestCase identityConstraint = (STStringUTestCase) set.next();
111         identityConstraint.str = "hihs";
112         q = newQuery();
113         q.constrain(identityConstraint).identity();
114         identityConstraint.str = "aaa";
115         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase("aaa"));
116     }
117
118     public void testNotIdentity() {
119         Query q = newQuery();
120         q.constrain(new STStringUTestCase("aaa"));
121         ObjectSet set = q.execute();
122         STStringUTestCase identityConstraint = (STStringUTestCase) set.next();
123         identityConstraint.str = null;
124         q = newQuery();
125         q.constrain(identityConstraint).identity().not();
126         identityConstraint.str = "aaa";
127         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(
128             q,
129             new Object JavaDoc[] { new STStringUTestCase(null), new STStringUTestCase("bbb"), new STStringUTestCase("dod")});
130     }
131
132     public void testNull() {
133         Query q = newQuery();
134         q.constrain(new STStringUTestCase(null));
135         q.descend("str").constrain(null);
136         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STStringUTestCase(null));
137     }
138
139     public void testNotNull() {
140         Query q = newQuery();
141         q.constrain(new STStringUTestCase(null));
142         q.descend("str").constrain(null).not();
143         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(
144             q,
145             new Object JavaDoc[] { new STStringUTestCase("aaa"), new STStringUTestCase("bbb"), new STStringUTestCase("dod")});
146     }
147
148     public void testConstraints() {
149         Query q = newQuery();
150         q.constrain(new STStringUTestCase("aaa"));
151         q.constrain(new STStringUTestCase("bbb"));
152         Constraints cs = q.constraints();
153         Constraint[] csa = cs.toArray();
154         if (csa.length != 2) {
155             db4ounit.Assert.fail("Constraints not returned");
156         }
157     }
158
159 }
160
Popular Tags