001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or 1any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: C_sb.java 10557 2007-06-07 09:21:44Z coqp $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.examples.clients.sb;
028:
029: import java.lang.reflect.InvocationTargetException;
030: import junit.framework.*;
031:
032: import org.objectweb.jonas.examples.util.JExampleTestCase;
033: import org.objectweb.jonas.examples.util.JPrintStream;
034: import org.objectweb.jonas.examples.util.NoExitSecurityManager;
035:
036: /**
037: * Define a class to test the sb example
038: * Test the client of sb example (Check if the text is "ClientOp OK. Exiting.")
039: * @author Florent Benoit
040: */
041: public class C_sb extends JExampleTestCase {
042:
043: /**
044: * Class of the sb.client
045: */
046: private static final String CLIENT_CLASS = "sb.ClientOp";
047:
048: /**
049: * Text to check
050: */
051: private static final String CLIENTOP_OK_TXT = "ClientOp OK. Exiting.";
052:
053: /**
054: * Main method
055: * @param args the arguments
056: */
057: public static void main(String[] args) {
058:
059: String testtorun = null;
060: // Get args
061: for (int argn = 0; argn < args.length; argn++) {
062: String sArg = args[argn];
063: if (sArg.equals("-n")) {
064: testtorun = args[++argn];
065: }
066: }
067:
068: if (testtorun == null) {
069: junit.textui.TestRunner.run(suite());
070: } else {
071: junit.textui.TestRunner.run(new C_sb(testtorun));
072: }
073: }
074:
075: /**
076: * Get a new TestSuite for this class
077: * @return a new TestSuite for this class
078: */
079: public static TestSuite suite() {
080: return new TestSuite(C_sb.class);
081: }
082:
083: /**
084: * Setup need for these tests
085: * sb is required
086: * @throws Exception if it fails
087: */
088: protected void setUp() throws Exception {
089: super .setUp();
090: useBeans("sb");
091: }
092:
093: /**
094: * Step to do at the end
095: * unload sb
096: * @throws Exception if it fails
097: */
098: protected void tearDown() throws Exception {
099: super .tearDown();
100: unUseBeans("sb");
101: }
102:
103: /**
104: * Constructor with a specified name
105: * @param s name
106: */
107: public C_sb(String s) {
108: super (s);
109: }
110:
111: /**
112: * Try to launch the client of the example sb
113: * @throws Exception if an error occurs
114: */
115: public void testClient() throws Exception {
116: JPrintStream jPrintStream = new JPrintStream(System.out);
117: System.setOut(jPrintStream);
118: String txt = null;
119: try {
120: //Define a SecurityManager to handle System.exit() case
121: System.setSecurityManager(new NoExitSecurityManager());
122:
123: //Call Method
124: callMainMethod(CLIENT_CLASS);
125:
126: txt = jPrintStream.getStringBuffer().toString();
127: } catch (InvocationTargetException ite) {
128: fail("Fail when invoking the client. It can be due to a System.exit()");
129: } catch (Exception e) {
130: fail("Client was not ok" + e);
131: } finally {
132: System.setSecurityManager(new SecurityManager());
133: jPrintStream.remove();
134: }
135:
136: // Check the text
137: if (txt.indexOf(CLIENTOP_OK_TXT) == -1) {
138: fail("The text that the client sent was not "
139: + CLIENTOP_OK_TXT);
140: }
141:
142: }
143:
144: }
|