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.db4ounit.jre12.soda.experiments;
022:
023: import com.db4o.*;
024: import com.db4o.query.*;
025:
026: public class STIdentityEvaluationTestCase extends
027: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
028:
029: public Object[] createData() {
030:
031: Helper helperA = new Helper("aaa");
032:
033: return new Object[] {
034: new STIdentityEvaluationTestCase(null),
035: new STIdentityEvaluationTestCase(helperA),
036: new STIdentityEvaluationTestCase(helperA),
037: new STIdentityEvaluationTestCase(helperA),
038: new STIdentityEvaluationTestCase(new HelperDerivate(
039: "bbb")),
040: new STIdentityEvaluationTestCase(new Helper("dod")) };
041: }
042:
043: public Helper helper;
044:
045: public STIdentityEvaluationTestCase() {
046: }
047:
048: public STIdentityEvaluationTestCase(Helper h) {
049: this .helper = h;
050: }
051:
052: public void test() {
053: Query q = newQuery();
054:
055: q.constrain(new Helper("aaa"));
056: ObjectSet os = q.execute();
057: Helper helperA = (Helper) os.next();
058: q = newQuery();
059: q.constrain(STIdentityEvaluationTestCase.class);
060: q.descend("helper").constrain(helperA).identity();
061: q.constrain(new AcceptAllEvaluation());
062: expect(q, new int[] { 1, 2, 3 });
063: }
064:
065: public void testMemberClassConstraint() {
066: Query q = newQuery();
067:
068: q.constrain(STIdentityEvaluationTestCase.class);
069: q.descend("helper").constrain(HelperDerivate.class);
070: expect(q, new int[] { 4 });
071: }
072:
073: public static class AcceptAllEvaluation implements Evaluation {
074: public void evaluate(Candidate candidate) {
075: candidate.include(true);
076: }
077: }
078:
079: public static class Helper {
080:
081: public String hString;
082:
083: public Helper() {
084: }
085:
086: public Helper(String str) {
087: hString = str;
088: }
089: }
090:
091: public static class HelperDerivate extends Helper {
092: public HelperDerivate() {
093: }
094:
095: public HelperDerivate(String str) {
096: super(str);
097: }
098:
099: }
100:
101: }
|