001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 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: * --------------------------------------------------------------------------
022: * $Id: F_JonasAdminDeployWar.java 7381 2005-09-14 16:00:02Z kemlerp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jonasadmin.test.deploy;
025:
026: import java.io.File;
027:
028: import junit.framework.TestSuite;
029:
030: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
031: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
032: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
033:
034: import com.meterware.httpunit.HttpUnitOptions;
035: import com.meterware.httpunit.SubmitButton;
036: import com.meterware.httpunit.TableCell;
037: import com.meterware.httpunit.WebForm;
038: import com.meterware.httpunit.WebLink;
039: import com.meterware.httpunit.WebResponse;
040: import com.meterware.httpunit.WebTable;
041:
042: /**
043: * Class for testing deploy/undeploy wars
044: * @author Paul Kemler
045: */
046: public class F_JonasAdminDeployWar extends JonasAdminTestCase {
047:
048: /**
049: * URL of the deployment of WARs
050: */
051: protected static final String URL_JONASADMIN_DEPLOYWAR = "EditDeploy.do?type=war";
052:
053: /**
054: * URL of the deployment
055: */
056: protected static final String URL_JONASADMIN_DEPLOY = "EditDeploy.do";
057:
058: /**
059: * URL of UPLOAD
060: */
061: protected static final String URL_JONASADMIN_UPLOAD = "EditUpload.do";
062:
063: /**
064: * URL of REMOVE
065: */
066: protected static final String URL_JONASADMIN_REMOVE = "EditRemove.do";
067:
068: /**
069: * number of tabs when you are in the deployment tabs
070: */
071: private static final int NUMBER_OF_TABS_FOR_DEPLOYMENT = 3;
072:
073: /**
074: * number of tabs when you are in the CONFIRM tabs
075: */
076: private static final int NUMBER_OF_TABS_FOR_CONFIRM = 4;
077:
078: /**
079: * Constructor with a specified name
080: * @param s name
081: */
082: public F_JonasAdminDeployWar(String s) {
083: super (s, URL_JONASADMIN);
084: }
085:
086: /**
087: * Main method
088: * @param args the arguments
089: */
090: public static void main(String[] args) {
091:
092: String testtorun = null;
093: // Get args
094: for (int argn = 0; argn < args.length; argn++) {
095: String sArg = args[argn];
096: if (sArg.equals("-n")) {
097: testtorun = args[++argn];
098: }
099: }
100: if (testtorun == null) {
101: junit.textui.TestRunner.run(suite());
102: } else {
103: junit.textui.TestRunner.run(new F_JonasAdminDeployWar(
104: testtorun));
105: }
106: }
107:
108: /**
109: * Get a new TestSuite for this class
110: * @return a new TestSuite for this class
111: */
112: public static TestSuite suite() {
113: return new TestSuite(F_JonasAdminDeployWar.class);
114: }
115:
116: /**
117: * Setup need for these tests jonasAdmin is required
118: * @throws Exception if it fails
119: */
120: protected void setUp() throws Exception {
121: super .setUp();
122:
123: if (wc.getCurrentPage().getURL() == null) {
124: useWar("jonasAdmin");
125: // login to jonas admin
126: try {
127: JonasAdminAuth.doValidAuth(wc, url);
128: } catch (Exception e) {
129: fail("authentification failed : " + e);
130: }
131: } else {
132: // if there was an error, the connection must be restablished
133: try {
134: wc.getFrameContents(FRAME_TREE);
135: } catch (Exception e) {
136: wc.getResponse(urlLogOut);
137: // login to jonas admin
138: try {
139: JonasAdminAuth.doValidAuth(wc, url);
140: } catch (Exception auth) {
141: fail("authentification failed : " + auth);
142: }
143: }
144: }
145: }
146:
147: /**
148: * Return the text of the deployed table or the deployable table
149: * @param wr the WebResponse to use
150: * @param deployed if true return the text deployed table, if false text of
151: * deployable
152: * @return the text of the deployed table or the deployable table
153: * @throws Exception if an error occurs
154: */
155: private String getDeployTable(WebResponse wr, boolean deployed)
156: throws Exception {
157:
158: // Extract right table
159: JonasAdminUtils utils = new JonasAdminUtils();
160: WebTable table = utils.getTable(wr, 0);
161:
162: TableCell deployableCell = table.getTableCell(1, 0);
163: TableCell deployedCell = table.getTableCell(1, 2);
164:
165: if (deployed) {
166: return deployedCell.getText();
167: } else {
168: return deployableCell.getText();
169: }
170: }
171:
172: /**
173: * Deploy the war with the testcase method and then, try to undeploy the war
174: * with jonaAdmin If it was undeployed, deploy it again with jonasAdmin Test
175: * with war autoload/ctxroot.war
176: * @throws Exception if an error occurs
177: */
178: public void testTryDeployUndeployWars() throws Exception {
179:
180: WebResponse wr;
181: WebLink link;
182: WebTable table;
183: WebTable tabTable;
184: int selectedTab;
185: /*
186: * To get some utils for WebTable
187: */
188: JonasAdminUtils utils = new JonasAdminUtils();
189:
190: // Disable errors of javascript
191: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
192: // Disable exception thrown on error status
193: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
194:
195: // First load War
196: String name = "autoload" + File.separator + "ctxroot";
197: String fileName = name + ".war";
198: useWar(name);
199:
200: // Go to Deployment/WebModules
201: wr = wc.getFrameContents(FRAME_TREE);
202: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
203: URL_JONASADMIN_DEPLOYWAR);
204: link.click();
205: wr = wc.getFrameContents(FRAME_CONTENT);
206: selectedTab = 1;
207:
208: // Verify tabs
209: tabTable = utils.getTabTable(wr);
210: testTabs(tabTable, NUMBER_OF_TABS_FOR_DEPLOYMENT, selectedTab,
211: "Problem in 'Deployment' tab.");
212: // - links
213: assertTrue("The link " + URL_JONASADMIN_UPLOAD
214: + " is not found in the second tab. ", tabTable
215: .getTableCell(0, 2).getLinks()[0].getURLString()
216: .endsWith(URL_JONASADMIN_UPLOAD));
217: assertTrue("The link " + URL_JONASADMIN_REMOVE
218: + " is not found in the third tab. ", tabTable
219: .getTableCell(0, 4).getLinks()[0].getURLString()
220: .endsWith(URL_JONASADMIN_REMOVE));
221:
222: String txt = getDeployTable(wr, true);
223:
224: if (txt.indexOf(fileName) == -1) {
225: fail("The file" + fileName + " was not found as deployed.");
226: }
227:
228: // Undeploy
229: WebForm[] webForms = wr.getForms();
230: WebForm webForm = webForms[0];
231:
232: String params = webForm.getParameterValue("undeploy");
233: WebForm.Scriptable script = webForm.getScriptableObject();
234: if (params.length() == 0) {
235: params += fileName;
236: } else {
237: params += "," + fileName;
238: }
239: script.setParameterValue("undeploy", params);
240:
241: SubmitButton button = webForm.getSubmitButtons()[0];
242: button.click();
243:
244: // Confirm
245: WebResponse submitUndeploy = wc.getFrameContents(FRAME_CONTENT);
246: selectedTab = 2;
247:
248: // Verify tabs
249: tabTable = utils.getTabTable(submitUndeploy);
250: testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab,
251: "Problem in 'Confirm' tab.");
252: // - links
253: assertTrue("The link " + URL_JONASADMIN_DEPLOY
254: + " is not found in the first tab. ", tabTable
255: .getTableCell(0, 0).getLinks()[0].getURLString()
256: .endsWith(URL_JONASADMIN_DEPLOY));
257: assertTrue("The link " + URL_JONASADMIN_UPLOAD
258: + " is not found in the third tab. ", tabTable
259: .getTableCell(0, 4).getLinks()[0].getURLString()
260: .endsWith(URL_JONASADMIN_UPLOAD));
261: assertTrue("The link " + URL_JONASADMIN_REMOVE
262: + " is not found in the fourth tab. ", tabTable
263: .getTableCell(0, 6).getLinks()[0].getURLString()
264: .endsWith(URL_JONASADMIN_REMOVE));
265:
266: webForms = submitUndeploy.getForms();
267: webForm = webForms[0];
268:
269: button = webForm.getSubmitButtons()[0];
270: button.click();
271: wr = wc.getFrameContents(FRAME_CONTENT);
272:
273: // Verify tabs
274: tabTable = utils.getTabTable(wr);
275: testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab,
276: "Problem in 'Result' tab.");
277: // - links
278: assertTrue("The link " + URL_JONASADMIN_DEPLOY
279: + " is not found in the first tab. ", tabTable
280: .getTableCell(0, 0).getLinks()[0].getURLString()
281: .endsWith(URL_JONASADMIN_DEPLOY));
282: assertTrue("The link " + URL_JONASADMIN_UPLOAD
283: + " is not found in the third tab. ", tabTable
284: .getTableCell(0, 4).getLinks()[0].getURLString()
285: .endsWith(URL_JONASADMIN_UPLOAD));
286: assertTrue("The link " + URL_JONASADMIN_REMOVE
287: + " is not found in the fourth tab. ", tabTable
288: .getTableCell(0, 6).getLinks()[0].getURLString()
289: .endsWith(URL_JONASADMIN_REMOVE));
290:
291: // Go back to Deployment
292: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
293: URL_JONASADMIN_DEPLOY);
294: link.click();
295: wr = wc.getFrameContents(FRAME_CONTENT);
296: selectedTab = 1;
297:
298: // Verify tabs
299: tabTable = utils.getTabTable(wr);
300: testTabs(tabTable, NUMBER_OF_TABS_FOR_DEPLOYMENT, selectedTab,
301: "Problem in 'Deployment' tab.");
302: // - links
303: assertTrue("The link " + URL_JONASADMIN_UPLOAD
304: + " is not found in the second tab. ", tabTable
305: .getTableCell(0, 2).getLinks()[0].getURLString()
306: .endsWith(URL_JONASADMIN_UPLOAD));
307: assertTrue("The link " + URL_JONASADMIN_REMOVE
308: + " is not found in the third tab. ", tabTable
309: .getTableCell(0, 4).getLinks()[0].getURLString()
310: .endsWith(URL_JONASADMIN_REMOVE));
311:
312: txt = getDeployTable(wr, true);
313:
314: if (txt.indexOf(fileName) != -1) {
315: fail("The jonasAdmin webApp has not removed. " + fileName);
316: }
317:
318: // now deploy
319: webForms = wr.getForms();
320: webForm = webForms[0];
321:
322: params = webForm.getParameterValue("deploy");
323: script = webForm.getScriptableObject();
324:
325: if (params.length() == 0) {
326: params += fileName;
327: } else {
328: params += "," + fileName;
329: }
330:
331: script.setParameterValue("deploy", params);
332: button = webForm.getSubmitButtons()[0];
333: button.click();
334:
335: // Confirm
336: submitUndeploy = wc.getFrameContents(FRAME_CONTENT);
337: // war is in the table
338: webForms = submitUndeploy.getForms();
339: webForm = webForms[0];
340:
341: button = webForm.getSubmitButtons()[0];
342: button.click();
343:
344: // Go back to Deployment
345: wr = wc.getFrameContents(FRAME_CONTENT);
346: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
347: URL_JONASADMIN_DEPLOY);
348: link.click();
349: wr = wc.getFrameContents(FRAME_CONTENT);
350:
351: txt = getDeployTable(wr, true);
352:
353: if (txt.indexOf(fileName) == -1) {
354: fail("The file " + fileName + " was not found as deployed.");
355: }
356: }
357:
358: /**
359: * Tear Down cleanUp action
360: * @throws Exception if an error occurs
361: */
362: public void tearDown() throws Exception {
363: super.tearDown();
364: }
365:
366: }
|