KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > examples > clients > eb > F_eb


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 1any 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  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: F_eb.java,v 1.1 2003/08/18 07:27:59 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.examples.clients.eb;
28
29 import java.lang.reflect.InvocationTargetException JavaDoc;
30 import junit.framework.*;
31
32 import org.objectweb.jonas.examples.util.JExampleTestCase;
33 import org.objectweb.jonas.examples.util.JPrintStream;
34 import org.objectweb.jonas.examples.util.NoExitSecurityManager;
35
36 /**
37  * Define a class to test the eb example
38  * Test the client of eb example (Check if the text is "ClientAccount terminated")
39  * - test case of AccountImplHome
40  * - test case of AccountExplHome
41  * @author Florent Benoit
42  */

43 public class F_eb extends JExampleTestCase {
44
45
46     /**
47      * Class of the eb.client
48      */

49     private static final String JavaDoc CLIENT_CLASS = "eb.ClientAccount";
50
51     /**
52      * Text to check
53      */

54     private static final String JavaDoc CLIENT_OK_TXT = "ClientAccount terminated" ;
55
56     /**
57      * Impl
58      */

59     private static final String JavaDoc ACC_IMPL = "AccountImplHome";
60
61
62     /**
63      * Expl
64      */

65     private static final String JavaDoc ACC_EXPL = "AccountExplHome";
66
67
68
69     /**
70      * Main method
71      * @param args the arguments
72      */

73     public static void main(String JavaDoc[] args) {
74
75         String JavaDoc testtorun = null;
76         // Get args
77
for (int argn = 0; argn < args.length; argn++) {
78             String JavaDoc sArg = args[argn];
79             if (sArg.equals("-n")) {
80                 testtorun = args[++argn];
81             }
82         }
83
84         if (testtorun == null) {
85             junit.textui.TestRunner.run(suite());
86         } else {
87             junit.textui.TestRunner.run(new F_eb(testtorun));
88         }
89     }
90
91     /**
92      * Get a new TestSuite for this class
93      * @return a new TestSuite for this class
94      */

95     public static TestSuite suite() {
96         return new TestSuite(F_eb.class);
97     }
98
99     /**
100      * Setup need for these tests
101      * eb is required
102      * @throws Exception if it fails
103      */

104     protected void setUp() throws Exception JavaDoc {
105         super.setUp();
106         useBeans("eb");
107     }
108
109     /**
110      * Step to do at the end
111      * unload eb
112      * @throws Exception if it fails
113      */

114     protected void tearDown() throws Exception JavaDoc {
115         super.tearDown();
116         unUseBeans("eb");
117     }
118
119     /**
120      * Constructor with a specified name
121      * @param s name
122      */

123     public F_eb(String JavaDoc s) {
124         super(s);
125     }
126
127     /**
128      * Test the return text of the example eb
129      * by using a specific mode (Impl or Expl)
130      * @param mode Can be AccountImplHome or AccountExplHome
131      */

132     private void doTestEb(String JavaDoc mode) {
133         JPrintStream jPrintStream = new JPrintStream(System.out);
134         System.setOut(jPrintStream);
135         String JavaDoc txt = null;
136         try {
137             // Define a SecurityManager to handle System.exit() case
138
System.setSecurityManager(new NoExitSecurityManager());
139
140             // Call Method
141
callMainMethod(CLIENT_CLASS, new String JavaDoc[] {mode});
142
143             txt = jPrintStream.getStringBuffer().toString();
144         } catch (InvocationTargetException JavaDoc ite) {
145             fail("Fail when invoking the client. It can be due to a System.exit()");
146         } catch (Exception JavaDoc e) {
147             fail("Client was not ok" + e);
148         } finally {
149             System.setSecurityManager(new SecurityManager JavaDoc());
150             jPrintStream.remove();
151         }
152
153         // Check the text
154
if (txt.indexOf(CLIENT_OK_TXT) == -1) {
155             fail("The text that the client sent was not " + CLIENT_OK_TXT);
156         }
157     }
158
159
160     /**
161      * Try to launch the client of the example eb
162      * with the case AccountImpl
163      * @throws Exception if an error occurs
164      */

165     public void testClientAccountImpl() throws Exception JavaDoc {
166         doTestEb(ACC_IMPL);
167     }
168
169     /**
170      * Try to launch the client of the example eb
171      * with the case AccountExpl
172      * @throws Exception if an error occurs
173      */

174     public void testClientAccountExpl() throws Exception JavaDoc {
175         doTestEb(ACC_EXPL);
176     }
177
178 }
179
Popular Tags