1 26 27 package org.objectweb.jonas.examples.clients.eb; 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 43 public class F_eb extends JExampleTestCase { 44 45 46 49 private static final String CLIENT_CLASS = "eb.ClientAccount"; 50 51 54 private static final String CLIENT_OK_TXT = "ClientAccount terminated" ; 55 56 59 private static final String ACC_IMPL = "AccountImplHome"; 60 61 62 65 private static final String ACC_EXPL = "AccountExplHome"; 66 67 68 69 73 public static void main(String [] args) { 74 75 String testtorun = null; 76 for (int argn = 0; argn < args.length; argn++) { 78 String 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 95 public static TestSuite suite() { 96 return new TestSuite(F_eb.class); 97 } 98 99 104 protected void setUp() throws Exception { 105 super.setUp(); 106 useBeans("eb"); 107 } 108 109 114 protected void tearDown() throws Exception { 115 super.tearDown(); 116 unUseBeans("eb"); 117 } 118 119 123 public F_eb(String s) { 124 super(s); 125 } 126 127 132 private void doTestEb(String mode) { 133 JPrintStream jPrintStream = new JPrintStream(System.out); 134 System.setOut(jPrintStream); 135 String txt = null; 136 try { 137 System.setSecurityManager(new NoExitSecurityManager()); 139 140 callMainMethod(CLIENT_CLASS, new String [] {mode}); 142 143 txt = jPrintStream.getStringBuffer().toString(); 144 } catch (InvocationTargetException ite) { 145 fail("Fail when invoking the client. It can be due to a System.exit()"); 146 } catch (Exception e) { 147 fail("Client was not ok" + e); 148 } finally { 149 System.setSecurityManager(new SecurityManager ()); 150 jPrintStream.remove(); 151 } 152 153 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 165 public void testClientAccountImpl() throws Exception { 166 doTestEb(ACC_IMPL); 167 } 168 169 174 public void testClientAccountExpl() throws Exception { 175 doTestEb(ACC_EXPL); 176 } 177 178 } 179 | Popular Tags |