001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test.legacy.soda.wrapper.untyped;
022:
023: import com.db4o.*;
024: import com.db4o.query.*;
025: import com.db4o.test.legacy.soda.*;
026:
027: public class STStringU implements STClass1 {
028:
029: public static transient SodaTest st;
030:
031: public Object str;
032:
033: public STStringU() {
034: }
035:
036: public STStringU(String str) {
037: this .str = str;
038: }
039:
040: public Object[] store() {
041: return new Object[] { new STStringU(null),
042: new STStringU("aaa"), new STStringU("bbb"),
043: new STStringU("dod") };
044: }
045:
046: public void testEquals() {
047: Query q = st.query();
048: q.constrain(store()[2]);
049: st.expectOne(q, store()[2]);
050: }
051:
052: public void testNotEquals() {
053: Query q = st.query();
054: Constraint c = q.constrain(store()[2]);
055: q.descend("str").constraints().not();
056: Object[] r = store();
057: st.expect(q, new Object[] { r[0], r[1], r[3] });
058: }
059:
060: public void testDescendantEquals() {
061: Query q = st.query();
062: q.constrain(new STStringU());
063: q.descend("str").constrain("bbb");
064: st.expectOne(q, new STStringU("bbb"));
065: }
066:
067: public void testContains() {
068: Query q = st.query();
069: Constraint c = q.constrain(new STStringU("od"));
070: q.descend("str").constraints().contains();
071: st.expectOne(q, new STStringU("dod"));
072: }
073:
074: public void testNotContains() {
075: Query q = st.query();
076: Constraint c = q.constrain(new STStringU("od"));
077: q.descend("str").constraints().contains().not();
078: st.expect(q, new Object[] { new STStringU(null),
079: new STStringU("aaa"), new STStringU("bbb") });
080: }
081:
082: public void testLike() {
083: Query q = st.query();
084: Constraint c = q.constrain(new STStringU("do"));
085: q.descend("str").constraints().like();
086: st.expectOne(q, new STStringU("dod"));
087: q = st.query();
088: c = q.constrain(new STStringU("od"));
089: q.descend("str").constraints().like();
090: st.expectOne(q, store()[3]);
091: }
092:
093: public void testNotLike() {
094: Query q = st.query();
095: Constraint c = q.constrain(new STStringU("aaa"));
096: q.descend("str").constraints().like().not();
097: st.expect(q, new Object[] { new STStringU(null),
098: new STStringU("bbb"), new STStringU("dod") });
099: q = st.query();
100: c = q.constrain(new STStringU("xxx"));
101: q.descend("str").constraints().like();
102: st.expectNone(q);
103: }
104:
105: public void testIdentity() {
106: Query q = st.query();
107: Constraint c = q.constrain(new STStringU("aaa"));
108: ObjectSet set = q.execute();
109: STStringU identityConstraint = (STStringU) set.next();
110: identityConstraint.str = "hihs";
111: q = st.query();
112: q.constrain(identityConstraint).identity();
113: identityConstraint.str = "aaa";
114: st.expectOne(q, new STStringU("aaa"));
115: }
116:
117: public void testNotIdentity() {
118: Query q = st.query();
119: Constraint c = q.constrain(new STStringU("aaa"));
120: ObjectSet set = q.execute();
121: STStringU identityConstraint = (STStringU) set.next();
122: identityConstraint.str = null;
123: q = st.query();
124: q.constrain(identityConstraint).identity().not();
125: identityConstraint.str = "aaa";
126: st.expect(q, new Object[] { new STStringU(null),
127: new STStringU("bbb"), new STStringU("dod") });
128: }
129:
130: public void testNull() {
131: Query q = st.query();
132: Constraint c = q.constrain(new STStringU(null));
133: q.descend("str").constrain(null);
134: st.expectOne(q, new STStringU(null));
135: }
136:
137: public void testNotNull() {
138: Query q = st.query();
139: Constraint c = q.constrain(new STStringU(null));
140: q.descend("str").constrain(null).not();
141: st.expect(q, new Object[] { new STStringU("aaa"),
142: new STStringU("bbb"), new STStringU("dod") });
143: }
144:
145: public void testConstraints() {
146: Query q = st.query();
147: q.constrain(new STStringU("aaa"));
148: q.constrain(new STStringU("bbb"));
149: Constraints cs = q.constraints();
150: Constraint[] csa = cs.toArray();
151: if (csa.length != 2) {
152: st.error("Constraints not returned");
153: }
154: }
155:
156: }
|