KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > examples > clients > sb > F_sb


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_sb.java,v 1.1 2003/08/18 07:27:59 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.examples.clients.sb;
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 sb example
38  * Test the client of sb example (Check if the text is "ClientOp OK. Exiting.")
39  * @author Florent Benoit
40  */

41 public class F_sb extends JExampleTestCase {
42
43
44     /**
45      * Class of the sb.client
46      */

47     private static final String JavaDoc CLIENT_CLASS = "sb.ClientOp";
48
49     /**
50      * Text to check
51      */

52     private static final String JavaDoc CLIENTOP_OK_TXT = "ClientOp OK. Exiting." ;
53
54
55     /**
56      * Main method
57      * @param args the arguments
58      */

59     public static void main(String JavaDoc[] args) {
60
61         String JavaDoc testtorun = null;
62         // Get args
63
for (int argn = 0; argn < args.length; argn++) {
64             String JavaDoc sArg = args[argn];
65             if (sArg.equals("-n")) {
66                 testtorun = args[++argn];
67             }
68         }
69
70         if (testtorun == null) {
71             junit.textui.TestRunner.run(suite());
72         } else {
73             junit.textui.TestRunner.run(new F_sb(testtorun));
74         }
75     }
76
77     /**
78      * Get a new TestSuite for this class
79      * @return a new TestSuite for this class
80      */

81     public static TestSuite suite() {
82         return new TestSuite(F_sb.class);
83     }
84
85     /**
86      * Setup need for these tests
87      * sb is required
88      * @throws Exception if it fails
89      */

90     protected void setUp() throws Exception JavaDoc {
91         super.setUp();
92         useBeans("sb");
93     }
94
95     /**
96      * Step to do at the end
97      * unload sb
98      * @throws Exception if it fails
99      */

100     protected void tearDown() throws Exception JavaDoc {
101         super.tearDown();
102         unUseBeans("sb");
103     }
104
105
106     /**
107      * Constructor with a specified name
108      * @param s name
109      */

110     public F_sb(String JavaDoc s) {
111         super(s);
112     }
113
114
115     /**
116      * Try to launch the client of the example sb
117      * @throws Exception if an error occurs
118      */

119     public void testClient() throws Exception JavaDoc {
120         JPrintStream jPrintStream = new JPrintStream(System.out);
121         System.setOut(jPrintStream);
122         String JavaDoc txt = null;
123         try {
124             //Define a SecurityManager to handle System.exit() case
125
System.setSecurityManager(new NoExitSecurityManager());
126
127             //Call Method
128
callMainMethod(CLIENT_CLASS);
129
130             txt = jPrintStream.getStringBuffer().toString();
131         } catch (InvocationTargetException JavaDoc ite) {
132             fail("Fail when invoking the client. It can be due to a System.exit()");
133         } catch (Exception JavaDoc e) {
134             fail("Client was not ok" + e);
135         } finally {
136             System.setSecurityManager(new SecurityManager JavaDoc());
137             jPrintStream.remove();
138         }
139
140         // Check the text
141
if (txt.indexOf(CLIENTOP_OK_TXT) == -1) {
142             fail("The text that the client sent was not " + CLIENTOP_OK_TXT);
143         }
144
145     }
146
147 }
148
Popular Tags