KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > catalina > F_JonasAdminConnector


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_JonasAdminConnector.java,v 1.3 2005/07/12 13:20:02 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.catalina;
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 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
33 import org.xml.sax.SAXException JavaDoc;
34
35 import com.meterware.httpunit.HTMLElement;
36 import com.meterware.httpunit.HttpUnitOptions;
37 import com.meterware.httpunit.TableCell;
38 import com.meterware.httpunit.WebConversation;
39 import com.meterware.httpunit.WebForm;
40 import com.meterware.httpunit.WebLink;
41 import com.meterware.httpunit.WebResponse;
42 import com.meterware.httpunit.WebTable;
43
44 /**
45  * Define a class to test the JOnAS Admin console Test connectors
46  * @author Paul Kemler
47  */

48 public class F_JonasAdminConnector extends JonasAdminTestCase {
49
50     /**
51      * URL of Jonas Logger
52      */

53     private static final String JavaDoc URL_JONASADMIN_JONAS_LOGGER = "/EditLoggingJonas.do";
54
55     /**
56      * URL to modify a connector
57      */

58     private static final String JavaDoc URL_JONASADMIN_MODIFY_CONNECTOR = "EditCatalinaConnector.do?select=jonas%3Atype%3DConnector%2Cport%3D";
59
60     /**
61      * INPUT Checkbox
62      */

63     private static final String JavaDoc INPUT_CHECKBOX = "input type=\"checkbox\"";
64
65     /**
66      * Title port
67      */

68     private static final String JavaDoc TITLE_PORT = "Port";
69
70     /**
71      * Title address
72      */

73     private static final String JavaDoc TITLE_ADDRESS = "Address";
74
75     /**
76      * Title type
77      */

78     private static final String JavaDoc TITLE_TYPE = "Type";
79
80     /**
81      * Button 'Save'
82      */

83     private static final String JavaDoc BUTTON_SAVE = "/EditServletServer.do?forward=ActionListCatalinaConnectors";
84
85     /**
86      * SUCCESS CODE
87      */

88     private static final int HTTP_SUCCESS_CODE = 200;
89
90     /**
91      * A 2nd connection to jonasAdmin
92      */

93     private static WebConversation wc2 = new WebConversation();
94
95     /**
96      * Constructor with a specified name
97      * @param s name
98      */

99     public F_JonasAdminConnector(String JavaDoc s) {
100         super(s, URL_JONASADMIN);
101     }
102
103     /**
104      * Constructor with a specified name
105      * @param wc the WebConversation of the suite test
106      * @param s name
107      */

108     public F_JonasAdminConnector(WebConversation wc, String JavaDoc s) {
109         super(wc, s, URL_JONASADMIN);
110     }
111
112     /**
113      * Main method
114      * @param args the arguments
115      */

116     public static void main(String JavaDoc[] args) {
117
118         String JavaDoc testtorun = null;
119         // Get args
120
for (int argn = 0; argn < args.length; argn++) {
121             String JavaDoc sArg = args[argn];
122             if (sArg.equals("-n")) {
123                 testtorun = args[++argn];
124             }
125         }
126         if (testtorun == null) {
127             junit.textui.TestRunner.run(suite());
128         } else {
129             junit.textui.TestRunner.run(new F_JonasAdminConnector(testtorun));
130         }
131     }
132
133     /**
134      * Get a new TestSuite for this class
135      * @return a new TestSuite for this class
136      */

137     public static TestSuite suite() {
138         return new TestSuite(F_JonasAdminConnector.class);
139     }
140
141     /**
142      * Get a new TestSuite for this class
143      * @param wc the WebConversation
144      * @return a new TestSuite for this class with the WebConversation instance
145      */

146     public static TestSuite suite(WebConversation wc) {
147         TestSuite suite = new TestSuite();
148         suite.addTest(new F_JonasAdminConnector(wc, "testConnectors"));
149         return suite;
150     }
151
152     /**
153      * Setup need for these tests jonasAdmin is required
154      * @throws Exception if it fails
155      */

156     protected void setUp() throws Exception JavaDoc {
157         super.setUp();
158
159         if (wc.getCurrentPage().getURL() == null) {
160             useWar("jonasAdmin");
161             // login to jonas admin
162
try {
163                 JonasAdminAuth.doValidAuth(wc, url);
164             } catch (Exception JavaDoc e) {
165                 fail("authentification failed : " + e);
166             }
167         } else {
168             // if there was an error, the connection must be restablished
169
try {
170                 wc.getFrameContents(FRAME_TREE);
171             } catch (Exception JavaDoc e) {
172                 wc.getResponse(urlLogOut);
173                 // login to jonas admin
174
try {
175                     JonasAdminAuth.doValidAuth(wc, url);
176                 } catch (Exception JavaDoc auth) {
177                     fail("authentification failed : " + auth);
178                 }
179             }
180         }
181     }
182
183     /**
184      * Test connectors
185      * @throws Exception if error occurs
186      */

187     public void testConnectors() throws Exception JavaDoc {
188
189         WebResponse wr;
190         WebLink link;
191         WebTable table;
192         WebForm form;
193
194         int row;
195         int portColumn;
196         int addressColumn;
197         int typeColumn;
198         int rowHttp;
199         int rowHttps;
200         int rowAjp;
201         String JavaDoc portHttp;
202         String JavaDoc portHttps;
203         String JavaDoc portAjp;
204         String JavaDoc testUrl;
205         JonasAdminUtils utils = new JonasAdminUtils();
206
207         // Disable errors of javascript
208
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
209         // Disable exception thrown on error status
210
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
211
212         // OPEN A SECOND CONNECTION
213
// login to jonas admin
214
try {
215             JonasAdminAuth.doValidAuth(wc2, url);
216         } catch (Exception JavaDoc e) {
217             fail("authentification failed : " + e);
218         }
219
220         if (jProp.isCatalina()) {
221             wr = ConnectorUtils.getConnectorPage(wc);
222             table = utils.getTable(wr, 3);
223             portColumn = utils.getColumn(TITLE_PORT, table).intValue();
224             if (portColumn == -1) {
225                 throw new IllegalThreadStateException JavaDoc("There is no column, which contains '" + TITLE_PORT + "'. ");
226             }
227             addressColumn = utils.getColumn(TITLE_ADDRESS, table).intValue();
228             if (portColumn == -1) {
229                 throw new IllegalThreadStateException JavaDoc("There is no column, which contains '" + TITLE_ADDRESS + "'. ");
230             }
231             typeColumn = utils.getColumn(TITLE_TYPE, table).intValue();
232             if (portColumn == -1) {
233                 throw new IllegalThreadStateException JavaDoc("There is no column, which contains '" + TITLE_TYPE + "'. ");
234             }
235
236             // Verify 'remove' button
237
if (table.getRowCount() == 2) {
238                 assertFalse("There is a remove button. ", wr.getText().indexOf("'remove'") != -1);
239                 assertFalse("There is a checkbox. ", wr.getText().indexOf(INPUT_CHECKBOX) != -1);
240             } else {
241                 assertTrue("There is no remove button but there is no one and only one connector. ", wr.getText()
242                         .indexOf("'remove'") != -1);
243                 assertTrue("There is no checkbox but there is no one and only one connector. ", wr.getText().indexOf(
244                         INPUT_CHECKBOX) != -1);
245             }
246
247             // Open connectors branch in the tree to verify if a connector is
248
// well added.
249
wr = wc.getFrameContents(FRAME_TREE);
250             table = wr.getTables()[0];
251             int rowConnectors = utils.getFirstRow("Connectors", table, 6).intValue();
252             if (rowConnectors == -1) {
253                 throw new IllegalThreadStateException JavaDoc("Connectors was not found in the tree. ");
254             }
255             TableCell cell = table.getTableCell(rowConnectors, 4);
256             HTMLElement[] elements = cell.getElementsWithAttribute("src", "images/tree/node_close_last.gif");
257             if (elements.length == 1) {
258                 if (elements[0].getAttribute("src").indexOf("node_close") != -1) {
259                     link = cell.getLinks()[0];
260                     link.click();
261                 }
262             }
263
264             // 1-Create new connectors
265
portHttp = ConnectorUtils.createNewConnector(wc, "http");
266             // Verify
267
wr = wc.getFrameContents(FRAME_TREE);
268             assertTrue("The port " + portHttp + " is not found in the tree. ", wr.getText().indexOf(portHttp) != -1);
269             wr = wc.getFrameContents(FRAME_CONTENT);
270             assertTrue("It is not the connectors.jsp page. ", wr.getText().indexOf("catalina/connectors.jsp") != -1);
271
272             wr = ConnectorUtils.getConnectorPage(wc);
273             table = utils.getTable(wr, 3);
274             form = wr.getForms()[0];
275             row = utils.getFirstRow(port, table, portColumn).intValue();
276             if (row == -1) {
277                 throw new IllegalThreadStateException JavaDoc("There is no row, which contains '" + port
278                         + "' in the 'Port' column. ");
279             }
280             rowHttp = utils.getFirstRow(portHttp, table, portColumn).intValue();
281             if (rowHttp == -1) {
282                 throw new IllegalThreadStateException JavaDoc("There is no row, which contains '" + portHttp
283                         + "' in the 'Port' column. ");
284             }
285             assertEquals("There is no the correct number of connectors. ", 3, table.getRowCount());
286             assertTrue("There is no remove button. ", wr.getText().indexOf("'remove'") != -1);
287             assertEquals("There is no the correct number of parameters in the form. ", 2,
288                     form.getParameterNames().length);
289             assertTrue("There is a checkbox for " + port + "port. ", table.getTableCell(row, 0).getElementsWithName(
290                     "selectedItems").length == 0);
291             assertEquals("There is no checkbox for " + portHttp + "port. ", 1, table.getTableCell(rowHttp, 0)
292                     .getElementsWithName("selectedItems").length);
293             assertEquals("The connector address is not null. ", "", table.getTableCell(rowHttp, addressColumn)
294                     .getText());
295             assertEquals("The connector type is not 'HTTP'. ", "HTTP", table.getTableCell(rowHttp, typeColumn)
296                     .getText());
297             testUrl = "http://localhost:" + portHttp + "/jonasAdmin/";
298             wr = wc2.getResponse(testUrl);
299             assertEquals("A code of 200 (success) should be returned. ", HTTP_SUCCESS_CODE, wr.getResponseCode());
300
301             portHttps = ConnectorUtils.createNewConnector(wc, "https");
302             // Verify
303
wr = ConnectorUtils.getConnectorPage(wc);
304             table = utils.getTable(wr, 3);
305             form = wr.getForms()[0];
306             row = utils.getFirstRow(port, table, portColumn).intValue();
307             if (row == -1) {
308                 throw new IllegalThreadStateException JavaDoc("There is no row, which contains '" + port
309                         + "' in the 'Port' column. ");
310             }
311             rowHttps = utils.getFirstRow(portHttps, table, portColumn).intValue();
312             if (rowHttps == -1) {
313                 throw new IllegalThreadStateException JavaDoc("There is no row, which contains '" + portHttps
314                         + "' in the 'Port' column. ");
315             }
316             assertEquals("There is no the correct number of connectors. ", 4, table.getRowCount());
317             assertTrue("There is no remove button. ", wr.getText().indexOf("'remove'") != -1);
318             assertEquals("There is no the correct number of parameters in the form. ", 2,
319                     form.getParameterNames().length);
320             assertEquals("There is no checkbox for " + portHttps + "port. ", 1, table.getTableCell(rowHttps, 0)
321                     .getElementsWithName("selectedItems").length);
322             assertEquals("The connector address is not null. ", "", table.getTableCell(rowHttps, addressColumn)
323                     .getText());
324             assertEquals("The connector type is not 'HTTPS'. ", "HTTPS", table.getTableCell(rowHttps, typeColumn)
325                     .getText());
326
327             portAjp = ConnectorUtils.createNewConnector(wc, "ajp");
328             // Verify
329
wr = ConnectorUtils.getConnectorPage(wc);
330             table = utils.getTable(wr, 3);
331             form = wr.getForms()[0];
332             row = utils.getFirstRow(port, table, portColumn).intValue();
333             if (row == -1) {
334                 throw new IllegalThreadStateException JavaDoc("There is no row, which contains '" + port
335                         + "' in the 'Port' column. ");
336             }
337             rowAjp = utils.getFirstRow(portAjp, table, portColumn).intValue();
338             if (rowAjp == -1) {
339                 throw new IllegalThreadStateException JavaDoc("There is no row, which contains '" + portAjp
340                         + "' in the 'Port' column. ");
341             }
342             assertEquals("There is no the correct number of connectors. ", 5, table.getRowCount());
343             assertTrue("There is no remove button. ", wr.getText().indexOf("'remove'") != -1);
344             assertEquals("There is no the correct number of parameters in the form. ", 2,
345                     form.getParameterNames().length);
346             assertEquals("There is no checkbox for " + portAjp + "port. ", 1, table.getTableCell(rowAjp, 0)
347                     .getElementsWithName("selectedItems").length);
348             assertEquals("The connector address is not null. ", "", table.getTableCell(rowAjp, addressColumn).getText());
349             assertEquals("The connector type is not 'AJP'. ", "AJP", table.getTableCell(rowAjp, typeColumn).getText());
350
351             // 2-Modify connectors
352
// Get form
353
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_MODIFY_CONNECTOR + portHttp);
354             if (link != null) {
355                 link.click();
356             } else {
357                 throw new IllegalThreadStateException JavaDoc("The link " + URL_JONASADMIN_MODIFY_CONNECTOR + portHttp
358                         + " is not found. ");
359             }
360             wr = wc.getFrameContents(FRAME_CONTENT);
361
362             table = utils.getTable(wr, 1);
363             // Verify
364
assertTrue("The value of 'Type' row is not 'HTTP'", table.getTableCell(0, 2).getText().indexOf("HTTP") != -1);
365             assertTrue("The value of 'Scheme' row is not 'http'", table.getTableCell(1, 2).getText().indexOf("http") != -1);
366             assertTrue("The value of 'Coyote Protocol Handler' row is not 'HTTP/1.1'", table.getTableCell(2, 2).getText().indexOf("HTTP/1.1") != -1);
367             assertTrue("The value of 'Secure (SSL) Connector' row is not 'false'", table.getTableCell(3, 2).getText().indexOf("false") != -1);
368
369             table = utils.getTable(wr, 4);
370             // Verify
371
assertTrue("The value of 'Port Number' row is not '"+ portHttp +"'", table.getTableCell(0, 2).getText().indexOf(portHttp) != -1);
372
373             table = utils.getTable(wr, 10);
374             // Verify
375
assertTrue("The value of 'Minimum Number of Processors' row is not '5'", table.getTableCell(0, 2).getText().indexOf("5") != -1);
376             assertTrue("The value of 'Maximum Number of Processors' row is not '5'", table.getTableCell(1, 2).getText().indexOf("20") != -1);
377
378             form = wr.getForms()[0];
379             ConnectorUtils.modifyHttpConnector(form, "250", "1048576", "10000", "", "2048", "", "9043", "50",
380                     "10", "25", "", "0", "true", "true", "true", "true", "true", "false", "5");
381
382             // Verify
383
wr = wc.getFrameContents(FRAME_CONTENT);
384             verifyConnector(wr, "250", "1048576", "10000", "", "2048", "", "9043", "50",
385                     "10", "25", "", "0", "true", "true", "true", "true", "true", "false", "5");
386
387             // 3-Remove connectors
388
String JavaDoc[] tabPort = {portHttp, portHttps, portAjp};
389             ConnectorUtils.deleteConnectors(wc, tabPort);
390             // Verify
391
wr = ConnectorUtils.getConnectorPage(wc);
392             table = utils.getTable(wr, 3);
393             assertEquals("The number of connectors is not 1. ", 2, table.getRowCount());
394
395             // 4-Button 'Save'
396
wr = wc.getFrameContents(FRAME_CONTENT);
397             link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, BUTTON_SAVE);
398             if (link == null) {
399                 throw new IllegalStateException JavaDoc("No link found for button : '" + BUTTON_SAVE + "'.");
400             }
401             wr = link.click();
402             assertTrue("It is not the servletServer.jsp page. ",
403                     wr.getText().indexOf("jonasserver/servletServer.jsp") != -1);
404         }
405     }
406
407     /**
408      * Verify value of parameters in connector form
409      * @param wr the content frame
410      * @param acceptCountText value of the acceptCountText param
411      * @param maxPostSizeText value of the maxPostSizeText param
412      * @param connTimeOutText value of the connTimeOutText param
413      * @param URIEncoding value of the URIEncoding param
414      * @param bufferSizeText value of the bufferSizeText param
415      * @param address value of the address param
416      * @param redirectPortText value of the redirectPortText param
417      * @param maxThreadsText value of the maxThreadsText param
418      * @param minSpareThreadsText value of the minSpareThreadsText param
419      * @param maxSpareThreadsText value of the maxSpareThreadsText param
420      * @param proxyName value of the proxyName param
421      * @param proxyPortText value of the proxyPortText param
422      * @param allowTrace value of the allowTrace param
423      * @param emptySessionPath value of the emptySessionPath param
424      * @param enableLookups value of the enableLookups param
425      * @param useBodyEncodingForURI value of the useBodyEncodingForURI param
426      * @param xpoweredBy value of the xpoweredBy param
427      * @param tcpNoDelay value of the tcpNoDelay param
428      * @param debugLvl value of the debugLvl param
429      * @throws SAXException if there is not a form.
430      */

