1 26 27 package org.objectweb.jonas.examples.clients.sb; 28 29 import java.lang.reflect.InvocationTargetException ; 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 41 public class F_sb extends JExampleTestCase { 42 43 44 47 private static final String CLIENT_CLASS = "sb.ClientOp"; 48 49 52 private static final String CLIENTOP_OK_TXT = "ClientOp OK. Exiting." ; 53 54 55 59 public static void main(String [] args) { 60 61 String testtorun = null; 62 for (int argn = 0; argn < args.length; argn++) { 64 String 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 81 public static TestSuite suite() { 82 return new TestSuite(F_sb.class); 83 } 84 85 90 protected void setUp() throws Exception { 91 super.setUp(); 92 useBeans("sb"); 93 } 94 95 100 protected void tearDown() throws Exception { 101 super.tearDown(); 102 unUseBeans("sb"); 103 } 104 105 106 110 public F_sb(String s) { 111 super(s); 112 } 113 114 115 119 public void testClient() throws Exception { 120 JPrintStream jPrintStream = new JPrintStream(System.out); 121 System.setOut(jPrintStream); 122 String txt = null; 123 try { 124 System.setSecurityManager(new NoExitSecurityManager()); 126 127 callMainMethod(CLIENT_CLASS); 129 130 txt = jPrintStream.getStringBuffer().toString(); 131 } catch (InvocationTargetException ite) { 132 fail("Fail when invoking the client. It can be due to a System.exit()"); 133 } catch (Exception e) { 134 fail("Client was not ok" + e); 135 } finally { 136 System.setSecurityManager(new SecurityManager ()); 137 jPrintStream.remove(); 138 } 139 140 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 |