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_JonasAdminDeployRar.java 8111 2006-03-10 13:59:44Z danesa $
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 rars
044: * @author Paul Kemler
045: */
046: public class F_JonasAdminDeployRar extends JonasAdminTestCase {
047:
048: /**
049: * URL of the deployment of RARs
050: */
051: protected static final String URL_JONASADMIN_DEPLOYRAR = "EditDeploy.do?type=rar";
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 = 4;
072:
073: /**
074: * number of tabs when you are in the CONFIRM tabs
075: */
076: private static final int NUMBER_OF_TABS_FOR_CONFIRM = 5;
077:
078: /**
079: * Constructor with a specified name
080: * @param s name
081: */
082: public F_JonasAdminDeployRar(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_JonasAdminDeployRar(
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_JonasAdminDeployRar.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 rar
174: * with jonaAdmin If it was undeployed, deploy it again with jonasAdmin Test
175: * with rar ErsatzEIS.rar
176: * @throws Exception if an error occurs
177: */
178: public void testTryDeployUndeployRars() 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: if (jProp.isResource()) {
196: // First load Rar
197: String name = "autoload" + File.separator + "ErsatzEIS";
198: String fileName = name + ".rar";
199: useRar(name);
200:
201: // Go to Deployment/RarModules
202: wr = wc.getFrameContents(FRAME_TREE);
203: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
204: URL_JONASADMIN_DEPLOYRAR);
205: link.click();
206: wr = wc.getFrameContents(FRAME_CONTENT);
207: selectedTab = 1;
208:
209: // Verify tabs
210: tabTable = utils.getTabTable(wr);
211: testTabs(tabTable, NUMBER_OF_TABS_FOR_DEPLOYMENT,
212: selectedTab, "Problem in 'Deployment' tab.");
213: // - links
214: assertTrue("The link " + URL_JONASADMIN_UPLOAD
215: + " is not found in the second tab. ", tabTable
216: .getTableCell(0, 2).getLinks()[0].getURLString()
217: .endsWith(URL_JONASADMIN_UPLOAD));
218: assertTrue("The link " + URL_JONASADMIN_REMOVE
219: + " is not found in the third tab. ", tabTable
220: .getTableCell(0, 4).getLinks()[0].getURLString()
221: .endsWith(URL_JONASADMIN_REMOVE));
222:
223: String txt = getDeployTable(wr, true);
224:
225: if (txt.indexOf(fileName) == -1) {
226: fail("The file" + fileName
227: + " was not found as deployed.");
228: }
229:
230: // Undeploy
231: WebForm[] webForms = wr.getForms();
232: WebForm webForm = webForms[0];
233:
234: String params = webForm.getParameterValue("undeploy");
235: WebForm.Scriptable script = webForm.getScriptableObject();
236: if (params.length() == 0) {
237: params += fileName;
238: } else {
239: params += "," + fileName;
240: }
241: script.setParameterValue("undeploy", params);
242:
243: SubmitButton button = webForm.getSubmitButtons()[0];
244: button.click();
245:
246: // Confirm
247: WebResponse submitUndeploy = wc
248: .getFrameContents(FRAME_CONTENT);
249: selectedTab = 2;
250:
251: // Verify tabs
252: tabTable = utils.getTabTable(submitUndeploy);
253: testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab,
254: "Problem in 'Confirm' tab.");
255: // - links
256: assertTrue("The link " + URL_JONASADMIN_DEPLOY
257: + " is not found in the first tab. ", tabTable
258: .getTableCell(0, 0).getLinks()[0].getURLString()
259: .endsWith(URL_JONASADMIN_DEPLOY));
260: assertTrue("The link " + URL_JONASADMIN_UPLOAD
261: + " is not found in the third tab. ", tabTable
262: .getTableCell(0, 4).getLinks()[0].getURLString()
263: .endsWith(URL_JONASADMIN_UPLOAD));
264: assertTrue("The link " + URL_JONASADMIN_REMOVE
265: + " is not found in the fourth tab. ", tabTable
266: .getTableCell(0, 6).getLinks()[0].getURLString()
267: .endsWith(URL_JONASADMIN_REMOVE));
268:
269: webForms = submitUndeploy.getForms();
270: webForm = webForms[0];
271:
272: button = webForm.getSubmitButtons()[0];
273: button.click();
274: wr = wc.getFrameContents(FRAME_CONTENT);
275:
276: // Verify tabs
277: tabTable = utils.getTabTable(wr);
278: testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab,
279: "Problem in 'Result' tab.");
280: // - links
281: assertTrue("The link " + URL_JONASADMIN_DEPLOY
282: + " is not found in the first tab. ", tabTable
283: .getTableCell(0, 0).getLinks()[0].getURLString()
284: .endsWith(URL_JONASADMIN_DEPLOY));
285: assertTrue("The link " + URL_JONASADMIN_UPLOAD
286: + " is not found in the third tab. ", tabTable
287: .getTableCell(0, 4).getLinks()[0].getURLString()
288: .endsWith(URL_JONASADMIN_UPLOAD));
289: assertTrue("The link " + URL_JONASADMIN_REMOVE
290: + " is not found in the fourth tab. ", tabTable
291: .getTableCell(0, 6).getLinks()[0].getURLString()
292: .endsWith(URL_JONASADMIN_REMOVE));
293:
294: // Go back to Deployment
295: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
296: URL_JONASADMIN_DEPLOY);
297: link.click();
298: wr = wc.getFrameContents(FRAME_CONTENT);
299: selectedTab = 1;
300:
301: // Verify tabs
302: tabTable = utils.getTabTable(wr);
303: testTabs(tabTable, NUMBER_OF_TABS_FOR_DEPLOYMENT,
304: selectedTab, "Problem in 'Deployment' tab.");
305: // - links
306: assertTrue("The link " + URL_JONASADMIN_UPLOAD
307: + " is not found in the second tab. ", tabTable
308: .getTableCell(0, 2).getLinks()[0].getURLString()
309: .endsWith(URL_JONASADMIN_UPLOAD));
310: assertTrue("The link " + URL_JONASADMIN_REMOVE
311: + " is not found in the third tab. ", tabTable
312: .getTableCell(0, 4).getLinks()[0].getURLString()
313: .endsWith(URL_JONASADMIN_REMOVE));
314:
315: txt = getDeployTable(wr, true);
316:
317: if (txt.indexOf(fileName) != -1) {
318: fail("The jonasAdmin webApp has not removed. "
319: + fileName);
320: }
321:
322: // now deploy
323: webForms = wr.getForms();
324: webForm = webForms[0];
325:
326: params = webForm.getParameterValue("deploy");
327: script = webForm.getScriptableObject();
328:
329: if (params.length() == 0) {
330: params += fileName;
331: } else {
332: params += "," + fileName;
333: }
334:
335: script.setParameterValue("deploy", params);
336: button = webForm.getSubmitButtons()[0];
337: button.click();
338:
339: // Confirm
340: submitUndeploy = wc.getFrameContents(FRAME_CONTENT);
341: // war is in the table
342: webForms = submitUndeploy.getForms();
343: webForm = webForms[0];
344:
345: button = webForm.getSubmitButtons()[0];
346: button.click();
347:
348: // Go back to Deployment
349: wr = wc.getFrameContents(FRAME_CONTENT);
350: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
351: URL_JONASADMIN_DEPLOY);
352: link.click();
353: wr = wc.getFrameContents(FRAME_CONTENT);
354:
355: txt = getDeployTable(wr, true);
356:
357: if (txt.indexOf(fileName) == -1) {
358: fail("The file " + fileName
359: + " was not found as deployed.");
360: }
361: }
362: }
363:
364: /**
365: * Tear Down cleanUp action
366: * @throws Exception if an error occurs
367: */
368: public void tearDown() throws Exception {
369: super.tearDown();
370: }
371:
372: }
|