KickJava   Java API By Example, From Geeks To Geeks.

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


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_Remon.java,v 1.1 2004/06/29 08:34:28 durieuxp Exp $
22  * --------------------------------------------------------------------------
23  */

24
25 package org.objectweb.jonas.jtests.clients.entity;
26
27 import java.rmi.RemoteException JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import javax.ejb.EJBObject JavaDoc;
31 import javax.ejb.FinderException JavaDoc;
32 import javax.ejb.RemoveException JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34 import javax.rmi.PortableRemoteObject JavaDoc;
35 import junit.framework.Assert;
36 import junit.framework.Test;
37 import junit.framework.TestSuite;
38 import org.objectweb.jonas.jtests.beans.relation.remon.Main;
39 import org.objectweb.jonas.jtests.beans.relation.remon.MainHome;
40 import org.objectweb.jonas.jtests.util.JTestCase;
41
42 /**
43  * This test suite tests specifics mapping used in some applications
44  * for example, cmr field and cmp field mapped on the same table column
45  * @author Philippe Durieux
46  */

47 public class F_Remon extends JTestCase {
48
49     /**
50      * Reference on the remote Home's
51      */

52     private static MainHome mainhome = null;
53
54     /**
55      * Standard constructor
56      */

57     public F_Remon(String JavaDoc name) {
58         super(name);
59     }
60
61     protected static boolean isInit = false;
62
63     /**
64      * setup is called before each test case.
65      * If not initialized, load the remon bean and lookup the Home.
66      */

67     protected void setUp() {
68         super.setUp();
69         if (!isInit) {
70             useBeans("remon", false);
71             try {
72                 mainhome = (MainHome) PortableRemoteObject.narrow(ictx.lookup("relation_remon_MainHome"),
73                                                                   MainHome.class);
74             } catch (NamingException JavaDoc e) {
75                 fail("Cannot get bean home: " + e.getMessage());
76             }
77             isInit = true;
78         }
79     }
80
81     /**
82      * teardown is called after each test case.
83      * Notes for debugging :
84      * To see DataBase state after a test is passed :
85      * Replace the cleanall() by sync(false).
86      */

87     protected void tearDown() throws Exception JavaDoc {
88         cleanall();
89         //sync(false);
90
}
91
92     /**
93      * Cleanup all the remon after each test, to make tests independant.
94      * Use transaction to avoid known bugs during cleanup.
95      * (With no transaction -> 1 remove will fail)
96      */

97     private void cleanall() throws Exception JavaDoc {
98         debug("remove all beans");
99
100         // In case there is a problem during remove, we must unload
101
// the bean to restart properly.
102
try {
103             cleanAllBeans(mainhome);
104         } catch (Exception JavaDoc e) {
105             error("Exception in cleanup: " + e);
106             unloadBeans("remon");
107             isInit = false;
108         }
109     }
110         
111     private void cleanAllBeans(MainHome home) throws RemoteException JavaDoc, RemoveException JavaDoc {
112         try {
113             Collection JavaDoc c = home.findAll();
114             for (Iterator JavaDoc i = c.iterator(); i.hasNext(); ) {
115                 EJBObject JavaDoc p = (EJBObject JavaDoc) i.next();
116                 p.remove();
117             }
118         } catch (FinderException JavaDoc e) {
119         }
120     }
121
122     // ---------------------------------------------------------------
123
// Set of the tests that are passed automatically.
124
// ---------------------------------------------------------------
125

126     public void testCreateMain() throws Exception JavaDoc {
127         mainhome.create("A1", "100", "at1");
128     }
129
130     /**
131      * Run all the tests of this suite.
132      */

133     public static Test suite() {
134         return new TestSuite(F_Remon.class);
135     }
136
137     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
138         String JavaDoc testtorun = null;
139         
140         // Get args
141
for (int argn = 0; argn < args.length; argn++) {
142             String JavaDoc sarg = args[argn];
143             if (sarg.equals("-n")) {
144                 testtorun = args[++argn];
145             }
146         }
147         if (testtorun == null) {
148             junit.textui.TestRunner.run(suite());
149         } else {
150             junit.textui.TestRunner.run(new F_Remon(testtorun));
151         }
152     }
153
154 }
155
Popular Tags