KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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