KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > deploy > F_JonasAdminDeploy


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 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_JonasAdminDeploy.java,v 1.4 2005/07/25 12:33:00 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.deploy;
27
28 import junit.framework.TestSuite;
29
30 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
31 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
32
33 import com.meterware.httpunit.HttpUnitOptions;
34 import com.meterware.httpunit.TableCell;
35 import com.meterware.httpunit.WebForm;
36 import com.meterware.httpunit.WebResponse;
37 import com.meterware.httpunit.WebTable;
38
39 /**
40  * Define a class to test the JOnAS Admin console
41  * Test authentication and deploy/undeploy ears
42  * @author Florent Benoit
43  */

44 public class F_JonasAdminDeploy extends JonasAdminTestCase {
45
46     /**
47      * Main method
48      * @param args the arguments
49      */

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

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

80     protected void setUp() throws Exception JavaDoc {
81         super.setUp();
82
83         if (wc.getCurrentPage().getURL() == null) {
84             useWar("jonasAdmin");
85         } else {
86             // if there was an error, the connection must be restablished
87
try {
88                 wc.getFrameContents(FRAME_TREE);
89             } catch (Exception JavaDoc e) {
90                 wc.getResponse(urlLogOut);
91             }
92         }
93     }
94
95
96     /**
97      * Constructor with a specified name
98      * @param s name
99      */

100     public F_JonasAdminDeploy(String JavaDoc s) {
101         super(s, URL_JONASADMIN);
102     }
103
104     /**
105      * Try to authenticate with a bad login/password
106      * @throws Exception if an error occurs
107      */

108     public void testTryBadAuth() throws Exception JavaDoc {
109         // login to jonas admin
110
WebResponse wRes = JonasAdminAuth.doAuth(wc, url, "bad", "bad");
111         String JavaDoc txt = wRes.getText();
112
113         if (txt.indexOf("Invalid username or password") == -1) {
114             fail("The login/password bad/bad can't be a valid l/p.");
115         }
116     }
117
118     /**
119      * Try to authenticate with a right login/password
120      * @throws Exception if an error occurs
121      */

122     public void testTryWithGoodAuth() throws Exception JavaDoc {
123         WebResponse wRes = JonasAdminAuth.doValidAuth(wc, url);
124         String JavaDoc txt = wRes.getText();
125
126         if (txt.indexOf("Invalid username or password") != -1) {
127             fail("The login/password jadmin/jonas must be valid.");
128         }
129     }
130
131     /**
132      * Return the text of the deployed table or the deployable table
133      * @param wr the WebResponse to use
134      * @param deployed if true return the text deployed table, if false text of deployable
135      * @return the text of the deployed table or the deployable table
136      * @throws Exception if an error occurs
137      */

138     private String JavaDoc getDeployTable(WebResponse wr, boolean deployed) throws Exception JavaDoc {
139
140         //Extract right table
141
WebTable bigTable = wr.getTables()[0];
142         WebTable firstTable = bigTable.getTableCell(1, 0).getTables()[0];
143         WebTable cellTable = firstTable.getTableCell(0, 0).getTables()[0];
144         WebTable subTable = cellTable.getTableCell(0, 0).getTables()[0];
145
146         TableCell deployableCell = subTable.getTableCell(1, 0);
147         TableCell deployedCell = subTable.getTableCell(1, 2);
148
149         if (deployed) {
150             return deployedCell.getText();
151         } else {
152             return deployableCell.getText();
153         }
154     }
155
156
157     /**
158      * Deploy the ear with the testcase method and then, try to undeploy the ear with jonaAdmin
159      * If it was undeployed, deploy it again with jonasAdmin
160      * @param name of the ear (without extension) to test
161      * @throws Exception if an error occurs
162      */

163     private void unDeployAndDeployEar(String JavaDoc name) throws Exception JavaDoc {
164         String JavaDoc fileName = name + ".ear";
165         String JavaDoc url = URL_JONASADMIN_DEPLOYEAR;
166
167         //First load Ear
168
useEar(name);
169
170         WebResponse wr = wc.getResponse(getAbsoluteUrl(url));
171         String JavaDoc txt = getDeployTable(wr, true);
172
173         if (txt.indexOf(fileName) == -1) {
174             fail("The file" + fileName + " was not found as deployed.");
175         }
176
177         WebForm[] webForms = wr.getForms();
178         WebForm webForm = webForms[0];
179
180         String JavaDoc params = webForm.getParameterValue("undeploy");
181         WebForm.Scriptable script = webForm.getScriptableObject();
182
183         // Disable errors of javascript
184
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
185
186         if (params.length() == 0) {
187             params += fileName;
188         } else {
189             params += "," + fileName;
190         }
191
192         script.setParameterValue("undeploy", params);
193
194         WebResponse submitUndeploy = webForm.submit();
195
196         //alarm is in the table
197
webForms = submitUndeploy.getForms();
198         webForm = webForms[0];
199
200         WebResponse endResp = webForm.submit();
201
202
203         wr = wc.getResponse(getAbsoluteUrl(url));
204         txt = getDeployTable(wr, true);
205
206         if (txt.indexOf(fileName) != -1) {
207             fail("The jonasAdmin webApp has not removed. " + fileName);
208         }
209
210         //now deploy
211
webForms = wr.getForms();
212         webForm = webForms[0];
213
214         params = webForm.getParameterValue("deploy");
215         script = webForm.getScriptableObject();
216
217         if (params.length() == 0) {
218             params += fileName;
219         } else {
220             params += "," + fileName;
221         }
222
223         script.setParameterValue("deploy", params);
224
225         submitUndeploy = webForm.submit();
226
227         //alarm is in the table
228
webForms = submitUndeploy.getForms();
229         webForm = webForms[0];
230
231         endResp = webForm.submit();
232
233         wr = wc.getResponse(getAbsoluteUrl(url));
234         txt = getDeployTable(wr, true);
235
236         if (txt.indexOf(fileName) == -1) {
237             fail("The file " + fileName + " was not found as deployed.");
238         }
239     }
240
241     /**
242      * Deploy the ear with the testcase method and then, try to undeploy the ear with jonaAdmin
243      * If it was undeployed, deploy it again with jonasAdmin
244      * Test with ears alarm and cmp2
245      * @throws Exception if an error occurs
246      */

247     public void testTryDeployUndeployEars() throws Exception JavaDoc {
248         // login to jonas admin
249
JonasAdminAuth.doValidAuth(wc, url);
250
251         unDeployAndDeployEar("alarm");
252         unDeployAndDeployEar("cmp2");
253     }
254
255 }
256
Popular Tags