KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > entity > F_RcycleEC2


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  * --------------------------------------------------------------------------
21  * $Id: F_RcycleEC2.java,v 1.9 2005/04/15 13:08:43 joaninh Exp $
22  * --------------------------------------------------------------------------
23  */

24
25 package org.objectweb.jonas.jtests.clients.entity;
26
27 import java.util.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import javax.naming.NamingException JavaDoc;
31 import javax.rmi.PortableRemoteObject JavaDoc;
32
33 import junit.framework.Test;
34 import junit.framework.TestSuite;
35
36 import org.objectweb.jonas.jtests.beans.relation.rcycle.PersonRemote;
37 import org.objectweb.jonas.jtests.beans.relation.rcycle.PersonHomeRemote;
38 import org.objectweb.jonas.jtests.util.JTestCase;
39
40 /**
41  * This is a test suite on CMP 2 : legacy, cycle in relations, relations between
42  * the same bean.
43  * @author Helene Joanin
44  */

45 public class F_RcycleEC2 extends JTestCase {
46
47     private static final int ID_L_ERIC = 1;
48
49     private static final int ID_JL_HELENE = 2;
50
51     private static final int ID_L_GUILHEM = 3;
52
53     private static final int ID_L_MALVA = 4;
54
55     private static PersonHomeRemote personhome = null;
56
57     public F_RcycleEC2(String JavaDoc name) {
58         super(name);
59     }
60
61     protected static boolean isInit = false;
62
63     protected void setUp() {
64         super.setUp();
65         if (!isInit) {
66             useBeans("rcycle", true);
67             try {
68                 personhome = (PersonHomeRemote) PortableRemoteObject.narrow(ictx.lookup("RcyclePersonHome"),
69                         PersonHomeRemote.class);
70             } catch (NamingException JavaDoc e) {
71                 fail("Cannot get bean home: " + e.getMessage());
72             }
73             isInit = true;
74         }
75     }
76
77     /**
78      * Test the findAll method.
79      * @throws Exception
80      */

81     public void testFindAll() throws Exception JavaDoc {
82         Collection JavaDoc cp = personhome.findAll();
83         assertEquals("Number of Persons: ", 4, cp.size());
84     }
85
86     /**
87      * (Bug #300533) Test the findQuery1 method.
88      * @throws Exception
89      */

90     public void testFindQuery1() throws Exception JavaDoc {
91         Collection JavaDoc cp = personhome.findQuery1();
92         assertEquals("Number of Persons: ", 0, cp.size());
93     }
94
95     /**
96      * Test the findQuery2 method.
97      * @throws Exception
98      */

99     public void testFindQuery2() throws Exception JavaDoc {
100         Collection JavaDoc cp = personhome.findQuery2();
101         assertEquals("Number of Persons: ", 0, cp.size());
102     }
103
104     /**
105      * (Bug #300526) Test the findSpouse3 method.
106      * @throws Exception
107      */

108     public void testFindSpouse3() throws Exception JavaDoc {
109         PersonRemote p = personhome.findSpouse3();
110         assertNull("Laurent Guilhem spouse: ", p);
111     }
112
113     /**
114      * Test the spouse relation.
115      * @throws Exception
116      */

117     public void testSpouseRelation() throws Exception JavaDoc {
118         PersonRemote ph = personhome.findByPrimaryKey(new Integer JavaDoc(ID_L_ERIC));
119         Integer JavaDoc iw = ph.retrieveSpouse();
120         assertEquals("Wife of Laurent Eric: ", ID_JL_HELENE, iw.intValue());
121         PersonRemote pw = personhome.findByPrimaryKey(iw);
122         Integer JavaDoc ih = pw.retrieveSpouse();
123         assertEquals("Husband of Joanin-Laurent Helene: ", ID_L_ERIC, ih.intValue());
124         PersonRemote pc = personhome.findByPrimaryKey(new Integer JavaDoc(ID_L_GUILHEM));
125         Integer JavaDoc in = pc.retrieveSpouse();
126         assertNull("Laurent Guilhem spouse: ", in);
127     }
128
129     /**
130      * Test the guardian/is-guardian-of relation.
131      * @throws Exception
132      */

133     public void testGuardianRelation() throws Exception JavaDoc {
134         Integer JavaDoc iLEric = new Integer JavaDoc(ID_L_ERIC);
135         PersonRemote ph = personhome.findByPrimaryKey(iLEric);
136         Collection JavaDoc c = ph.retrieveGuardianOf();
137         assertEquals("Laurent Eric guardian of: ", 2, c.size());
138         for (Iterator JavaDoc i = c.iterator(); i.hasNext();) {
139             Integer JavaDoc ip = (Integer JavaDoc) i.next();
140             PersonRemote p = personhome.findByPrimaryKey(ip);
141             assertEquals("Guardian of " + p.getName() + ": ", iLEric, p.retrieveGuardian());
142         }
143     }
144
145     /**
146      * Test the parents/children relation.
147      * @throws Exception
148      */

149     public void testParentsChildrenRelation() throws Exception JavaDoc {
150         Integer JavaDoc iLEric = new Integer JavaDoc(ID_L_ERIC);
151         PersonRemote ph = personhome.findByPrimaryKey(iLEric);
152         Collection JavaDoc cc = ph.retrieveChildren();
153         assertEquals("Laurent Eric father of: ", 2, cc.size());
154         for (Iterator JavaDoc i = cc.iterator(); i.hasNext();) {
155             Integer JavaDoc ip = (Integer JavaDoc) i.next();
156             PersonRemote p = personhome.findByPrimaryKey(ip);
157             Collection JavaDoc cp = p.retrieveParents();
158             assertTrue("Father of " + p.getName() + ": ", cp.contains(iLEric));
159         }
160     }
161
162     /**
163      * Test if a cmr null is 'null'
164      * @throws Exception
165      */

166     public void testCmrNull() throws Exception JavaDoc {
167         PersonRemote ph = personhome.findByPrimaryKey(new Integer JavaDoc(ID_L_ERIC));
168         assertTrue("CMR null is NOT null", ph.testCmrNull());
169     }
170
171     /**
172      * Verify the spy trace to check less database access are done
173      * @throws Exception
174      */

175     public void testPrefetch() throws Exception JavaDoc {
176         //sleep(15000);
177
try {
178             utx.begin();
179             Integer JavaDoc iLEric = new Integer JavaDoc(ID_L_ERIC);
180             PersonRemote ph = personhome.findByPrimaryKey(iLEric);
181             // If there is CMR prefetching, this may imply less database access
182
Collection JavaDoc cc = ph.retrieveChildrenNames();
183             assertEquals("Laurent Eric father of: ", 2, cc.size());
184         } finally {
185             utx.commit();
186         }
187     }
188
189     protected boolean initStateOK() throws Exception JavaDoc {
190         return true;
191     }
192
193     public static Test suite() {
194         return new TestSuite(F_RcycleEC2.class);
195     }
196
197     public static void main(String JavaDoc args[]) {
198         String JavaDoc testtorun = null;
199         // Get args
200
for (int argn = 0; argn < args.length; argn++) {
201             String JavaDoc sarg = args[argn];
202             if (sarg.equals("-n")) {
203                 testtorun = args[++argn];
204             }
205         }
206         if (testtorun == null) {
207             junit.textui.TestRunner.run(suite());
208         } else {
209             junit.textui.TestRunner.run(new F_RcycleEC2(testtorun));
210         }
211     }
212 }
213
Popular Tags