001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or 1any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: C_mailsb.java 10557 2007-06-07 09:21:44Z coqp $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.examples.clients.mailsb;
028:
029: import java.lang.reflect.InvocationTargetException;
030: import junit.framework.*;
031:
032: import org.objectweb.jonas.examples.util.JExampleTestCase;
033: import org.objectweb.jonas.examples.util.JPrintStream;
034: import org.objectweb.jonas.examples.util.NoExitSecurityManager;
035:
036: /**
037: * Define a class to test the mailsb example
038: * Test the client of mailsb example
039: * Test only MimePartDS as MailSession do some prompts
040: * (Check if the text is "OK !OK !OK !OK !")
041: * @author Florent Benoit
042: */
043: public class C_mailsb extends JExampleTestCase {
044:
045: /**
046: * Class of the mailsb.client
047: */
048: private static final String CLIENT_CLASS = "mailsb.ClientMailer";
049:
050: /**
051: * Text to check
052: */
053: private static final String CLIENTOP_OK_TXT = "OK !OK !OK !OK !";
054:
055: /**
056: * Main method
057: * @param args the arguments
058: */
059: public static void main(String[] args) {
060:
061: String testtorun = null;
062: // Get args
063: for (int argn = 0; argn < args.length; argn++) {
064: String sArg = args[argn];
065: if (sArg.equals("-n")) {
066: testtorun = args[++argn];
067: }
068: }
069:
070: if (testtorun == null) {
071: junit.textui.TestRunner.run(suite());
072: } else {
073: junit.textui.TestRunner.run(new C_mailsb(testtorun));
074: }
075: }
076:
077: /**
078: * Get a new TestSuite for this class
079: * @return a new TestSuite for this class
080: */
081: public static TestSuite suite() {
082: return new TestSuite(C_mailsb.class);
083: }
084:
085: /**
086: * Setup need for these tests
087: * mailsb is required
088: * @throws Exception if it fails
089: */
090: protected void setUp() throws Exception {
091: super .setUp();
092: useBeans("mailsb");
093: }
094:
095: /**
096: * Step to do at the end
097: * unload mailsb
098: * @throws Exception if it fails
099: */
100: protected void tearDown() throws Exception {
101: super .tearDown();
102: unUseBeans("mailsb");
103: }
104:
105: /**
106: * Constructor with a specified name
107: * @param s name
108: */
109: public C_mailsb(String s) {
110: super (s);
111: }
112:
113: /**
114: * Try to launch the client of the example mailsb
115: * @throws Exception if an error occurs
116: */
117: public void testClientMimePartDS() throws Exception {
118: JPrintStream jPrintStream = new JPrintStream(System.out);
119: System.setOut(jPrintStream);
120: String txt = null;
121: try {
122: //Define a SecurityManager to handle System.exit() case
123: System.setSecurityManager(new NoExitSecurityManager());
124:
125: //Call Method
126: callMainMethod(CLIENT_CLASS, new String[] {
127: "MimePartDSMailer", "content of junit test" });
128:
129: txt = jPrintStream.getStringBuffer().toString();
130: } catch (InvocationTargetException ite) {
131: fail("Fail when invoking the client. It can be due to a System.exit()");
132: } catch (Exception e) {
133: fail("Client was not ok" + e);
134: } finally {
135: System.setSecurityManager(new SecurityManager());
136: jPrintStream.remove();
137: }
138:
139: // Check the text
140: if (txt.indexOf(CLIENTOP_OK_TXT) == -1) {
141: fail("The text that the client sent was not "
142: + CLIENTOP_OK_TXT);
143: }
144:
145: }
146:
147: }
|