1 26 27 package org.objectweb.jonas.examples.clients.mailsb; 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_mailsb extends JExampleTestCase { 44 45 46 49 private static final String CLIENT_CLASS = "mailsb.ClientMailer"; 50 51 54 private static final String CLIENTOP_OK_TXT = "OK !OK !OK !OK !" ; 55 56 57 61 public static void main(String [] args) { 62 63 String testtorun = null; 64 for (int argn = 0; argn < args.length; argn++) { 66 String sArg = args[argn]; 67 if (sArg.equals("-n")) { 68 testtorun = args[++argn]; 69 } 70 } 71 72 if (testtorun == null) { 73 junit.textui.TestRunner.run(suite()); 74 } else { 75 junit.textui.TestRunner.run(new F_mailsb(testtorun)); 76 } 77 } 78 79 83 public static TestSuite suite() { 84 return new TestSuite(F_mailsb.class); 85 } 86 87 92 protected void setUp() throws Exception { 93 super.setUp(); 94 useBeans("mailsb"); 95 } 96 97 102 protected void tearDown() throws Exception { 103 super.tearDown(); 104 unUseBeans("mailsb"); 105 } 106 107 108 112 public F_mailsb(String s) { 113 super(s); 114 } 115 116 117 121 public void testClientMimePartDS() throws Exception { 122 JPrintStream jPrintStream = new JPrintStream(System.out); 123 System.setOut(jPrintStream); 124 String txt = null; 125 try { 126 System.setSecurityManager(new NoExitSecurityManager()); 128 129 callMainMethod(CLIENT_CLASS, new String [] {"MimePartDSMailer", "content of junit test"}); 131 132 txt = jPrintStream.getStringBuffer().toString(); 133 } catch (InvocationTargetException ite) { 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 |