KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 package org.objectweb.jonas.jtests.clients.entity;
23
24 import java.util.Collection JavaDoc;
25 import javax.naming.NamingException JavaDoc;
26 import javax.rmi.PortableRemoteObject JavaDoc;
27 import junit.framework.Test;
28 import junit.framework.TestSuite;
29 import org.objectweb.jonas.jtests.beans.ebasic.*;
30
31
32 /**
33  * This is an advanced test suite for home interface on pk auto incremented CMP1
34  */

35 public class F_PkAutoEC extends A_Cmp2Util {
36
37     private static String JavaDoc BEAN_HOME_PKAUTO = "pkautoobjectcmp1Home";
38
39     protected static pkautoObjectHome pkautoobjectcmp1home = null;
40
41     public F_PkAutoEC(String JavaDoc name) {
42         super(name);
43     }
44
45     protected static boolean isInit = false;
46
47     protected void setUp() {
48         super.setUp();
49         boolean ok = false;
50         int nbtry = 0;
51         while (!ok && nbtry < 3) {
52             if (!isInit) {
53                 // load bean if not loaded yet
54
useBeans("ebasic", true);
55                 // lookup home used in the tests
56
try {
57                     pkautoobjectcmp1home = (pkautoObjectHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_PKAUTO),
58                                                                               pkautoObjectHome.class);
59                 } catch (NamingException JavaDoc e) {
60                     fail("Cannot get bean home: " + e.getMessage());
61                 }
62                 // check if tables have been initialized
63
try {
64                     Collection JavaDoc bpk = pkautoobjectcmp1home.findAll();
65                     if (bpk.isEmpty()) {
66                         throw new Exception JavaDoc("Table vide");
67                     }
68                 } catch (Exception JavaDoc e) {
69                     // Make the initialization needed for the tests
70
try {
71                         utx.begin();
72                         for (int i = 1; i <= 10; i++) {
73                             pkautoobjectcmp1home.create(10, 20);
74                         }
75                     } catch (Exception JavaDoc i) {
76                         i.printStackTrace(System.out);
77                         fail("InitialState creation problem: " + i);
78                     } finally {
79                         try {
80                             utx.commit();
81                         } catch (Exception JavaDoc ii) {
82                         }
83                     }
84                 }
85                 isInit = true;
86             }
87             // Check that all is OK. Sometimes, a test has failed and has corrupted
88
// the bean state in the database. We must unload and reload the bean then.
89
nbtry++;
90             try {
91                 if (initStateOK()) {
92                     ok = true;
93                 }
94             } catch (Exception JavaDoc e) {
95             }
96             if (!ok) {
97                 isInit = false;
98                 unloadBeans("ebasic");
99             }
100         }
101     }
102
103
104     /*
105      * Check that we are in the same state as after the tables creation for thoses beans A and B
106      * (ie if it is the initial state)
107      */

108     boolean initStateOK() throws Exception JavaDoc {
109         msgerror = new StringBuffer JavaDoc();
110         Collection JavaDoc bpk = pkautoobjectcmp1home.findAll();
111         return (bpk.size() == 10);
112     }
113
114     /**
115      *
116      */

117     public void testEmpty() throws Exception JavaDoc {
118         checkIsInitialState();
119     }
120
121     /**
122      */

123     public static Test suite() {
124         return new TestSuite(F_PkAutoEC.class);
125     }
126
127     public static void main (String JavaDoc args[]) {
128         String JavaDoc testtorun = null;
129         // Get args
130
for (int argn = 0; argn < args.length; argn++) {
131             String JavaDoc s_arg = args[argn];
132             Integer JavaDoc i_arg;
133             if (s_arg.equals("-n")) {
134                 testtorun = args[++argn];
135             }
136         }
137         if (testtorun == null) {
138             junit.textui.TestRunner.run(suite());
139         } else {
140             junit.textui.TestRunner.run(new F_PkAutoEC(testtorun));
141         }
142     }
143 }
144
145
Popular Tags