KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > experiments > STIdentityEvaluationTestCase


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.experiments;
22 import com.db4o.*;
23 import com.db4o.query.*;
24
25
26 public class STIdentityEvaluationTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase{
27     
28     public Object JavaDoc[] createData() {
29         
30         Helper helperA = new Helper("aaa");
31         
32         return new Object JavaDoc[] {
33             new STIdentityEvaluationTestCase(null),
34             new STIdentityEvaluationTestCase(helperA),
35             new STIdentityEvaluationTestCase(helperA),
36             new STIdentityEvaluationTestCase(helperA),
37             new STIdentityEvaluationTestCase(new HelperDerivate("bbb")),
38             new STIdentityEvaluationTestCase(new Helper("dod"))
39             };
40     }
41     
42     public Helper helper;
43     
44     public STIdentityEvaluationTestCase(){
45     }
46     
47     public STIdentityEvaluationTestCase(Helper h){
48         this.helper = h;
49     }
50     
51     public void test(){
52         Query q = newQuery();
53         
54         q.constrain(new Helper("aaa"));
55         ObjectSet os = q.execute();
56         Helper helperA = (Helper)os.next();
57         q = newQuery();
58         q.constrain(STIdentityEvaluationTestCase.class);
59         q.descend("helper").constrain(helperA).identity();
60         q.constrain(new Evaluation() {
61             public void evaluate(Candidate candidate) {
62                 candidate.include(true);
63             }
64         });
65         expect(q, new int[] {1, 2, 3});
66     }
67     
68     public void testMemberClassConstraint(){
69         Query q = newQuery();
70         
71         q.constrain(STIdentityEvaluationTestCase.class);
72         q.descend("helper").constrain(HelperDerivate.class);
73         expect(q, new int[] {4});
74     }
75     
76     public static class Helper{
77         
78         public String JavaDoc hString;
79         
80         public Helper(){
81         }
82         
83         public Helper(String JavaDoc str){
84             hString = str;
85         }
86     }
87     
88     public static class HelperDerivate extends Helper{
89         public HelperDerivate(){
90         }
91         
92         public HelperDerivate(String JavaDoc str){
93             super(str);
94         }
95         
96     }
97     
98 }
99
Popular Tags