KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > examples > clients > mailsb > F_mailsb


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: F_mailsb.java,v 1.1 2003/08/18 07:27:59 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.examples.clients.mailsb;
28
29 import java.lang.reflect.InvocationTargetException JavaDoc;
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 /**
37  * Define a class to test the mailsb example
38  * Test the client of mailsb example
39  * Test only MimePartDS as MailSession do some prompts
40  * (Check if the text is "OK !OK !OK !OK !")
41  * @author Florent Benoit
42  */

43 public class F_mailsb extends JExampleTestCase {
44
45
46     /**
47      * Class of the mailsb.client
48      */

49     private static final String JavaDoc CLIENT_CLASS = "mailsb.ClientMailer";
50
51     /**
52      * Text to check
53      */

54     private static final String JavaDoc CLIENTOP_OK_TXT = "OK !OK !OK !OK !" ;
55
56
57     /**
58      * Main method
59      * @param args the arguments
60      */

61     public static void main(String JavaDoc[] args) {
62
63         String JavaDoc testtorun = null;
64         // Get args
65
for (int argn = 0; argn < args.length; argn++) {
66             String JavaDoc 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     /**
80      * Get a new TestSuite for this class
81      * @return a new TestSuite for this class
82      */

83     public static TestSuite suite() {
84         return new TestSuite(F_mailsb.class);
85     }
86
87     /**
88      * Setup need for these tests
89      * mailsb is required
90      * @throws Exception if it fails
91      */

92     protected void setUp() throws Exception JavaDoc {
93         super.setUp();
94         useBeans("mailsb");
95     }
96
97     /**
98      * Step to do at the end
99      * unload mailsb
100      * @throws Exception if it fails
101      */

102     protected void tearDown() throws Exception JavaDoc {
103         super.tearDown();
104         unUseBeans("mailsb");
105     }
106
107
108     /**
109      * Constructor with a specified name
110      * @param s name
111      */

112     public F_mailsb(String JavaDoc s) {
113         super(s);
114     }
115
116
117     /**
118      * Try to launch the client of the example mailsb
119      * @throws Exception if an error occurs
120      */

121     public void testClientMimePartDS() throws Exception JavaDoc {
122         JPrintStream jPrintStream = new JPrintStream(System.out);
123         System.setOut(jPrintStream);
124         String JavaDoc txt = null;
125         try {
126             //Define a SecurityManager to handle System.exit() case
127
System.setSecurityManager(new NoExitSecurityManager());
128
129             //Call Method
130
callMainMethod(CLIENT_CLASS, new String JavaDoc[] {"MimePartDSMailer", "content of junit test"});
131
132             txt = jPrintStream.getStringBuffer().toString();
133         } catch (InvocationTargetException JavaDoc ite) {
134             fail("Fail when invoking the client. It can be due to a System.exit()");
135         } catch (Exception JavaDoc e) {
136             fail("Client was not ok" + e);
137         } finally {
138             System.setSecurityManager(new SecurityManager JavaDoc());
139             jPrintStream.remove();
140         }
141
142         // Check the text
143
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