KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > examples > clients > cmp2 > F_Cmp2


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  * --------------------------------------------------------------------------
22  * $Id: F_Cmp2.java,v 1.2 2004/03/19 11:57:17 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.examples.clients.cmp2;
27
28 import junit.framework.TestSuite;
29
30 import org.objectweb.jonas.examples.util.JExampleTestCase;
31
32 import com.meterware.httpunit.WebForm;
33 import com.meterware.httpunit.WebResponse;
34
35 /**
36  * Define a class to test the cmp2 example
37  * Test the three servlet are ok
38  * @author Philippe Coq
39  */

40 public class F_Cmp2 extends JExampleTestCase {
41
42     /**
43      * URL of the cmp2 page
44      */

45     private static final String JavaDoc URL_EARCMP2 = "/cmp2";
46
47     /**
48      * Main method
49      * @param args the arguments
50      */

51     public static void main(String JavaDoc[] args) {
52
53         String JavaDoc testtorun = null;
54         // Get args
55
for (int argn = 0; argn < args.length; argn++) {
56             String JavaDoc sArg = args[argn];
57             if (sArg.equals("-n")) {
58                 testtorun = args[++argn];
59             }
60         }
61
62         if (testtorun == null) {
63             junit.textui.TestRunner.run(suite());
64         } else {
65             junit.textui.TestRunner.run(new F_Cmp2(testtorun));
66         }
67     }
68
69     /**
70      * Get a new TestSuite for this class
71      * @return a new TestSuite for this class
72      */

73     public static TestSuite suite() {
74         return new TestSuite(F_Cmp2.class);
75     }
76
77     /**
78      * Setup need for these tests
79      * cmp2 is required
80      * @throws Exception if it fails
81      */

82     protected void setUp() throws Exception JavaDoc {
83         super.setUp();
84         useEar("cmp2");
85     }
86
87     /**
88      * Constructor with a specified name
89      * @param s name
90      */

91     public F_Cmp2(String JavaDoc s) {
92         super(s, URL_EARCMP2);
93     }
94
95     /**
96      * Test the examples showing 1-to-1 relationship
97      * @throws Exception if an error occurs
98      */

99     public void testFirstServlet() throws Exception JavaDoc {
100  
101         WebResponse wr = wc.getResponse(url);
102
103         WebForm[] webForms = wr.getForms();
104         WebForm webForm = webForms[0];
105         assertNotNull("There must be a form in the html page", webForm);
106         WebResponse wFormRes = webForm.submit();
107         String JavaDoc txt = wFormRes.getText();
108         if (txt.indexOf("<strong>Servlet is OK.</strong>") == -1) {
109             fail("The example was not ok : " + txt);
110         }
111     }
112
113
114     /**
115      * Test the examples showing n-to-1 1-to-n relationship
116      * @throws Exception if an error occurs
117      */

118     public void testSecondServlet() throws Exception JavaDoc {
119  
120         WebResponse wr = wc.getResponse(url);
121
122         WebForm[] webForms = wr.getForms();
123         WebForm webForm = webForms[1];
124         assertNotNull("There must be a form in the html page", webForm);
125         WebResponse wFormRes = webForm.submit();
126         String JavaDoc txt = wFormRes.getText();
127         if (txt.indexOf("<strong>Servlet is OK.</strong>") == -1) {
128             fail("The example was not ok : " + txt);
129         }
130     }
131
132     /**
133      * Test the examples using EJB-QL
134      * @throws Exception if an error occurs
135      */

136     public void testThirdServlet() throws Exception JavaDoc {
137  
138         WebResponse wr = wc.getResponse(url);
139
140         WebForm[] webForms = wr.getForms();
141         WebForm webForm = webForms[2];
142         assertNotNull("There must be a form in the html page", webForm);
143         WebResponse wFormRes = webForm.submit();
144         String JavaDoc txt = wFormRes.getText();
145         if (txt.indexOf("<strong>Servlet is OK.</strong>") == -1) {
146             fail("The example was not ok : " + txt);
147         }
148     }
149
150 }
151
Popular Tags