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_samplemdb extends JExampleTestCase { 43 44 45 48 private static final String CLIENT_CLASS = "samplemdb.MdbClient"; 49 50 53 private static final String CLIENTOP_OK_TXT = "MDBsample is Ok"; 54 55 56 60 public static void main(String [] args) { 61 62 String testtorun = null; 63 for (int argn = 0; argn < args.length; argn++) { 65 String sArg = args[argn]; 66 if (sArg.equals("-n")) { 67 testtorun = args[++argn]; 68 } 69 } 70 71 if (testtorun == null) { 72 junit.textui.TestRunner.run(suite()); 73 } else { 74 junit.textui.TestRunner.run(new F_samplemdb(testtorun)); 75 } 76 } 77 78 82 public static TestSuite suite() { 83 return new TestSuite(F_samplemdb.class); 84 } 85 86 91 protected void setUp() throws Exception { 92 super.setUp(); 93 useBeans("samplemdb"); 94 } 95 96 101 protected void tearDown() throws Exception { 102 super.tearDown(); 103 unUseBeans("samplemdb"); 104 } 105 106 107 111 public F_samplemdb(String s) { 112 super(s); 113 } 114 115 116 120 public void testClient() throws Exception { 121 JPrintStream jPrintStream = new JPrintStream(System.out); 122 System.setOut(jPrintStream); 123 String txt = null; 124 try { 125 System.setSecurityManager(new NoExitSecurityManager()); 127 128 callMainMethod(CLIENT_CLASS); 130 131 txt = jPrintStream.getStringBuffer().toString(); 132 } catch (InvocationTargetException ite) { 133 System.out.println("Error = " + ite); 134 ite.printStackTrace(); 135 fail("Fail when invoking the client. It can be due to a System.exit()"); 136 } catch (Exception e) { 137 fail("Client was not ok" + e); 138 } finally { 139 System.setSecurityManager(new SecurityManager ()); 140 jPrintStream.remove(); 141 } 142 143 System.out.println("Sample mdb txt = " + txt); 144 145 if (txt.indexOf(CLIENTOP_OK_TXT) == -1) { 147 fail("The text that the client sent was not " + CLIENTOP_OK_TXT); 148 } 149 150 } 151 152 } 153 | Popular Tags |