1 26 27 package org.objectweb.jonas.examples.clients.lb; 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_lb extends JExampleTestCase { 42 43 44 47 private static final String CLIENT_CLASS = "lb.Client"; 48 49 52 private static final String CLIENTOP_OK_TXT = "PASS when checking all accounts" ; 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_lb(testtorun)); 74 } 75 } 76 77 81 public static TestSuite suite() { 82 return new TestSuite(F_lb.class); 83 } 84 85 90 protected void setUp() throws Exception { 91 super.setUp(); 92 useBeans("lb"); 93 } 94 95 100 protected void tearDown() throws Exception { 101 super.tearDown(); 102 unUseBeans("lb"); 103 } 104 105 106 110 public F_lb(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 System.out.println("Error = " + ite); 133 ite.printStackTrace(); 134 fail("Fail when invoking the client. It can be due to a System.exit()"); 135 } catch (Exception e) { 136 fail("Client was not ok" + e); 137 } finally { 138 System.setSecurityManager(new SecurityManager ()); 139 jPrintStream.remove(); 140 } 141 142 if (txt.indexOf(CLIENTOP_OK_TXT) == -1) { 144 fail("The text that the client sent was not " + CLIENTOP_OK_TXT); 145 } 146 147 } 148 149 } 150 | Popular Tags |