1 25 26 package org.objectweb.jonas.jonasadmin.test.jonasserver; 27 28 import java.io.IOException ; 29 import java.net.MalformedURLException ; 30 31 import junit.framework.TestSuite; 32 33 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth; 34 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase; 35 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils; 36 import org.objectweb.jonas_lib.version.Version; 37 import org.xml.sax.SAXException ; 38 39 import com.meterware.httpunit.HttpUnitOptions; 40 import com.meterware.httpunit.WebConversation; 41 import com.meterware.httpunit.WebLink; 42 import com.meterware.httpunit.WebResponse; 43 import com.meterware.httpunit.WebTable; 44 45 50 public class F_JonasAdminInfoServer extends JonasAdminTestCase { 51 52 55 private static final String URL_JONASADMIN_SERVER = "EditJonasServer.do"; 56 57 60 private static final String URL_JONASADMIN_JMX_SERVER = "EditJmxServer.do"; 61 62 65 private static final String URL_JONASADMIN_SERVER_REGISTRY = "ListRegistry.do"; 66 67 70 private static final String URL_JONASADMIN_SERVLET_SERVER = "EditServletServer.do"; 71 72 75 private static final String URL_JONASADMIN_JVM = "EditJvm.do"; 76 77 80 private static final String URL_JONASADMIN_OWNER = "/jonasAdmin/ListOwnerMBeans.do"; 81 82 85 private static final String RMI_PROTOCOL = "rmi/"; 86 87 90 private static final String SELECT_JVM_MBEAN = "jonas%3Aj2eeType%3DJVM%2Cname%3Djonas%2CJ2EEServer%3Djonas"; 91 92 95 private static final String SELECT_MBEAN_SERVER_MBEAN = "JMImplementation%3Atype%3DMBeanServerDelegate"; 96 97 100 private static final String SELECT_SERVLET_SERVER_MBEAN = "jonas%3Atype%3Dservice%2Cname%3DwebContainers"; 101 102 105 private static final String SELECT_CATALINA_SERVER = "Catalina%3Atype%3DServer"; 106 107 110 private static final String URL_MBEAN_ATTRIBUTS = "/jonasAdmin/ListMBeanAttributes.do?select="; 111 112 115 private static final String END_OF_COLUMN = "</td>"; 116 117 120 private static WebConversation wc2 = new WebConversation(); 121 122 126 public F_JonasAdminInfoServer(String s) { 127 super(s, URL_JONASADMIN); 128 } 129 130 135 public F_JonasAdminInfoServer(WebConversation wc, String s) { 136 super(wc, s, URL_JONASADMIN); 137 } 138 139 143 public static void main(String [] args) { 144 145 String testtorun = null; 146 for (int argn = 0; argn < args.length; argn++) { 148 String sArg = args[argn]; 149 if (sArg.equals("-n")) { 150 testtorun = args[++argn]; 151 } 152 } 153 if (testtorun == null) { 154 junit.textui.TestRunner.run(suite()); 155 } else { 156 junit.textui.TestRunner.run(new F_JonasAdminInfoServer(testtorun)); 157 } 158 } 159 160 164 public static TestSuite suite() { 165 return new TestSuite(F_JonasAdminInfoServer.class); 166 } 167 168 173 public static TestSuite suite(WebConversation wc) { 174 TestSuite suite = new TestSuite(); 175 suite.addTest(new F_JonasAdminInfoServer(wc, "testInfos")); 176 return suite; 177 } 178 179 184 protected void setUp() throws Exception { 185 super.setUp(); 186 187 unUseEar("earsample"); 188 189 if (wc.getCurrentPage().getURL() == null) { 190 useWar("jonasAdmin"); 191 try { 193 JonasAdminAuth.doValidAuth(wc, url); 194 } catch (Exception e) { 195 fail("authentification failed : " + e); 196 } 197 } else { 198 try { 200 wc.getFrameContents(FRAME_TREE); 201 } catch (Exception e) { 202 wc.getResponse(urlLogOut); 203 try { 205 JonasAdminAuth.doValidAuth(wc, url); 206 } catch (Exception auth) { 207 fail("authentification failed : " + auth); 208 } 209 } 210 } 211 } 212 213 218 public void testInfos() throws Exception { 219 220 WebResponse wr; 221 WebLink link; 222 WebTable table; 223 JonasAdminUtils utils = new JonasAdminUtils(); 224 225 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 227 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 229 230 String jonasName = null; 231 String jonasVersion = Version.NUMBER; 232 String jonasProtocol = RMI_PROTOCOL + jProp.getRegistryProtocol(); 233 234 String mbeanId = null; 235 String mbeanSpecification = null; 236 String mbeanSpecVersion = null; 237 String mbeanSpecVendor = null; 238 String mbeanImplementation = null; 239 String mbeanImplVersion = null; 240 String mbeanImplVendor = null; 241 242 String registryProtocol = jProp.getRegistryProtocol(); 243 String registryUrl = jProp.getRegistryUrl(); 244 int jndiNb = 0; 245 246 String servletName = null; 247 String servletVersion = null; 248 String servletService = null; 249 String servletEngine = null; 250 String servletHost = null; 251 252 String jvmVersion = jProp.getJvmVersion(); 253 String jvmVendor = jProp.getJvmVendor(); 254 String jvmNode = null; 255 256 257 try { 260 JonasAdminAuth.doValidAuth(wc2, url); 261 } catch (Exception e) { 262 fail("authentification failed : " + e); 263 } 264 265 wr = wc.getFrameContents(FRAME_TREE); 268 link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_SERVER); 269 link.click(); 270 wr = wc.getFrameContents(FRAME_CONTENT); 271 272 String text; 274 text = wr.getText(); 275 int beginIndex = text.indexOf("Server JOnAS ( "); 276 int endIndex = text.indexOf(" )", beginIndex); 277 jonasName = text.substring(beginIndex + "Server JOnAS ( ".length(), endIndex); 278 279 try { 280 table = utils.getTable(wr, 0); 282 283 assertEquals("It is not the jonas name. ", jonasName, table.getTableCell(0, 2).getText()); 285 assertEquals("It is not the jonas version. ", jonasVersion, table.getTableCell(1, 2).getText()); 286 assertEquals("It is not the jonas protocol. ", jonasProtocol, table.getTableCell(2, 2).getText()); 287 } catch (SAXException e) { 288 fail("The jonas table is incorrect."); 289 } 290 291 292 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_JMX_SERVER); 294 link.click(); 295 wr = wc.getFrameContents(FRAME_CONTENT); 296 297 mbeanId = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN, "MBeanServerId"); 298 mbeanSpecification = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN, "SpecificationName"); 299 mbeanSpecVersion = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN, "SpecificationVersion"); 300 mbeanSpecVendor = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN, "SpecificationVendor"); 301 mbeanImplementation = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN, "ImplementationName"); 302 mbeanImplVersion = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN, "ImplementationVersion"); 303 mbeanImplVendor = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN, "ImplementationVendor"); 304 305 try { 306 table = utils.getTable(wr, 0); 308 309 assertEquals("It is not the mbean server id. ", mbeanId, table.getTableCell(0, 2).getText()); 311 assertEquals("It is not the mbean server specification name. ", mbeanSpecification, table.getTableCell(1, 2).getText()); 312 assertEquals("It is not the mbean server specification version. ", mbeanSpecVersion, table.getTableCell(2, 2).getText()); 313 assertEquals("It is not the mbean server specification vendor. ", mbeanSpecVendor, table.getTableCell(3, 2).getText()); 314 assertEquals("It is not the mbean server implementation name. ", mbeanImplementation, table.getTableCell(4, 2).getText()); 315 assertEquals("It is not the mbean server implementation version. ", mbeanImplVersion, table.getTableCell(5, 2).getText()); 316 assertEquals("It is not the mbean server implementation vendor. ", mbeanImplVendor, table.getTableCell(6, 2).getText()); 317 } catch (SAXException e) { 318 fail("The jmx server table is incorrect."); 319 } 320 321 322 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_SERVER_REGISTRY); 324 link.click(); 325 wr = wc.getFrameContents(FRAME_CONTENT); 326 327 try { 328 table = utils.getTable(wr, 0); 330 331 assertEquals("It is not the registry protocol. ", registryProtocol, table.getTableCell(1, 0).getText()); 333 assertEquals("It is not the registry url. ", registryUrl, table.getTableCell(1, 1).getText()); 334 } catch (SAXException e) { 335 fail("The registry table is incorrect."); 336 } 337 338 try { 339 table = utils.getTable(wr, 3); 341 int rowNb = table.getRowCount(); 342 jndiNb = getJndiNb(wr); 343 text = table.getText(); 344 345 if (jndiNb > 0) { 347 assertEquals("The number of jndi names is not " + jndiNb, rowNb, jndiNb); 348 } 349 assertFalse("'EarOpHome' is found. ", text.indexOf("EarOpHome") > -1); 350 assertFalse("'EarOpHome_L' is found. ", text.indexOf("EarOpHome_L") > -1); 351 assertFalse("'eisName' is found. ", text.indexOf("eisName") > -1); 352 } catch (SAXException e) { 353 fail("The jndi name table is incorrect."); 354 } 355 356 useEar("earsample"); 358 359 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_JVM); 361 link.click(); 362 wr = wc.getFrameContents(FRAME_CONTENT); 363 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_SERVER_REGISTRY); 364 link.click(); 365 wr = wc.getFrameContents(FRAME_CONTENT); 366 367 try { 368 table = utils.getTable(wr, 3); 370 int jndiNb2 = getJndiNb(wr); 371 text = table.getText(); 372 373 assertEquals("The number of JNDI names has not been updated: ", jndiNb + 3, jndiNb2); 375 assertTrue("'EarOpHome' is not found. ", text.indexOf("EarOpHome") > -1); 376 assertTrue("'EarOpHome_L' is not found. ", text.indexOf("EarOpHome_L") > -1); 377 assertTrue("'eisName' is not found. ", text.indexOf("eisName") > -1); 378 } catch (SAXException e) { 379 fail("The jndi name table is incorrect."); 380 } 381 382 383 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_SERVLET_SERVER); 385 link.click(); 386 wr = wc.getFrameContents(FRAME_CONTENT); 387 388 servletName = getMBeanAttribut(SELECT_SERVLET_SERVER_MBEAN, "ServerName"); 389 servletVersion = getMBeanAttribut(SELECT_SERVLET_SERVER_MBEAN, "ServerVersion"); 390 if (jProp.isCatalina()) { 392 String selectService = getMBeanAttribut(SELECT_CATALINA_SERVER, "serviceNames"); 393 if (selectService.indexOf("[ ") == 0) { 394 if (selectService.indexOf(" ]") == selectService.length()-2) { 395 selectService = selectService.substring(2, selectService.length()-2); 396 } else { 397 selectService = selectService.substring(2); 398 } 399 } 400 servletService = getMBeanAttribut(selectService, "name"); 401 String selectContainer = getMBeanAttribut(selectService, "containerName"); 402 servletEngine = getMBeanAttribut(selectContainer, "name"); 403 servletHost = getMBeanAttribut(selectContainer, "defaultHost"); 404 } 405 406 try { 407 table = utils.getTable(wr, 0); 409 410 assertEquals("It is not the servlet server name. ", servletName, table.getTableCell(0, 2).getText()); 412 assertEquals("It is not the servlet server version. ", servletVersion, table.getTableCell(1, 2).getText()); 413 if (jProp.isCatalina()) { 414 assertEquals("It is not the servlet server service. ", servletService, table.getTableCell(2, 2).getText()); 415 assertEquals("It is not the servlet server engine. ", servletEngine, table.getTableCell(3, 2).getText()); 416 assertEquals("It is not the servlet server host. ", servletHost, table.getTableCell(4, 2).getText()); 417 } 418 } catch (SAXException e) { 419 fail("The jmx server table is incorrect."); 420 } 421 422 423 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_JVM); 425 link.click(); 426 wr = wc.getFrameContents(FRAME_CONTENT); 427 428 jvmNode = getMBeanAttribut(SELECT_JVM_MBEAN, "node"); 429 try { 430 table = utils.getTable(wr, 0); 432 433 assertEquals("It is not the jvm version. ", jvmVersion, table.getTableCell(0, 2).getText()); 435 assertEquals("It is not the jvm vendor. ", jvmVendor, table.getTableCell(1, 2).getText()); 436 assertEquals("It is not the jvm node. ", jvmNode, table.getTableCell(2, 2).getText()); 437 } catch (SAXException e) { 438 fail("The jvm table is incorrect."); 439 } 440 441 } 442 443 449 private int getJndiNb(WebResponse contentFrame) throws SAXException { 450 JonasAdminUtils utils = new JonasAdminUtils(); 451 WebTable table = utils.getTable(contentFrame, 2); 452 453 String text = table.getTableCell(0, 0).getText(); 454 int beginIndex = text.indexOf("("); 455 int endIndex = text.indexOf(")", beginIndex); 456 String nb = text.substring(beginIndex + "(".length(), endIndex); 457 458 return Integer.parseInt(nb); 459 } 460 461 470 private String getMBeanAttribut(String select, String attribut) { 471 WebResponse wr; 472 String urlAttributs = prefixUrl + URL_MBEAN_ATTRIBUTS + select; 473 474 try { 475 wr = wc2.getResponse(urlAttributs); 476 String attributs = wr.getText(); 477 int position = attributs.indexOf("<b>" + attribut + "</b>"); 478 int beginIndex = attributs.indexOf("== ", position); 479 int endIndex = attributs.indexOf(END_OF_COLUMN, beginIndex); 480 return attributs.substring(beginIndex + "== ".length(), endIndex); 481 } catch (MalformedURLException e) { 482 throw new IllegalStateException ("Invalid URL: " + url + ". " + e); 483 } catch (IOException e) { 484 throw new IllegalStateException ("No response from: " + url + ". " + e); 485 } catch (SAXException e) { 486 throw new IllegalStateException ("No text found. " + e); 487 } 488 } 489 490 494 public void tearDown() throws Exception { 495 } 496 } 497 | Popular Tags |