KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > wrapper > untyped > STStringU


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