Source Code Cross Referenced for F_JonasAdminNavigation.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jonasadmin » test » navigation » 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.navigation 
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_JonasAdminNavigation.java 7381 2005-09-14 16:00:02Z kemlerp $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.jonasadmin.test.navigation;
025:
026:        import java.io.IOException;
027:        import java.util.Vector;
028:
029:        import junit.framework.TestSuite;
030:
031:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
032:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminFiles;
033:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
034:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTree;
035:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
036:        import org.xml.sax.SAXException;
037:
038:        import com.meterware.httpunit.HttpException;
039:        import com.meterware.httpunit.HttpNotFoundException;
040:        import com.meterware.httpunit.HttpUnitOptions;
041:        import com.meterware.httpunit.TableCell;
042:        import com.meterware.httpunit.WebLink;
043:        import com.meterware.httpunit.WebResponse;
044:        import com.meterware.httpunit.WebTable;
045:
046:        /**
047:         * Define a class to test the JOnAS Admin console
048:         * Test all links, content title, selected tree item
049:         * @author kemlerp
050:         *
051:         */
052:        public class F_JonasAdminNavigation extends JonasAdminTestCase {
053:
054:            /**
055:             * SUCCESS CODE
056:             */
057:            private static final int HTTP_SUCCESS_CODE = 200;
058:
059:            /**
060:             * NAME OF THE EAR LINK
061:             */
062:            private static final String EAR_LINK_NAME = "Applications (EAR)";
063:
064:            /**
065:             * URL of the bean alarm record
066:             */
067:            private static final String URL_JONASADMIN_ALARM_RECORD = "/jonasAdmin/EditEjbEnt.do?select=jonas:j2eeType=EntityBean,name=AlarmRecord,EJBModule=alarm,J2EEApplication=alarm,J2EEServer=jonas";
068:
069:            /**
070:             * URL of the synchronize button
071:             */
072:            private static final String URL_JONASADMIN_SYNCHRONIZE = "/jonasAdmin/ExecuteEjb.do?action=synchronize";
073:
074:            /**
075:             * URL of the reduce instance button
076:             */
077:            private static final String URL_JONASADMIN_REDUCE = "/jonasAdmin/ExecuteEjb.do?action=reduceCache";
078:
079:            /**
080:             * URL of the reduce pool instance button
081:             */
082:            private static final String URL_JONASADMIN_REDUCE_POOL = "/jonasAdmin/ExecuteEjb.do?action=reducePool";
083:
084:            /**
085:             * URL of the new group instance button
086:             */
087:            private static final String URL_JONASADMIN_NEW_GROUP = "/jonasAdmin/EditNewGroupMemoryRealm.do?action=create";
088:
089:            /**
090:             * URL of the new user instance button
091:             */
092:            private static final String URL_JONASADMIN_NEW_USER = "/jonasAdmin/EditNewUserMemoryRealm.do?action=create";
093:
094:            /**
095:             * Class value of the selected tree control
096:             */
097:            private static final String CLASS_TREE_CONTROL_SELECTED = "tree-control-selected";
098:
099:            /**
100:             * Name of the property navigation.mbean
101:             */
102:            private static final String NAVIGATION_MBEAN = "navigation.mbean";
103:
104:            /**
105:             * Name of the property navigation.link
106:             */
107:            private static final String NAVIGATION_LINK = "navigation.link";
108:
109:            /**
110:             * Name of the property navigation.contentTitle
111:             */
112:            private static final String NAVIGATION_CONTENT_TITLE = "navigation.contentTitle";
113:
114:            /**
115:             * Name of the property navigation.selectedItem
116:             */
117:            private static final String NAVIGATION_SELECTED_ITEM = "navigation.selectedItem";
118:
119:            /**
120:             * Name of the property navigation.titleTomThumb
121:             */
122:            private static final String NAVIGATION_TITLE_TOM_THUMB = "navigation.titleTomThumb";
123:
124:            /**
125:             * Name of the property navigation.rarInEar
126:             */
127:            private static final String NAVIGATION_RAR_IN_EAR = "navigation.rarInEar";
128:
129:            /**
130:             * Time of beginning testAllLinks
131:             */
132:            private String beginTime;
133:
134:            /**
135:             * Time of ending testAllLinks
136:             */
137:            private String endTime;
138:
139:            /**
140:             * Constructor with a specified name
141:             * @param s name
142:             */
143:            public F_JonasAdminNavigation(String s) {
144:                super (s, URL_JONASADMIN);
145:            }
146:
147:            /**
148:             * Main method
149:             * @param args the arguments
150:             */
151:            public static void main(String[] args) {
152:
153:                String testtorun = null;
154:                // Get args
155:                for (int argn = 0; argn < args.length; argn++) {
156:                    String sArg = args[argn];
157:                    if (sArg.equals("-n")) {
158:                        testtorun = args[++argn];
159:                    }
160:                }
161:                if (testtorun == null) {
162:                    junit.textui.TestRunner.run(suite());
163:                } else {
164:                    junit.textui.TestRunner.run(new F_JonasAdminNavigation(
165:                            testtorun));
166:                }
167:            }
168:
169:            /**
170:             * Get a new TestSuite for this class
171:             * @return a new TestSuite for this class
172:             */
173:            public static TestSuite suite() {
174:                return new TestSuite(F_JonasAdminNavigation.class);
175:            }
176:
177:            /**
178:             * Setup need for these tests
179:             * jonasAdmin is required
180:             * @throws Exception if it fails
181:             */
182:            protected void setUp() throws Exception {
183:                super .setUp();
184:
185:                // Get time
186:                beginTime = getTime();
187:
188:                if (wc.getCurrentPage().getURL() == null) {
189:                    useWar("jonasAdmin");
190:                    // login to jonas admin
191:                    try {
192:                        JonasAdminAuth.doValidAuth(wc, url);
193:                    } catch (Exception e) {
194:                        fail("authentification failed :  " + e);
195:                    }
196:                } else {
197:                    // if there was an error, the connection must be restablished
198:                    try {
199:                        wc.getFrameContents(FRAME_TREE);
200:                    } catch (Exception e) {
201:                        wc.getResponse(urlLogOut);
202:                        // login to jonas admin
203:                        try {
204:                            JonasAdminAuth.doValidAuth(wc, url);
205:                        } catch (Exception auth) {
206:                            fail("authentification failed :  " + auth);
207:                        }
208:                    }
209:                }
210:                undeployAllEar();
211:                undeployAllJar();
212:
213:                useEar("autoload/mejb");
214:            }
215:
216:            /**
217:             * Test all about the navigation
218:             * @throws Exception if error occurs
219:             *
220:             */
221:            public void testAll() throws Exception {
222:
223:                Vector viewedURLs = new Vector();
224:                WebResponse wr;
225:
226:                viewedURLs.add(URL_JONASADMIN);
227:
228:                // Disable errors of javascript
229:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
230:                // Disable exception thrown on error status
231:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
232:
233:                // add links
234:                // deploy ear
235:                if (jProp.isEar()) {
236:                    useEar("alarm");
237:                    if (jProp.isResource()) {
238:                        if (configFile != null) {
239:                            if (configFile.get(NAVIGATION_RAR_IN_EAR).equals(
240:                                    "on")) {
241:                                useEar("earsample");
242:                            }
243:                        } else {
244:                            useEar("earsample");
245:                        }
246:                    }
247:                    // Reload the page
248:                    wc.getResponse(getAbsoluteUrl(URL_JONASADMIN));
249:                }
250:
251:                // Get the frame "tree"
252:                WebResponse treeFrame = wc.getFrameContents(FRAME_TREE);
253:
254:                // Open tree
255:                try {
256:                    treeFrame = JonasAdminTree.openTree(treeFrame, wc);
257:                } catch (IOException e) {
258:                    fail("failed to open tree. " + e);
259:                }
260:
261:                // When EJB service is actived
262:                if (jProp.isEjb()) {
263:                    // Particular cases because of values of the session do not correspond at the page
264:                    // 1-"/jonasAdmin/ExecuteEjb.do?action=synchronize"
265:                    testParticularCase("name=AlarmRecord", "synchronize",
266:                            URL_JONASADMIN_SYNCHRONIZE, viewedURLs);
267:
268:                    // 2-"/jonasAdmin/ExecuteEjb.do?action=reduceCache"
269:                    testParticularCase("name=AlarmRecord", "reduceCache",
270:                            URL_JONASADMIN_REDUCE, viewedURLs);
271:
272:                    // 3-"/jonasAdmin/ExecuteEjb.do?action=reducePool"
273:                    testParticularCase(
274:                            "EditEjbSbl.do?select=jonas:j2eeType=StatelessSessionBean,name=MEJB,EJBModule=mejb,J2EEApplication=mejb,J2EEServer=jonas",
275:                            "reducePool", URL_JONASADMIN_REDUCE_POOL,
276:                            viewedURLs);
277:                }
278:
279:                // 4-"/jonasAdmin/EditNewGroupMemoryRealm.do?action=create"
280:                testParticularCase("memrlm_1", "Groups.do", "action=create",
281:                        URL_JONASADMIN_NEW_GROUP, viewedURLs);
282:
283:                // 5-"/jonasAdmin/EditNewUserMemoryRealm.do?action=create"
284:                testParticularCase("memrlm_1", "Users.do", "action=create",
285:                        URL_JONASADMIN_NEW_USER, viewedURLs);
286:
287:                // Verify all links are not viewTree.do
288:                try {
289:                    verifyLinks(treeFrame, viewedURLs);
290:                } catch (IOException e) {
291:                    throw new IllegalStateException(
292:                            "Problem to verify all links. " + e);
293:                } catch (Exception e) {
294:                    throw new IllegalStateException(
295:                            "Problem to verify all links. " + e);
296:                }
297:
298:                // Test MBean
299:                if (configFile.get(NAVIGATION_MBEAN).equals("on")) {
300:                    testMBean(viewedURLs);
301:                }
302:            }
303:
304:            /**
305:             * Verify all links in frame
306:             * @param frame The frame
307:             * @param viewedURLs All URLs have just been viewed
308:             * @throws IOException if error occurs to get response
309:             * @throws Exception if error occurs to get response
310:             */
311:            public void verifyLinks(WebResponse frame, Vector viewedURLs)
312:                    throws Exception, IOException {
313:
314:                WebLink[] links = null;
315:
316:                // Disable errors of javascript
317:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
318:                // Disable exception thrown on error status
319:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
320:
321:                // Get links
322:                links = frame.getLinks();
323:                WebResponse wr;
324:
325:                for (int i = 0; i < links.length; i++) {
326:                    // Verify all links are not viewTree.do and don't contain "://"
327:                    if (links[i].getURLString().indexOf("viewTree.do") == -1
328:                            && links[i].getURLString().indexOf(
329:                                    "ListMBeanDetails.do") == -1
330:                            && links[i].getURLString().indexOf("://") == -1) {
331:                        if (!viewedURLs.contains(links[i].getURLString())) {
332:                            executeTests(frame, links[i], viewedURLs);
333:
334:                            // Verify content frame links
335:                            WebResponse contentFrame = wc
336:                                    .getFrameContents(FRAME_CONTENT);
337:                            verifyLinks(contentFrame, viewedURLs);
338:                        }
339:                    }
340:                }
341:            }
342:
343:            /**
344:             * Test links and content titles for a particular case
345:             * @param treeLink the link of the tree frame to click
346:             * @param contentLink the link of the content frame to click
347:             * @param url the url to test
348:             * @param viewedURLs All URLs have just been viewed
349:             * @throws Exception if an error occurs
350:             */
351:            private void testParticularCase(String treeLink,
352:                    String contentLink, String url, Vector viewedURLs)
353:                    throws Exception {
354:                WebLink link;
355:                WebResponse wr;
356:                WebResponse frame;
357:
358:                frame = wc.getFrameContents(FRAME_TREE);
359:                link = frame.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
360:                        treeLink);
361:                if (link == null) {
362:                    throw new IllegalStateException(
363:                            "No link found for treelink : '" + treeLink + "'.");
364:                }
365:                wr = link.click();
366:
367:                frame = wc.getFrameContents(FRAME_CONTENT);
368:                link = frame.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
369:                        contentLink);
370:
371:                if (link == null) {
372:                    throw new IllegalStateException(
373:                            "No link found for treelink : '" + treeLink + "'.");
374:                }
375:                executeTests(frame, link, viewedURLs);
376:            }
377:
378:            /**
379:             * Test links and content titles for a particular case
380:             * @param treeLink the link of the tree frame to click
381:             * @param contentLink the link of the content frame to click
382:             * @param contentLink2 the second link of the content frame to click
383:             * @param url the url to test
384:             * @param viewedURLs All URLs have just been viewed
385:             * @throws Exception if an error occurs
386:             */
387:            private void testParticularCase(String treeLink,
388:                    String contentLink, String contentLink2, String url,
389:                    Vector viewedURLs) throws Exception {
390:
391:                WebLink link;
392:                WebResponse wr;
393:                WebResponse frame;
394:
395:                frame = wc.getFrameContents(FRAME_TREE);
396:                link = frame.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
397:                        treeLink);
398:                if (link == null) {
399:                    throw new IllegalStateException(
400:                            "No link found for treelink : '" + treeLink + "'.");
401:                }
402:                wr = link.click();
403:
404:                frame = wc.getFrameContents(FRAME_CONTENT);
405:                link = frame.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
406:                        contentLink);
407:                if (link == null) {
408:                    throw new IllegalStateException(
409:                            "No link found for contentLink : '" + contentLink
410:                                    + "'.");
411:                }
412:                wr = link.click();
413:
414:                frame = wc.getFrameContents(FRAME_CONTENT);
415:                link = frame.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
416:                        contentLink2);
417:                if (link == null) {
418:                    throw new IllegalStateException(
419:                            "No link found for contentLink2 : '" + contentLink2
420:                                    + "'.");
421:                }
422:
423:                executeTests(frame, link, viewedURLs);
424:            }
425:
426:            /**
427:             * call the tests
428:             * @param frame The frame where the link is
429:             * @param link A no null link
430:             * @param viewedURLs All URLs have just been viewed
431:             * @throws SAXException If an error occurs
432:             */
433:            private void executeTests(WebResponse frame, WebLink link,
434:                    Vector viewedURLs) throws SAXException {
435:
436:                WebResponse wr;
437:                try {
438:                    wr = link.click();
439:                    // To check if the link is correct
440:                    if (configFile.get(NAVIGATION_LINK).equals("on")) {
441:                        testLinks(wr);
442:                    }
443:                } catch (HttpNotFoundException e) {
444:                    if (configFile.get(NAVIGATION_LINK).equals("on")) {
445:                        fail("failed to click : link = " + link.getText()
446:                                + ", URL = " + link.getURLString()
447:                                + ", page = " + viewedURLs.lastElement() + ". "
448:                                + e);
449:                    }
450:                } catch (HttpException e) {
451:                    if (configFile.get(NAVIGATION_LINK).equals("on")) {
452:                        fail("failed to click : link = " + link.getText()
453:                                + ", URL = " + link.getURLString()
454:                                + ", page = " + viewedURLs.lastElement() + ". "
455:                                + e);
456:                    }
457:                } catch (IOException e) {
458:                    if (configFile.get(NAVIGATION_LINK).equals("on")) {
459:                        fail("failed to click : link = " + link.getText()
460:                                + ", URL = " + link.getURLString()
461:                                + ", page = " + viewedURLs.lastElement() + ". "
462:                                + e);
463:                    }
464:                }
465:
466:                // To check if the content title is correct
467:                if (configFile.get(NAVIGATION_CONTENT_TITLE).equals("on")) {
468:                    testContentTitle(link.getURLString());
469:                }
470:
471:                // To check if the selected item is correct for links of the tree frame
472:                if (frame.getFrameName().equalsIgnoreCase(FRAME_TREE)) {
473:                    if (configFile.get(NAVIGATION_SELECTED_ITEM).equals("on")) {
474:                        testTreeSelected(link.getURLString());
475:                    }
476:                }
477:
478:                // To check if the title tom thumb is correct
479:                if (configFile.get(NAVIGATION_TITLE_TOM_THUMB).equals("on")) {
480:                    testTitleTomThumb(link.getURLString());
481:                }
482:
483:                // Add URL to viewed URLs
484:                viewedURLs.add(link.getURLString());
485:            }
486:
487:            /**
488:             * Test if the response is a success
489:             * @param wr
490:             */
491:            private void testLinks(WebResponse wr) {
492:                assertEquals("a code of 200 (success) should be returned. ",
493:                        HTTP_SUCCESS_CODE, wr.getResponseCode());
494:            }
495:
496:            /**
497:             * Test jonasAdmin content titles
498:             * @param url The url of the link that was clicked
499:             * @throws SAXException if an error occurs when getElementsWithAttribute is called
500:             */
501:            private void testContentTitle(String url) throws SAXException {
502:
503:                WebResponse tree = null;
504:                WebResponse content = null;
505:                String treeTitle = null;
506:                String contentTitle = null;
507:
508:                // Verify content title of the content frame
509:                content = wc.getFrameContents(FRAME_CONTENT);
510:                tree = wc.getFrameContents(FRAME_TREE);
511:
512:                // Get title from the tree frame
513:                if (tree.getElementsWithAttribute("class",
514:                        CLASS_TREE_CONTROL_SELECTED).length == 1) {
515:                    treeTitle = new String(tree.getElementsWithAttribute(
516:                            "class", CLASS_TREE_CONTROL_SELECTED)[0].getText());
517:                }
518:
519:                // Get title from the content frame
520:                if (content.getElementsWithAttribute("class", "contentTitle").length == 1) {
521:                    contentTitle = new String(content.getElementsWithAttribute(
522:                            "class", "contentTitle")[0].getText());
523:                }
524:                if (treeTitle != null && contentTitle != null) {
525:                    assertEquals("The content title (" + contentTitle
526:                            + ") is different of the link name (" + treeTitle
527:                            + "). Clicked link was " + url, treeTitle,
528:                            contentTitle);
529:                } else {
530:                    if (!url.equals(URL_JONASADMIN)) {
531:                        if (treeTitle != null) {
532:                            try {
533:                                fail("Content title is null. Name of the selected link was "
534:                                        + treeTitle
535:                                        + ". Link URL: "
536:                                        + url
537:                                        + " Content frame: "
538:                                        + content.getText());
539:                            } catch (IOException e) {
540:                                fail("Content title is null. Name of the selected link was "
541:                                        + treeTitle
542:                                        + ". Link URL: "
543:                                        + url
544:                                        + " Error to get content frame text");
545:                            }
546:                        } else {
547:                            if (contentTitle != null) {
548:                                fail("No link is selected. Content title was "
549:                                        + contentTitle);
550:                            } else {
551:                                try {
552:                                    fail("No link and no content title are found. Tree frame: "
553:                                            + tree.getText()
554:                                            + ".  Content frame: "
555:                                            + content.getText());
556:                                } catch (IOException e) {
557:                                    fail("No link and no content title are found because there is a problem in tree frame or content frame. ");
558:                                }
559:                            }
560:                        }
561:                    }
562:                }
563:
564:                // To free memory
565:                content = null;
566:                tree = null;
567:            }
568:
569:            /**
570:             * Test jonasAdmin selection of tree items
571:             * @param selectedLink The url of the link that was clicked
572:             */
573:            private void testTreeSelected(String selectedLink) {
574:
575:                WebResponse tree = null;
576:
577:                // Verify tree frame
578:                tree = wc.getFrameContents(FRAME_TREE);
579:
580:                try {
581:                    if (!JonasAdminTree.treeControlSelected(tree, selectedLink)) {
582:                        fail("The name of the link " + selectedLink
583:                                + " is not selected in the tree.");
584:                    }
585:                } catch (SAXException sax) {
586:                    fail("" + sax);
587:                }
588:
589:                tree = null;
590:            }
591:
592:            /**
593:             * Test the jonasAdmin title tom thumb
594:             * @param url The url of the link that was clicked
595:             */
596:            private void testTitleTomThumb(String url) {
597:                WebResponse contentFrame = wc.getFrameContents(FRAME_CONTENT);
598:                WebResponse treeFrame = wc.getFrameContents(FRAME_TREE);
599:                WebTable thumbTable = null;
600:                WebTable treeTable = null;
601:                TableCell thumbCell = null;
602:                TableCell treeCell = null;
603:                String text = null;
604:                String[] thumbs = null;
605:                String[] treeThumbs = null;
606:                JonasAdminUtils utils = new JonasAdminUtils();
607:                int row;
608:                int column;
609:
610:                try {
611:                    thumbTable = contentFrame.getTables()[0];
612:                } catch (SAXException e) {
613:                    fail("There is no table in content frame: " + e);
614:                }
615:
616:                thumbCell = thumbTable.getTableCell(0, 0);
617:                text = thumbCell.getText();
618:                thumbs = text.split(" > ");
619:
620:                try {
621:                    treeTable = treeFrame.getTables()[0];
622:                } catch (SAXException e) {
623:                    fail("There is no table in tree frame: " + e);
624:                }
625:                JonasAdminUtils.CoordCell coord = utils
626:                        .getSelectedItemRow(treeTable);
627:
628:                if (!url.equals(URL_JONASADMIN)) {
629:                    row = coord.getRow().intValue();
630:                    column = coord.getColumn().intValue();
631:                    // get parents of the selected item
632:                    treeThumbs = new String[thumbs.length];
633:                    int i = thumbs.length;
634:                    while (row > 0 && column > 3 && i > 0) {
635:                        boolean found = false;
636:                        column--;
637:                        i--;
638:                        // get the row parent
639:                        int nextRow = row;
640:                        while (nextRow > 0 && !found) {
641:                            nextRow--;
642:                            treeCell = treeTable.getTableCell(nextRow,
643:                                    column - 2);
644:                            if (treeCell.getElementsWithAttribute("src",
645:                                    "images/tree/node_open_middle.gif").length == 1) {
646:                                treeCell = treeTable.getTableCell(nextRow,
647:                                        column);
648:                                treeThumbs[i] = treeCell.getText();
649:                                found = true;
650:                                assertEquals("For the link " + url,
651:                                        treeThumbs[i], thumbs[i]);
652:                            } else if (treeCell.getElementsWithAttribute("src",
653:                                    "images/tree/node_open_last.gif").length == 1) {
654:                                treeCell = treeTable.getTableCell(nextRow,
655:                                        column);
656:                                treeThumbs[i] = treeCell.getText();
657:                                found = true;
658:                                assertEquals("For the link " + url,
659:                                        treeThumbs[i], thumbs[i]);
660:                            } else if (treeCell.getElementsWithAttribute("src",
661:                                    "images/tree/node_open_first.gif").length == 1) {
662:                                treeCell = treeTable.getTableCell(nextRow,
663:                                        column);
664:                                treeThumbs[i] = treeCell.getText();
665:                                found = true;
666:                                assertEquals("For the link " + url,
667:                                        treeThumbs[i], thumbs[i]);
668:                            } else if (treeCell.getElementsWithAttribute("src",
669:                                    "images/tree/node_open.gif").length == 1) {
670:                                treeCell = treeTable.getTableCell(nextRow,
671:                                        column);
672:                                treeThumbs[i] = treeCell.getText();
673:                                found = true;
674:                                assertEquals("For the link " + url,
675:                                        treeThumbs[i], thumbs[i]);
676:                            }
677:                        }
678:                        row = nextRow;
679:                    }
680:                }
681:            }
682:
683:            /**
684:             * Test links, content titles, selected tree of mbeans
685:             * @throws Exception if an error occurs
686:             */
687:            private void testMBean(Vector viewedURLs) throws Exception {
688:                WebResponse wr = wc.getFrameContents(FRAME_TREE);
689:                WebLink link;
690:
691:                // Open MBean branch
692:                if (wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
693:                        "viewTree.do?tree=domain*mbeans*j2ee") == null) {
694:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
695:                            "viewTree.do?tree=domain*mbeans");
696:                    if (link == null) {
697:                        throw new IllegalStateException(
698:                                "The link viewTree.do?domain*mbeans is not found in tree. ");
699:                    }
700:                    wr = link.click();
701:                }
702:                // J2EE MBeans
703:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
704:                        "viewTree.do?tree=domain*mbeans*j2ee");
705:                if (link == null) {
706:                    throw new IllegalStateException(
707:                            "The link viewTree.do?domain*mbeans*j2ee is not found in tree. ");
708:                }
709:                wr = link.click();
710:
711:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
712:                        "viewTree.do?tree=domain*mbeans*j2ee*");
713:                if (link == null) {
714:                    throw new IllegalStateException(
715:                            "The link viewTree.do?domain*mbeans*j2ee* is not found in tree. ");
716:                }
717:                wr = link.click();
718:
719:                link = wr.getMatchingLinks(WebLink.MATCH_URL_STRING,
720:                        "viewTree.do?tree=domain*mbeans*j2ee*")[1];
721:                if (link == null) {
722:                    throw new IllegalStateException(
723:                            "The 2nd link viewTree.do?domain*mbeans*j2ee* is not found in tree. ");
724:                }
725:                wr = link.click();
726:                // OWNER MBeans
727:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
728:                        "viewTree.do?tree=domain*mbeans*owner");
729:                if (link == null) {
730:                    throw new IllegalStateException(
731:                            "The link viewTree.do?domain*mbeans*owner is not found in tree. ");
732:                }
733:                wr = link.click();
734:
735:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
736:                        "viewTree.do?tree=domain*mbeans*owner*");
737:                if (link == null) {
738:                    throw new IllegalStateException(
739:                            "The link viewTree.do?domain*mbeans*owner* is not found in tree. ");
740:                }
741:                wr = link.click();
742:
743:                link = wr.getMatchingLinks(WebLink.MATCH_URL_STRING,
744:                        "viewTree.do?tree=domain*mbeans*owner*")[1];
745:                if (link == null) {
746:                    throw new IllegalStateException(
747:                            "The 2nd link viewTree.do?domain*mbeans*owner* is not found in tree. ");
748:                }
749:                wr = link.click();
750:
751:                // OTHER MBeans
752:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
753:                        "viewTree.do?tree=domain*mbeans*unknown");
754:                if (link == null) {
755:                    throw new IllegalStateException(
756:                            "The link viewTree.do?domain*mbeans*unknow is not found in tree. ");
757:                }
758:                wr = link.click();
759:
760:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
761:                        "viewTree.do?tree=domain*mbeans*unknown*");
762:                if (link == null) {
763:                    throw new IllegalStateException(
764:                            "The link viewTree.do?domain*mbeans*unknow* is not found in tree. ");
765:                }
766:                wr = link.click();
767:
768:                link = wr.getMatchingLinks(WebLink.MATCH_URL_STRING,
769:                        "viewTree.do?tree=domain*mbeans*unknown*")[1];
770:                if (link == null) {
771:                    throw new IllegalStateException(
772:                            "The 2nd link viewTree.do?domain*mbeans*unknow* is not found in tree. ");
773:                }
774:                wr = link.click();
775:
776:                // Tests - ListMBeans.do
777:                wr = wc.getFrameContents(FRAME_TREE);
778:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
779:                        "ListMBeans.do");
780:                if (link == null) {
781:                    throw new IllegalStateException(
782:                            "ListMBeans.do was not found in tree. ");
783:                }
784:                executeTests(wr, link, viewedURLs);
785:
786:                // Tests - ListJ2eeMBeans.do
787:                wr = wc.getFrameContents(FRAME_TREE);
788:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
789:                        "ListJ2eeMBeans.do");
790:                if (link == null) {
791:                    throw new IllegalStateException(
792:                            "ListJ2eeMBeans.do was not found in tree. ");
793:                }
794:                executeTests(wr, link, viewedURLs);
795:
796:                // Tests - ListOwnerMBeans.do
797:                wr = wc.getFrameContents(FRAME_TREE);
798:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
799:                        "ListOwnerMBeans.do");
800:                if (link == null) {
801:                    throw new IllegalStateException(
802:                            "ListOwnerMBeans.do was not found in tree. ");
803:                }
804:                executeTests(wr, link, viewedURLs);
805:
806:                // Tests - ListUnknownMBeans.do
807:                wr = wc.getFrameContents(FRAME_TREE);
808:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
809:                        "ListUnknownMBeans.do");
810:                if (link == null) {
811:                    throw new IllegalStateException(
812:                            "ListUnknownMBeans.do was not found in tree. ");
813:                }
814:                executeTests(wr, link, viewedURLs);
815:
816:                // Tests - ListMBeanDetails.do
817:                wr = wc.getFrameContents(FRAME_TREE);
818:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
819:                        "ListMBeanDetails.do");
820:                if (link == null) {
821:                    throw new IllegalStateException(
822:                            "ListMBeanDetails.do was not found in tree. ");
823:                }
824:                executeTests(wr, link, viewedURLs);
825:
826:                // Tests - ListMBeanAttributes.do
827:                wr = wc.getFrameContents(FRAME_CONTENT);
828:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
829:                        "ListMBeanAttributes.do");
830:                if (link == null) {
831:                    throw new IllegalStateException(
832:                            "ListMBeansAttributes.do was not found in tree. ");
833:                }
834:                executeTests(wr, link, viewedURLs);
835:
836:                // Tests - ListMBeanOperations.do
837:                wr = wc.getFrameContents(FRAME_CONTENT);
838:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
839:                        "ListMBeanOperations.do");
840:                if (link == null) {
841:                    throw new IllegalStateException(
842:                            "ListMBeansOperations.do was not found in tree. ");
843:                }
844:                executeTests(wr, link, viewedURLs);
845:
846:                // Tests - ListMBeanProperties.do
847:                wr = wc.getFrameContents(FRAME_CONTENT);
848:                link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
849:                        "ListMBeanProperties.do");
850:                if (link == null) {
851:                    throw new IllegalStateException(
852:                            "ListMBeansProperties.do was not found in tree. ");
853:                }
854:                executeTests(wr, link, viewedURLs);
855:            }
856:
857:            /**
858:             * Tear Down cleanUp action
859:             * @throws Exception if an error occurs for close JMX connection
860:             */
861:            public void tearDown() throws Exception {
862:                super .tearDown();
863:                // Get time
864:                endTime = getTime();
865:
866:                // Delete created files: server.xml
867:                JonasAdminFiles.recoverServerConf(beginTime, endTime);
868:            }
869:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.