1 26 27 package org.objectweb.jonas.examples.clients.mdb; 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 42 public class F_sampleappli extends JExampleTestCase { 43 44 45 48 private static final String CLIENT_CLASS = "sampleappli.SampleAppliClient"; 49 50 53 private static final String CLIENTOP_OK_TXT1 = "Nb messages sent and received OK"; 54 55 58 private static final String CLIENTOP_OK_TXT2 = "SampleApplicationClient OK" ; 59 60 61 65 public static void main(String [] args) { 66 67 String testtorun = null; 68 for (int argn = 0; argn < args.length; argn++) { 70 String sArg = args[argn]; 71 if (sArg.equals("-n")) { 72 testtorun = args[++argn]; 73 } 74 } 75 76 if (testtorun == null) { 77 junit.textui.TestRunner.run(suite()); 78 } else { 79 junit.textui.TestRunner.run(new F_sampleappli(testtorun)); 80 } 81 } 82 83 87 public static TestSuite suite() { 88 return new TestSuite(F_sampleappli.class); 89 } 90 91 96 protected void setUp() throws Exception { 97 super.setUp(); 98 useBeans("sampleappli"); 99 } 100 101 106 protected void tearDown() throws Exception { 107 super.tearDown(); 108 unUseBeans("sampleappli"); 109 } 110 111 112 116 public F_sampleappli(String s) { 117 super(s); 118 } 119 120 121 125 public void testClient() throws Exception { 126 JPrintStream jPrintStream = new JPrintStream(System.out); 127 System.setOut(jPrintStream); 128 String txt = null; 129 try { 130 System.setSecurityManager(new NoExitSecurityManager()); 132 133 callMainMethod(CLIENT_CLASS); 135 136 txt = jPrintStream.getStringBuffer().toString(); 137 } catch (InvocationTargetException ite) { 138 System.out.println("Error = " + ite); 139 ite.printStackTrace(); 140 fail("Fail when invoking the client. It can be due to a System.exit()"); 141 } catch (Exception e) { 142 fail("Client was not ok" + e); 143 } finally { 144 System.setSecurityManager(new SecurityManager ()); 145 jPrintStream.remove(); 146 } 147 148 System.out.println("Sample appli txt = " + txt); 149 150 if (txt.indexOf(CLIENTOP_OK_TXT1) == -1) { 152 fail("The text that the client sent was not " + CLIENTOP_OK_TXT1); 153 } 154 155 if (txt.indexOf(CLIENTOP_OK_TXT2) == -1) { 157 fail("The text that the client sent was not " + CLIENTOP_OK_TXT2); 158 } 159 160 161 } 162 163 } 164 | Popular Tags |