1 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 ; 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 48 public class F_JonasAdminConnector extends JonasAdminTestCase { 49 50 53 private static final String URL_JONASADMIN_JONAS_LOGGER = "/EditLoggingJonas.do"; 54 55 58 private static final String URL_JONASADMIN_MODIFY_CONNECTOR = "EditCatalinaConnector.do?select=jonas%3Atype%3DConnector%2Cport%3D"; 59 60 63 private static final String INPUT_CHECKBOX = "input type=\"checkbox\""; 64 65 68 private static final String TITLE_PORT = "Port"; 69 70 73 private static final String TITLE_ADDRESS = "Address"; 74 75 78 private static final String TITLE_TYPE = "Type"; 79 80 83 private static final String BUTTON_SAVE = "/EditServletServer.do?forward=ActionListCatalinaConnectors"; 84 85 88 private static final int HTTP_SUCCESS_CODE = 200; 89 90 93 private static WebConversation wc2 = new WebConversation(); 94 95 99 public F_JonasAdminConnector(String s) { 100 super(s, URL_JONASADMIN); 101 } 102 103 108 public F_JonasAdminConnector(WebConversation wc, String s) { 109 super(wc, s, URL_JONASADMIN); 110 } 111 112 116 public static void main(String [] args) { 117 118 String testtorun = null; 119 for (int argn = 0; argn < args.length; argn++) { 121 String 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 137 public static TestSuite suite() { 138 return new TestSuite(F_JonasAdminConnector.class); 139 } 140 141 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 156 protected void setUp() throws Exception { 157 super.setUp(); 158 159 if (wc.getCurrentPage().getURL() == null) { 160 useWar("jonasAdmin"); 161 try { 163 JonasAdminAuth.doValidAuth(wc, url); 164 } catch (Exception e) { 165 fail("authentification failed : " + e); 166 } 167 } else { 168 try { 170 wc.getFrameContents(FRAME_TREE); 171 } catch (Exception e) { 172 wc.getResponse(urlLogOut); 173 try { 175 JonasAdminAuth.doValidAuth(wc, url); 176 } catch (Exception auth) { 177 fail("authentification failed : " + auth); 178 } 179 } 180 } 181 } 182 183 187 public void testConnectors() throws Exception { 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 portHttp; 202 String portHttps; 203 String portAjp; 204 String testUrl; 205 JonasAdminUtils utils = new JonasAdminUtils(); 206 207 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 209 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 211 212 try { 215 JonasAdminAuth.doValidAuth(wc2, url); 216 } catch (Exception 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 ("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 ("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 ("There is no column, which contains '" + TITLE_TYPE + "'. "); 234 } 235 236 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 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 ("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 portHttp = ConnectorUtils.createNewConnector(wc, "http"); 266 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 ("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 ("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 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 ("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 ("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 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 ("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 ("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 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 ("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 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 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 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 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 String [] tabPort = {portHttp, portHttps, portAjp}; 389 ConnectorUtils.deleteConnectors(wc, tabPort); 390 wr = ConnectorUtils.getConnectorPage(wc); 392 table = utils.getTable(wr, 3); 393 assertEquals("The number of connectors is not 1. ", 2, table.getRowCount()); 394 395 wr = wc.getFrameContents(FRAME_CONTENT); 397 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, BUTTON_SAVE); 398 if (link == null) { 399 throw new IllegalStateException ("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 431 private void verifyConnector(WebResponse wr, String acceptCountText, 432 String maxPostSizeText, String connTimeOutText, String URIEncoding, String bufferSizeText, String address, 433 String redirectPortText, String maxThreadsText, String minSpareThreadsText, String maxSpareThreadsText, 434 String proxyName, String proxyPortText, String allowTrace, String emptySessionPath, String enableLookups, 435 String useBodyEncodingForURI, String xpoweredBy, String tcpNoDelay, String debugLvl) throws SAXException { 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 |