Source Code Cross Referenced for F_JonasAdminInfoServer.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jonasadmin » test » jonasserver » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.jonasadmin.test.jonasserver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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_JonasAdminInfoServer.java 7381 2005-09-14 16:00:02Z kemlerp $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.jonasadmin.test.jonasserver;
025:
026:        import java.io.IOException;
027:        import java.net.MalformedURLException;
028:
029:        import junit.framework.TestSuite;
030:
031:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
032:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
033:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
034:        import org.objectweb.jonas_lib.version.Version;
035:        import org.xml.sax.SAXException;
036:
037:        import com.meterware.httpunit.HttpUnitOptions;
038:        import com.meterware.httpunit.WebConversation;
039:        import com.meterware.httpunit.WebLink;
040:        import com.meterware.httpunit.WebResponse;
041:        import com.meterware.httpunit.WebTable;
042:
043:        /**
044:         * Class for testing server infos in jonasAdmin
045:         * @author kemlerp
046:         *
047:         */
048:        public class F_JonasAdminInfoServer extends JonasAdminTestCase {
049:
050:            /**
051:             * URL of the Server Management
052:             */
053:            private static final String URL_JONASADMIN_SERVER = "EditJonasServer.do";
054:
055:            /**
056:             * URL of the JMX SERVER
057:             */
058:            private static final String URL_JONASADMIN_JMX_SERVER = "EditJmxServer.do";
059:
060:            /**
061:             * URL of the server registry
062:             */
063:            private static final String URL_JONASADMIN_SERVER_REGISTRY = "ListRegistry.do";
064:
065:            /**
066:             * URL of the SERVLET SERVER
067:             */
068:            private static final String URL_JONASADMIN_SERVLET_SERVER = "EditServletServer.do";
069:
070:            /**
071:             * URL of the JVM
072:             */
073:            private static final String URL_JONASADMIN_JVM = "EditJvm.do";
074:
075:            /**
076:             * URL of owner mbeans
077:             */
078:            private static final String URL_JONASADMIN_OWNER = "/jonasAdmin/ListOwnerMBeans.do";
079:
080:            /**
081:             * RMI PROTOCOL
082:             */
083:            private static final String RMI_PROTOCOL = "rmi/";
084:
085:            /**
086:             * Value of select parameter for JVM
087:             */
088:            private static final String SELECT_JVM_MBEAN = "jonas%3Aj2eeType%3DJVM%2Cname%3Djonas%2CJ2EEServer%3Djonas";
089:
090:            /**
091:             * Value of select parameter for MBEAN Server
092:             */
093:            private static final String SELECT_MBEAN_SERVER_MBEAN = "JMImplementation%3Atype%3DMBeanServerDelegate";
094:
095:            /**
096:             * Value of select parameter for Servlet Server
097:             */
098:            private static final String SELECT_SERVLET_SERVER_MBEAN = "jonas%3Atype%3Dservice%2Cname%3DwebContainers";
099:
100:            /**
101:             * Value of select parameter for Catalina Server
102:             */
103:            private static final String SELECT_CATALINA_SERVER = "Catalina%3Atype%3DServer";
104:
105:            /**
106:             * URL of the MBean attributs
107:             */
108:            private static final String URL_MBEAN_ATTRIBUTS = "/jonasAdmin/ListMBeanAttributes.do?select=";
109:
110:            /**
111:             * Balise HTML
112:             */
113:            private static final String END_OF_COLUMN = "</td>";
114:
115:            /**
116:             * A 2nd connection to jonasAdmin
117:             */
118:            private static WebConversation wc2 = new WebConversation();
119:
120:            /**
121:             * Constructor with a specified name
122:             * @param s name
123:             */
124:            public F_JonasAdminInfoServer(String s) {
125:                super (s, URL_JONASADMIN);
126:            }
127:
128:            /**
129:             * Main method
130:             * @param args the arguments
131:             */
132:            public static void main(String[] args) {
133:
134:                String testtorun = null;
135:                // Get args
136:                for (int argn = 0; argn < args.length; argn++) {
137:                    String sArg = args[argn];
138:                    if (sArg.equals("-n")) {
139:                        testtorun = args[++argn];
140:                    }
141:                }
142:                if (testtorun == null) {
143:                    junit.textui.TestRunner.run(suite());
144:                } else {
145:                    junit.textui.TestRunner.run(new F_JonasAdminInfoServer(
146:                            testtorun));
147:                }
148:            }
149:
150:            /**
151:             * Get a new TestSuite for this class
152:             * @return a new TestSuite for this class
153:             */
154:            public static TestSuite suite() {
155:                return new TestSuite(F_JonasAdminInfoServer.class);
156:            }
157:
158:            /**
159:             * Setup need for these tests
160:             * jonasAdmin is required
161:             * @throws Exception if it fails
162:             */
163:            protected void setUp() throws Exception {
164:                super .setUp();
165:
166:                unUseEar("earsample");
167:
168:                if (wc.getCurrentPage().getURL() == null) {
169:                    useWar("jonasAdmin");
170:                    // login to jonas admin
171:                    try {
172:                        JonasAdminAuth.doValidAuth(wc, url);
173:                    } catch (Exception e) {
174:                        fail("authentification failed :  " + e);
175:                    }
176:                } else {
177:                    // if there was an error, the connection must be restablished
178:                    try {
179:                        wc.getFrameContents(FRAME_TREE);
180:                    } catch (Exception e) {
181:                        wc.getResponse(urlLogOut);
182:                        // login to jonas admin
183:                        try {
184:                            JonasAdminAuth.doValidAuth(wc, url);
185:                        } catch (Exception auth) {
186:                            fail("authentification failed :  " + auth);
187:                        }
188:                    }
189:                }
190:            }
191:
192:            /**
193:             * Test JOnAS server infos
194:             * @throws Exception if error occurs
195:             *
196:             */
197:            public void testInfos() throws Exception {
198:
199:                WebResponse wr;
200:                WebLink link;
201:                WebTable table;
202:                JonasAdminUtils utils = new JonasAdminUtils();
203:
204:                // Disable errors of javascript
205:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
206:                // Disable exception thrown on error status
207:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
208:
209:                String jonasName = null;
210:                String jonasVersion = Version.NUMBER;
211:                String jonasProtocol = RMI_PROTOCOL
212:                        + jProp.getRegistryProtocol();
213:
214:                String mbeanId = null;
215:                String mbeanSpecification = null;
216:                String mbeanSpecVersion = null;
217:                String mbeanSpecVendor = null;
218:                String mbeanImplementation = null;
219:                String mbeanImplVersion = null;
220:                String mbeanImplVendor = null;
221:
222:                String registryProtocol = jProp.getRegistryProtocol();
223:                String registryUrl = jProp.getRegistryUrl();
224:                int jndiNb = 0;
225:
226:                String servletName = null;
227:                String servletVersion = null;
228:                String servletService = null;
229:                String servletEngine = null;
230:                String servletHost = null;
231:
232:                String jvmVersion = jProp.getJvmVersion();
233:                String jvmVendor = jProp.getJvmVendor();
234:                String jvmNode = null;
235:
236:                // OPEN A SECOND CONNECTION
237:                // login to jonas admin
238:                try {
239:                    JonasAdminAuth.doValidAuth(wc2, url);
240:                } catch (Exception e) {
241:                    fail("authentification failed :  " + e);
242:                }
243:
244:                // TEST JONAS SERVER
245:                // Go to jonas server management
246:                wr = wc.getFrameContents(FRAME_TREE);
247:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
248:                        URL_JONASADMIN_SERVER);
249:                link.click();
250:                wr = wc.getFrameContents(FRAME_CONTENT);
251:
252:                // Get jonas server name
253:                String text;
254:                text = wr.getText();
255:                int beginIndex = text.indexOf("Server JOnAS ( ");
256:                int endIndex = text.indexOf(" )", beginIndex);
257:                jonasName = text.substring(beginIndex
258:                        + "Server JOnAS ( ".length(), endIndex);
259:
260:                try {
261:                    // Get table
262:                    table = utils.getTable(wr, 0);
263:
264:                    // Verify
265:                    assertEquals("It is not the jonas name. ", jonasName, table
266:                            .getTableCell(0, 2).getText());
267:                    assertEquals("It is not the jonas version. ", jonasVersion,
268:                            table.getTableCell(1, 2).getText());
269:                    assertEquals("It is not the jonas protocol. ",
270:                            jonasProtocol, table.getTableCell(2, 2).getText());
271:                } catch (SAXException e) {
272:                    fail("The jonas table is incorrect.");
273:                }
274:
275:                // TEST JMX SERVER
276:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
277:                        URL_JONASADMIN_JMX_SERVER);
278:                link.click();
279:                wr = wc.getFrameContents(FRAME_CONTENT);
280:
281:                mbeanId = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN,
282:                        "MBeanServerId");
283:                mbeanSpecification = getMBeanAttribut(
284:                        SELECT_MBEAN_SERVER_MBEAN, "SpecificationName");
285:                mbeanSpecVersion = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN,
286:                        "SpecificationVersion");
287:                mbeanSpecVendor = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN,
288:                        "SpecificationVendor");
289:                mbeanImplementation = getMBeanAttribut(
290:                        SELECT_MBEAN_SERVER_MBEAN, "ImplementationName");
291:                mbeanImplVersion = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN,
292:                        "ImplementationVersion");
293:                mbeanImplVendor = getMBeanAttribut(SELECT_MBEAN_SERVER_MBEAN,
294:                        "ImplementationVendor");
295:
296:                try {
297:                    // Get table
298:                    table = utils.getTable(wr, 0);
299:
300:                    // Verify
301:                    assertEquals("It is not the mbean server id. ", mbeanId,
302:                            table.getTableCell(0, 2).getText());
303:                    assertEquals(
304:                            "It is not the mbean server specification name. ",
305:                            mbeanSpecification, table.getTableCell(1, 2)
306:                                    .getText());
307:                    assertEquals(
308:                            "It is not the mbean server specification version. ",
309:                            mbeanSpecVersion, table.getTableCell(2, 2)
310:                                    .getText());
311:                    assertEquals(
312:                            "It is not the mbean server specification vendor. ",
313:                            mbeanSpecVendor, table.getTableCell(3, 2).getText());
314:                    assertEquals(
315:                            "It is not the mbean server implementation name. ",
316:                            mbeanImplementation, table.getTableCell(4, 2)
317:                                    .getText());
318:                    assertEquals(
319:                            "It is not the mbean server implementation version. ",
320:                            mbeanImplVersion, table.getTableCell(5, 2)
321:                                    .getText());
322:                    assertEquals(
323:                            "It is not the mbean server implementation vendor. ",
324:                            mbeanImplVendor, table.getTableCell(6, 2).getText());
325:                } catch (SAXException e) {
326:                    fail("The jmx server table is incorrect.");
327:                }
328:
329:                // TEST REGISTRY INFOS
330:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
331:                        URL_JONASADMIN_SERVER_REGISTRY);
332:                link.click();
333:                wr = wc.getFrameContents(FRAME_CONTENT);
334:
335:                try {
336:                    // Get table
337:                    table = utils.getTable(wr, 0);
338:
339:                    // Verify
340:                    assertEquals("It is not the registry protocol. ",
341:                            registryProtocol, table.getTableCell(1, 0)
342:                                    .getText());
343:                    assertEquals("It is not the registry url. ", registryUrl,
344:                            table.getTableCell(1, 1).getText());
345:                } catch (SAXException e) {
346:                    fail("The registry table is incorrect.");
347:                }
348:
349:                try {
350:                    //Get table
351:                    table = utils.getTable(wr, 3);
352:                    int rowNb = table.getRowCount();
353:                    jndiNb = getJndiNb(wr);
354:                    text = table.getText();
355:
356:                    // Verify
357:                    if (jndiNb > 0) {
358:                        assertEquals("The number of jndi names is not "
359:                                + jndiNb, rowNb, jndiNb);
360:                    }
361:                    assertFalse("'EarOpHome' is found. ", text
362:                            .indexOf("EarOpHome") > -1);
363:                    assertFalse("'EarOpHome_L' is found. ", text
364:                            .indexOf("EarOpHome_L") > -1);
365:                    assertFalse("'eisName' is found. ",
366:                            text.indexOf("eisName") > -1);
367:                } catch (SAXException e) {
368:                    fail("The jndi name table is incorrect.");
369:                }
370:
371:                // Deploy earsample.ear
372:                useEar("earsample");
373:
374:                // Refresh
375:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
376:                        URL_JONASADMIN_JVM);
377:                link.click();
378:                wr = wc.getFrameContents(FRAME_CONTENT);
379:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
380:                        URL_JONASADMIN_SERVER_REGISTRY);
381:                link.click();
382:                wr = wc.getFrameContents(FRAME_CONTENT);
383:
384:                try {
385:                    //Get table
386:                    table = utils.getTable(wr, 3);
387:                    int jndiNb2 = getJndiNb(wr);
388:                    text = table.getText();
389:
390:                    // Verify
391:                    if (jProp.isResource()) {
392:                        // 3 JNDI NAMES are added: EarOpHome, EarOpHome_L, eisName
393:                        assertEquals(
394:                                "The number of JNDI names has not been updated: ",
395:                                jndiNb + 3, jndiNb2);
396:                        assertTrue("'eisName' is not found. ", text
397:                                .indexOf("eisName") > -1);
398:                    } else {
399:                        // 2 JNDI NAMES are added: EarOpHome, EarOpHome_L
400:                        assertEquals(
401:                                "The number of JNDI names has not been updated: ",
402:                                jndiNb + 2, jndiNb2);
403:                    }
404:                    assertTrue("'EarOpHome' is not found. ", text
405:                            .indexOf("EarOpHome") > -1);
406:                    assertTrue("'EarOpHome_L' is not found. ", text
407:                            .indexOf("EarOpHome_L") > -1);
408:                } catch (SAXException e) {
409:                    fail("The jndi name table is incorrect.");
410:                }
411:
412:                // TEST SERVLET SERVER
413:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
414:                        URL_JONASADMIN_SERVLET_SERVER);
415:                link.click();
416:                wr = wc.getFrameContents(FRAME_CONTENT);
417:
418:                servletName = getMBeanAttribut(SELECT_SERVLET_SERVER_MBEAN,
419:                        "ServerName");
420:                servletVersion = getMBeanAttribut(SELECT_SERVLET_SERVER_MBEAN,
421:                        "ServerVersion");
422:                // if CATALINA
423:                if (jProp.isCatalina()) {
424:                    String selectService = getMBeanAttribut(
425:                            SELECT_CATALINA_SERVER, "serviceNames");
426:                    if (selectService.indexOf("[ ") == 0) {
427:                        if (selectService.indexOf(" ]") == selectService
428:                                .length() - 2) {
429:                            selectService = selectService.substring(2,
430:                                    selectService.length() - 2);
431:                        } else {
432:                            selectService = selectService.substring(2);
433:                        }
434:                    }
435:                    servletService = getMBeanAttribut(selectService, "name");
436:                    String selectContainer = getMBeanAttribut(selectService,
437:                            "containerName");
438:                    servletEngine = getMBeanAttribut(selectContainer, "name");
439:                    servletHost = getMBeanAttribut(selectContainer,
440:                            "defaultHost");
441:                }
442:
443:                try {
444:                    // Get table
445:                    table = utils.getTable(wr, 0);
446:
447:                    // Verify
448:                    assertEquals("It is not the servlet server name. ",
449:                            servletName, table.getTableCell(0, 2).getText());
450:                    assertEquals("It is not the servlet server version. ",
451:                            servletVersion, table.getTableCell(1, 2).getText());
452:                    if (jProp.isCatalina()) {
453:                        assertEquals("It is not the servlet server service. ",
454:                                servletService, table.getTableCell(2, 2)
455:                                        .getText());
456:                        assertEquals("It is not the servlet server engine. ",
457:                                servletEngine, table.getTableCell(3, 2)
458:                                        .getText());
459:                        assertEquals("It is not the servlet server host. ",
460:                                servletHost, table.getTableCell(4, 2).getText());
461:                    }
462:                } catch (SAXException e) {
463:                    fail("The jmx server table is incorrect.");
464:                }
465:
466:                // TEST JVM INFOS
467:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
468:                        URL_JONASADMIN_JVM);
469:                link.click();
470:                wr = wc.getFrameContents(FRAME_CONTENT);
471:
472:                jvmNode = getMBeanAttribut(SELECT_JVM_MBEAN, "node");
473:                try {
474:                    // Get table
475:                    table = utils.getTable(wr, 0);
476:
477:                    // Verify
478:                    assertEquals("It is not the jvm version. ", jvmVersion,
479:                            table.getTableCell(0, 2).getText());
480:                    assertEquals("It is not the jvm vendor. ", jvmVendor, table
481:                            .getTableCell(1, 2).getText());
482:                    assertEquals("It is not the jvm node. ", jvmNode, table
483:                            .getTableCell(2, 2).getText());
484:                } catch (SAXException e) {
485:                    fail("The jvm table is incorrect.");
486:                }
487:
488:            }
489:
490:            /**
491:             * Get the number of JNDI object
492:             * @param contentFrame the content frame
493:             * @return number of JNDI objects
494:             * @throws SAXException if a table or cell doesn't match.
495:             */
496:            private int getJndiNb(WebResponse contentFrame) throws SAXException {
497:                JonasAdminUtils utils = new JonasAdminUtils();
498:                WebTable table = utils.getTable(contentFrame, 2);
499:
500:                String text = table.getTableCell(0, 0).getText();
501:                int beginIndex = text.indexOf("(");
502:                int endIndex = text.indexOf(")", beginIndex);
503:                String nb = text.substring(beginIndex + "(".length(), endIndex);
504:
505:                return Integer.parseInt(nb);
506:            }
507:
508:            /**
509:             * Get MBean attribut
510:             * @param select value of select param to indicate the chosen MBean
511:             * @param attribut name of attribut
512:             * @return value of the attribut
513:             * @throws MalformedURLException if url is invalid
514:             * @throws IOException if url is not correct
515:             * @throws SAXException if an error is found
516:             */
517:            private String getMBeanAttribut(String select, String attribut) {
518:                WebResponse wr;
519:                String urlAttributs = prefixUrl + URL_MBEAN_ATTRIBUTS + select;
520:
521:                try {
522:                    wr = wc2.getResponse(urlAttributs);
523:                    String attributs = wr.getText();
524:                    int position = attributs.indexOf("<b>" + attribut + "</b>");
525:                    int beginIndex = attributs.indexOf("== ", position);
526:                    int endIndex = attributs.indexOf(END_OF_COLUMN, beginIndex);
527:                    return attributs.substring(beginIndex + "== ".length(),
528:                            endIndex);
529:                } catch (MalformedURLException e) {
530:                    throw new IllegalStateException("Invalid URL: " + url
531:                            + ". " + e);
532:                } catch (IOException e) {
533:                    throw new IllegalStateException("No response from: " + url
534:                            + ". " + e);
535:                } catch (SAXException e) {
536:                    throw new IllegalStateException("No text found. " + e);
537:                }
538:            }
539:
540:            /**
541:             * Tear Down cleanUp action
542:             * @throws Exception if an error occurs
543:             */
544:            public void tearDown() throws Exception {
545:                super.tearDown();
546:            }
547:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.