431     private void verifyConnector(WebResponse wr, String JavaDoc acceptCountText,
432             String JavaDoc maxPostSizeText, String JavaDoc connTimeOutText, String JavaDoc URIEncoding, String JavaDoc bufferSizeText, String JavaDoc address,
433             String JavaDoc redirectPortText, String JavaDoc maxThreadsText, String JavaDoc minSpareThreadsText, String JavaDoc maxSpareThreadsText,
434             String JavaDoc proxyName, String JavaDoc proxyPortText, String JavaDoc allowTrace, String JavaDoc emptySessionPath, String JavaDoc enableLookups,
435             String JavaDoc useBodyEncodingForURI, String JavaDoc xpoweredBy, String JavaDoc tcpNoDelay, String JavaDoc debugLvl) throws SAXException JavaDoc {
436         WebForm form = wr.getForms()[0];
437         assertEquals("Accept count value is not" + acceptCountText + ". ", acceptCountText, form.getParameterValue("acceptCountText"));
438         assertEquals("Max Bytes in a Post value is not" + maxPostSizeText + ". ", maxPostSizeText, form.getParameterValue("maxPostSizeText"));
439         assertEquals("Connection Timeout value is not" + connTimeOutText + ". ", connTimeOutText, form.getParameterValue("connTimeOutText"));
440         assertEquals("URI Encoding value is not" + URIEncoding + ". ", URIEncoding, form.getParameterValue("URIEncoding"));
441         assertEquals("Default Buffer Size value is not" + bufferSizeText + ". ", bufferSizeText, form.getParameterValue("bufferSizeText"));
442         assertEquals("IP Address value is not" + address + ". ", address, form.getParameterValue("address"));
443         assertEquals("Redirect Port Number value is not" + redirectPortText + ". ", redirectPortText, form.getParameterValue("redirectPortText"));
444         assertEquals("Maximum Threads value is not" + maxThreadsText + ". ", maxThreadsText, form.getParameterValue("maxThreadsText"));
445         assertEquals("Minimum Spare Threads value is not" + minSpareThreadsText + ". ", minSpareThreadsText, form.getParameterValue("minSpareThreadsText"));
446         assertEquals("Maximum Spare Threads value is not" + maxSpareThreadsText + ". ", maxSpareThreadsText, form.getParameterValue("maxSpareThreadsText"));
447         assertEquals("Proxy Name value is not" + proxyName + ". ", proxyName, form.getParameterValue("proxyName"));
448         assertEquals("Proxy Port Number value is not" + proxyPortText + ". ", proxyPortText, form.getParameterValue("proxyPortText"));
449         assertEquals("Allow Trace value is not" + allowTrace + ". ", allowTrace, form.getParameterValue("allowTrace"));
450         assertEquals("Empty Session Path value is not" + emptySessionPath + ". ", emptySessionPath, form.getParameterValue("emptySessionPath"));
451         assertEquals("Enable DNS Lookups value is not" + enableLookups + ". ", enableLookups, form.getParameterValue("enableLookups"));
452         assertEquals("Use Body Encoding for URI value is not" + useBodyEncodingForURI + ". ", useBodyEncodingForURI, form.getParameterValue("useBodyEncodingForURI"));
453         assertEquals("X-Powered-By Generation Enabled value is not" + xpoweredBy + ". ", xpoweredBy, form.getParameterValue("xpoweredBy"));
454         assertEquals("Should we use TCP no delay value is not" + tcpNoDelay + ". ", tcpNoDelay, form.getParameterValue("tcpNoDelay"));
455         assertEquals("Debug Level value is not" + debugLvl + ". ", debugLvl, form.getParameterValue("debugLvl"));
456     }
457 }
458
Popular Tags