1 25 26 package org.objectweb.jonas.jonasadmin.test.service.container; 27 28 import java.io.File ; 29 30 import junit.framework.TestSuite; 31 32 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth; 33 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase; 34 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils; 35 36 import com.meterware.httpunit.HttpUnitOptions; 37 import com.meterware.httpunit.TableCell; 38 import com.meterware.httpunit.WebConversation; 39 import com.meterware.httpunit.WebLink; 40 import com.meterware.httpunit.WebResponse; 41 import com.meterware.httpunit.WebTable; 42 43 48 public class F_JonasAdminApplicationContainer extends JonasAdminTestCase { 49 50 53 private static final String URL_JONASADMIN_APP_CONTAINER = "ListAppContainers.do"; 54 55 58 private static final String URL_JONASADMIN_EAR = "/jonasAdmin/EditEar.do"; 59 60 63 private static final String URL_JONASADMIN_WEB = "/jonasAdmin/service/earWars.jsp"; 64 65 68 private static final String URL_JONASADMIN_JAR = "/jonasAdmin/service/earJars.jsp"; 69 70 73 private static final String URL_JONASADMIN_RAR = "/jonasAdmin/service/earRars.jsp"; 74 75 78 private static final String URL_JONASADMIN_XML = "/jonasAdmin/service/earXmlDeployment.jsp"; 79 80 83 private static final int NUMBER_OF_TABS_WITH_WAR_JAR_RAR = 6; 84 85 88 private static final int NUMBER_OF_TABS_WITHOUT_RAR = 5; 89 90 94 public F_JonasAdminApplicationContainer(String s) { 95 super(s, URL_JONASADMIN); 96 } 97 98 103 public F_JonasAdminApplicationContainer(WebConversation wc, String s) { 104 super(wc, s, URL_JONASADMIN); 105 } 106 107 111 public static void main(String [] args) { 112 113 String testtorun = null; 114 for (int argn = 0; argn < args.length; argn++) { 116 String sArg = args[argn]; 117 if (sArg.equals("-n")) { 118 testtorun = args[++argn]; 119 } 120 } 121 if (testtorun == null) { 122 junit.textui.TestRunner.run(suite()); 123 } else { 124 junit.textui.TestRunner.run(new F_JonasAdminApplicationContainer(testtorun)); 125 } 126 } 127 128 132 public static TestSuite suite() { 133 return new TestSuite(F_JonasAdminApplicationContainer.class); 134 } 135 136 141 public static TestSuite suite(WebConversation wc) { 142 TestSuite suite = new TestSuite(); 143 suite.addTest(new F_JonasAdminApplicationContainer(wc, "testAddEarWithWarJarAndRar")); 144 suite.addTest(new F_JonasAdminApplicationContainer(wc, "testAddEarWithoutRar")); 145 return suite; 146 } 147 148 153 protected void setUp() throws Exception { 154 super.setUp(); 155 156 if (wc.getCurrentPage().getURL() == null) { 157 useWar("jonasAdmin"); 158 try { 160 JonasAdminAuth.doValidAuth(wc, url); 161 } catch (Exception e) { 162 fail("authentification failed : " + e); 163 } 164 } else { 165 try { 167 wc.getFrameContents(FRAME_TREE); 168 } catch (Exception e) { 169 wc.getResponse(urlLogOut); 170 try { 172 JonasAdminAuth.doValidAuth(wc, url); 173 } catch (Exception auth) { 174 fail("authentification failed : " + auth); 175 } 176 } 177 } 178 } 179 180 185 public void testAddEarWithWarJarAndRar() throws Exception { 186 187 WebResponse wr; 188 WebLink link; 189 WebTable table; 190 WebTable tabTable; 191 TableCell selectedCell; 192 TableCell cell; 193 String ear = "earsample"; 194 int selectedTab; 195 int code; 196 JonasAdminUtils utils = new JonasAdminUtils(); 197 198 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 200 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 202 203 if (jProp.isEar() && jProp.isEjb() && jProp.isResource()) { 205 useEar(ear); 207 208 wr = wc.getFrameContents(FRAME_TREE); 210 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_APP_CONTAINER); 211 link.click(); 212 wr = wc.getFrameContents(FRAME_CONTENT); 213 214 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, ear); 216 link.click(); 217 wr = wc.getFrameContents(FRAME_CONTENT); 218 selectedTab = 2; 219 220 table = utils.getTable(wr, 0); 222 cell = table.getTableCell(0,2); 223 assertEquals("It is not the name of the ear file. ", ear + ".ear", cell.getText()); 225 String path = System.getProperty("jonas.base") + File.separator + "apps" + File.separator + ear + ".ear"; 227 assertEquals("It is not the path of the ear file. ", path, table.getTableCell(1,2).getText()); 228 229 tabTable = utils.getTabTable(wr); 231 testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab); 232 assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ", 234 tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER)); 235 assertTrue("The link " + URL_JONASADMIN_WEB + " is not found in the third tab. ", 236 tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB)); 237 assertTrue("The link " + URL_JONASADMIN_JAR + " is not found in the fourth tab. ", 238 tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JAR)); 239 assertTrue("The link " + URL_JONASADMIN_RAR + " is not found in the fifth tab. ", 240 tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_RAR)); 241 assertTrue("The link " + URL_JONASADMIN_XML + " is not found in the sixth tab. ", 242 tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_XML)); 243 244 245 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_WEB); 247 link.click(); 248 wr = wc.getFrameContents(FRAME_CONTENT); 249 selectedTab = 3; 250 251 table = utils.getTable(wr, 0); 253 cell = table.getTableCell(1, 0); 255 assertEquals("It is not the name of the war file. ", "earsample", cell.getText()); 256 link = cell.getLinks()[0]; 258 code = wc.sendRequest(link.getRequest()).getResponseCode(); 259 assertTrue("The file link does not contain 'EditWebApp.do?on='. ", link.getURLString().indexOf("EditWebApp.do?on=") != -1); 260 assertEquals("The link " + link.getURLString() + " is not found. ", 200, code); 261 262 cell = table.getTableCell(1, 1); 264 assertTrue("It is not the path of the war file. ", cell.getText().endsWith("earsample.war")); 265 266 tabTable = utils.getTabTable(wr); 268 testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab); 269 assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ", 271 tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER)); 272 assertTrue("The link " + URL_JONASADMIN_EAR + " is not found in the second tab. ", 273 tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EAR)); 274 assertTrue("The link " + URL_JONASADMIN_JAR + " is not found in the fourth tab. ", 275 tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JAR)); 276 assertTrue("The link " + URL_JONASADMIN_RAR + " is not found in the fifth tab. ", 277 tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_RAR)); 278 assertTrue("The link " + URL_JONASADMIN_XML + " is not found in the sixth tab. ", 279 tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_XML)); 280 281 282 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_JAR); 284 link.click(); 285 wr = wc.getFrameContents(FRAME_CONTENT); 286 selectedTab = 4; 287 288 table = utils.getTable(wr, 0); 290 cell = table.getTableCell(1, 0); 291 assertEquals("It is not the name of the war file. ", "secusb", cell.getText()); 293 link = cell.getLinks()[0]; 295 code = wc.sendRequest(link.getRequest()).getResponseCode(); 296 assertTrue("The file link does not contain 'EditContainer.do?select='. ", cell.getLinks()[0].getURLString().indexOf("EditContainer.do?select=") != -1); 297 assertEquals("The link " + link.getURLString() + " is not found. ", 200, code); 298 299 cell = table.getTableCell(1, 1); 301 assertTrue("It is not the path of the war file. ", cell.getText().endsWith("secusb.jar")); 302 303 tabTable = utils.getTabTable(wr); 305 testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab); 306 assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ", 308 tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER)); 309 assertTrue("The link " + URL_JONASADMIN_EAR + " is not found in the second tab. ", 310 tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EAR)); 311 assertTrue("The link " + URL_JONASADMIN_WEB + " is not found in the third tab. ", 312 tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB)); 313 assertTrue("The link " + URL_JONASADMIN_RAR + " is not found in the fifth tab. ", 314 tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_RAR)); 315 assertTrue("The link " + URL_JONASADMIN_XML + " is not found in the sixth tab. ", 316 tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_XML)); 317 318 319 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_RAR); 321 link.click(); 322 wr = wc.getFrameContents(FRAME_CONTENT); 323 selectedTab = 5; 324 325 table = utils.getTable(wr, 0); 327 cell = table.getTableCell(1, 0); 328 assertEquals("It is not the name of the rar file. ", "earsample.ra-sample", cell.getText()); 330 link = cell.getLinks()[0]; 332 code = wc.sendRequest(link.getRequest()).getResponseCode(); 333 assertTrue("The file link does not contain 'EditResourceAdapter.do?select='. ", cell.getLinks()[0].getURLString().indexOf("EditResourceAdapter.do?select=") != -1); 334 assertEquals("The link " + link.getURLString() + " is not found. ", 200, code); 335 336 cell = table.getTableCell(1, 1); 338 assertTrue("It is not the path of the rar file. ", cell.getText().endsWith("ra-sample.rar")); 339 340 tabTable = utils.getTabTable(wr); 342 testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab); 343 assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ", 345 tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER)); 346 assertTrue("The link " + URL_JONASADMIN_EAR + " is not found in the second tab. ", 347 tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EAR)); 348 assertTrue("The link " + URL_JONASADMIN_WEB + " is not found in the third tab. ", 349 tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB)); 350 assertTrue("The link " + URL_JONASADMIN_JAR + " is not found in the fourth tab. ", 351 tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JAR)); 352 assertTrue("The link " + URL_JONASADMIN_XML + " is not found in the sixth tab. ", 353 tabTable.getTableCell(0, 10).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_XML)); 354 355 356 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_XML); 358 link.click(); 359 wr = wc.getFrameContents(FRAME_CONTENT); 360 selectedTab = 6; 361 362 tabTable = utils.getTabTable(wr); 364 testTabs(tabTable, NUMBER_OF_TABS_WITH_WAR_JAR_RAR, selectedTab); 365 assertTrue("The link " + URL_JONASADMIN_APP_CONTAINER + " is not found in the first tab. ", 367 tabTable.getTableCell(0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_APP_CONTAINER)); 368 assertTrue("The link " + URL_JONASADMIN_EAR + " is not found in the second tab. ", 369 tabTable.getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_EAR)); 370 assertTrue("The link " + URL_JONASADMIN_WEB + " is not found in the third tab. ", 371 tabTable.getTableCell(0, 4).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_WEB)); 372 assertTrue("The link " + URL_JONASADMIN_JAR + " is not found in the fourth tab. ", 373 tabTable.getTableCell(0, 6).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_JAR)); 374 assertTrue("The link " + URL_JONASADMIN_RAR + " is not found in the fifth tab. ", 375 tabTable.getTableCell(0, 8).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_RAR)); 376 } 377 } 378 379 384 public void testAddEarWithoutRar() throws Exception { 385 386 WebResponse wr; 387 WebLink link; 388 WebTable tabTable; 389 String ear = "alarm"; 390 JonasAdminUtils utils = new JonasAdminUtils(); 391 392 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 394 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 396 397 if (jProp.isEar() && jProp.isEjb() && jProp.isResource()) { 399 useEar(ear); 401 402 wr = wc.getFrameContents(FRAME_TREE); 404 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_APP_CONTAINER); 405 link.click(); 406 wr = wc.getFrameContents(FRAME_CONTENT); 407 408 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, ear); 410 link.click(); 411 wr = wc.getFrameContents(FRAME_CONTENT); 412 413 tabTable = utils.getTabTable(wr); 415 assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR + " tabs. ", 417 NUMBER_OF_TABS_WITHOUT_RAR, (tabTable.getColumnCount() + 1) / 2); 418 419 420 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_WEB); 422 link.click(); 423 wr = wc.getFrameContents(FRAME_CONTENT); 424 425 tabTable = utils.getTabTable(wr); 427 assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR + " tabs. ", 429 NUMBER_OF_TABS_WITHOUT_RAR, (tabTable.getColumnCount() + 1) / 2); 430 431 432 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_JAR); 434 link.click(); 435 wr = wc.getFrameContents(FRAME_CONTENT); 436 437 tabTable = utils.getTabTable(wr); 439 assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR + " tabs. ", 441 NUMBER_OF_TABS_WITHOUT_RAR, (tabTable.getColumnCount() + 1) / 2); 442 443 444 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_XML); 446 link.click(); 447 wr = wc.getFrameContents(FRAME_CONTENT); 448 449 tabTable = utils.getTabTable(wr); 451 assertEquals("There are not " + NUMBER_OF_TABS_WITHOUT_RAR + " tabs. ", 453 NUMBER_OF_TABS_WITHOUT_RAR, (tabTable.getColumnCount() + 1) / 2); 454 } 455 } 456 457 463 private void testTabs(WebTable tabTable, int nbTabs, int selectedTab) { 464 TableCell selectedCell; 465 assertEquals("There are not " + nbTabs + " tabs. ", 467 nbTabs, (tabTable.getColumnCount() + 1) / 2); 468 selectedCell = tabTable.getTableCell(1, (selectedTab * 2) - 2); 470 assertEquals("It is not the selected tab. ", 1, selectedCell.getElementsWithAttribute("src", "/jonasAdmin/images/dot.gif").length); 471 } 472 473 } 474 | Popular Tags |