Source Code Cross Referenced for F_JonasAdminDomain.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jonasadmin » test » domain » 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.domain 
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_JonasAdminDomain.java 8091 2006-03-07 15:29:27Z danesa $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.jonasadmin.test.domain;
025:
026:        import junit.framework.TestSuite;
027:
028:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
029:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
030:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
031:        import org.xml.sax.SAXException;
032:
033:        import com.meterware.httpunit.HttpUnitOptions;
034:        import com.meterware.httpunit.HttpUnitUtils;
035:        import com.meterware.httpunit.TableCell;
036:        import com.meterware.httpunit.WebLink;
037:        import com.meterware.httpunit.WebResponse;
038:        import com.meterware.httpunit.WebTable;
039:
040:        /**
041:         * Define a class to add useful methods for test the examples
042:         *  - Execute the EditDomainAction
043:         * @author Paul Kemler
044:         */
045:        public class F_JonasAdminDomain extends JonasAdminTestCase {
046:            /**
047:             * default domain name
048:             */
049:            private static final String DOMAIN_NAME = "jonas";
050:            /**
051:             * default server name
052:             */
053:            private static final String SERVER_NAME = "jonas";
054:            /**
055:             * default jonas domain description in domain.xml
056:             */
057:            private static final String DESCRIPTION = "A domain named jonas";
058:            /**
059:             *
060:             */
061:            private static final String TITLE_OTHERSERVERS = "Servers in domain";
062:            /**
063:             * Domain type set to domainForm by EditDomainAction
064:             */
065:            private static final String TITLE_DOMAIN = "Domain";
066:            /**
067:             * label.domain.properties
068:             */
069:            private static final String TITLE_PROPERTIES = "properties";
070:            /**
071:             * label.domain.servers
072:             */
073:            private static final String TITLE_SERVERS = "Servers in domain";
074:            /**
075:             * message.domain.servers.none
076:             */
077:            private static final String MESSAGE_NO_SERVERS = "No other server in this domain!";
078:            /**
079:             * label.domain.clusters
080:             */
081:            private static final String TITLE_CLUSTERS = "Clusters";
082:            /**
083:             * message.domain.clusters.none
084:             */
085:            private static final String MESSAGE_NO_CLUSTERS = "No clusters in this domain!";
086:
087:            /**
088:             * Main method
089:             * @param args the arguments
090:             */
091:            public static void main(String[] args) {
092:
093:                String testtorun = null;
094:                // Get args
095:                for (int argn = 0; argn < args.length; argn++) {
096:                    String sArg = args[argn];
097:                    if (sArg.equals("-n")) {
098:                        testtorun = args[++argn];
099:                    }
100:                }
101:                if (testtorun == null) {
102:                    junit.textui.TestRunner.run(suite());
103:                } else {
104:                    junit.textui.TestRunner.run(new F_JonasAdminDomain(
105:                            testtorun));
106:                }
107:            }
108:
109:            /**
110:             * Get a new TestSuite for this class
111:             * @return a new TestSuite for this class
112:             */
113:            public static TestSuite suite() {
114:                return new TestSuite(F_JonasAdminDomain.class);
115:            }
116:
117:            /**
118:             * Setup need for these tests
119:             * jonasAdmin is required
120:             * @throws Exception if it fails
121:             */
122:            protected void setUp() throws Exception {
123:                super .setUp();
124:
125:                if (wc.getCurrentPage().getURL() == null) {
126:                    useWar("jonasAdmin");
127:                    // login to jonas admin
128:                    try {
129:                        JonasAdminAuth.doValidAuth(wc, url);
130:                    } catch (Exception e) {
131:                        fail("authentification failed :  " + e);
132:                    }
133:                } else {
134:                    // if there was an error, the connection must be restablished
135:                    try {
136:                        wc.getFrameContents(FRAME_TREE);
137:                    } catch (Exception e) {
138:                        wc.getResponse(urlLogOut);
139:                        // login to jonas admin
140:                        try {
141:                            JonasAdminAuth.doValidAuth(wc, url);
142:                        } catch (Exception auth) {
143:                            fail("authentification failed :  " + auth);
144:                        }
145:                    }
146:                }
147:            }
148:
149:            /**
150:             * Constructor with a specified name
151:             * @param s name
152:             */
153:            public F_JonasAdminDomain(String s) {
154:                super (s, URL_JONASADMIN);
155:            }
156:
157:            /**
158:             * Verify if it is the good link of the tree which is selected
159:             * @param wr The WebResponse of the 'tree' frame
160:             * @param name A string with the name of the link
161:             * @return a boolean. True if the name is found in the link, else false.
162:             */
163:            private boolean treeControlSelected(WebResponse wr, String name) {
164:                boolean isSelected = false; // the result
165:                int nbSelectedLink = 0; // number of selected link
166:                String attribut; // value of class attribut
167:
168:                // Get all links
169:                WebLink[] links;
170:                try {
171:                    links = wr.getLinks();
172:
173:                    // Search links with the 'tree-control-selected' class attribut
174:                    // and increase nbSelectedLink
175:                    for (int i = 0; i < links.length; i++) {
176:                        attribut = links[i].getAttribute("class");
177:                        if (attribut.indexOf("tree-control-selected") != -1) {
178:                            nbSelectedLink++;
179:                        }
180:                    }
181:
182:                    if (nbSelectedLink == 1) {
183:                        WebLink link = wr.getLinkWith(name);
184:                        String content = link.getAttribute("class");
185:                        if (content.indexOf("tree-control-selected") != -1) {
186:                            isSelected = true;
187:                        }
188:                    }
189:                } catch (SAXException e) {
190:                    fail("No link was found. " + e);
191:                }
192:
193:                return isSelected;
194:            }
195:
196:            /**
197:             * Test Succesful Select
198:             * @throws Exception if it fails
199:             *
200:             */
201:            public void testSuccessfulSelect() throws Exception {
202:
203:                // Disable errors of javascript
204:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
205:
206:                // Get the frame "tree"
207:                WebResponse treeFrame = wc.getFrameContents(FRAME_TREE);
208:
209:                // Create a request
210:                WebLink link = treeFrame.getLinkWith("Domain");
211:                link.click();
212:
213:                // Get the frame "tree"
214:                treeFrame = wc.getFrameContents(FRAME_TREE);
215:
216:                // Verify if the attribut class that values "tree-control-selected"
217:                // it is in a link with "Domain"
218:                if (!treeControlSelected(treeFrame, "Domain")) {
219:                    fail("Domain is not selected in the tree.");
220:                }
221:
222:                // Create a new request for going to another page
223:                link = treeFrame.getLinkWith("Services");
224:                link.click();
225:
226:                // Get the frame "tree"
227:                treeFrame = wc.getFrameContents(FRAME_TREE);
228:
229:                // Verify if the attribut class that values "tree-control-selected"
230:                // it is NOT in a link with "Domain"
231:                if (treeControlSelected(treeFrame, "Domain")) {
232:                    fail("Domain is selected in the tree.");
233:                }
234:
235:                // Create a new request for going to another page
236:                link = treeFrame.getLinkWith("Domain");
237:                link.click();
238:
239:                // Get the frame "tree"
240:                treeFrame = wc.getFrameContents(FRAME_TREE);
241:
242:                // Verify if the attribut class that values "tree-control-selected"
243:                // it is in a link with "Domain"
244:                if (!treeControlSelected(treeFrame, "Domain")) {
245:                    fail("Domain is not selected in the tree.");
246:                }
247:
248:            }
249:
250:            /**
251:             * Test Succesful Master Server Link
252:             * @throws Exception if it fails
253:             *
254:             */
255:            public void testSuccesfulServerLink() throws Exception {
256:
257:                // The expected link
258:                String expectedLink = URL_JONASADMIN
259:                        + "EditJonasServer.do?select=jonas:j2eeType=J2EEServer,name=jonas";
260:
261:                // Disable errors of javascript
262:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
263:
264:                // Get the frame "tree"
265:                WebResponse treeFrame = wc.getFrameContents(FRAME_TREE);
266:
267:                // Create a request
268:                WebLink link = treeFrame.getLinkWith("Domain");
269:                link.click();
270:
271:                // Get the response
272:                WebResponse wr = wc.getFrameContents(FRAME_CONTENT);
273:
274:                // Verify the link to the JonasAdmin's server (the master)
275:                link = wr.getLinks()[0];
276:                String actualLink = link.getAttribute("href");
277:                actualLink = HttpUnitUtils.decode(actualLink);
278:                assertEquals("The link of the JonasAdmin's server is wrong.",
279:                        expectedLink, actualLink);
280:            }
281:
282:            /**
283:             * Test if Domain presentation is correct
284:             * @throws Exception if it fails
285:             *
286:             */
287:            public void testDomainProperties() throws Exception {
288:                JonasAdminUtils utils = new JonasAdminUtils();
289:                // Disable errors of javascript
290:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
291:
292:                // Get the frame "tree"
293:                WebResponse treeFrame = wc.getFrameContents(FRAME_TREE);
294:
295:                // Create a request
296:                WebLink link = treeFrame.getLinkWith("Domain");
297:                link.click();
298:
299:                // Get the response
300:                WebResponse wr = wc.getFrameContents(FRAME_CONTENT);
301:
302:                // Properties table
303:                // - Title table -
304:                // We are expecting "Domain properties"
305:                WebTable table = utils.getTable(wr, 0);
306:                TableCell cell = table.getTableCell(0, 0);
307:                String text = cell.getText();
308:                boolean found;
309:                if (text.indexOf(TITLE_DOMAIN) == 0
310:                        && text.indexOf(TITLE_PROPERTIES) > 0) {
311:                    found = true;
312:                } else {
313:                    found = false;
314:                }
315:                assertTrue("Can't find title " + TITLE_DOMAIN + " "
316:                        + TITLE_PROPERTIES, found);
317:                // - Table content -
318:                table = utils.getTable(wr, 1);
319:                // First row Name jonas
320:                cell = table.getTableCell(0, 0);
321:                String propText = cell.getText();
322:                // step over 2nd cell conataining &nbsp;
323:                cell = table.getTableCell(0, 2);
324:                String valuText = cell.getText();
325:                if (propText.indexOf("Name") >= 0
326:                        && valuText.indexOf(DOMAIN_NAME) >= 0) {
327:                    found = true;
328:                } else {
329:                    found = false;
330:                }
331:                assertTrue("The Name property is not " + DOMAIN_NAME, found);
332:                // Next row
333:                cell = table.getTableCell(1, 0);
334:                propText = cell.getText();
335:                // step over 2nd cell conataining &nbsp;
336:                cell = table.getTableCell(1, 2);
337:                valuText = cell.getText();
338:                if (propText.indexOf("Description") >= 0
339:                        && valuText.indexOf(DESCRIPTION) >= 0) {
340:                    found = true;
341:                } else {
342:                    found = false;
343:                }
344:                assertTrue("The Description property is not " + DESCRIPTION,
345:                        found);
346:                // Next row
347:                cell = table.getTableCell(2, 0);
348:                propText = cell.getText();
349:                // step over 2nd cell conataining &nbsp;
350:                cell = table.getTableCell(2, 2);
351:                valuText = cell.getText();
352:                if (propText.indexOf("Master server") >= 0
353:                        && valuText.indexOf(SERVER_NAME) >= 0) {
354:                    found = true;
355:                } else {
356:                    found = false;
357:                }
358:                assertTrue("The Master server property is not " + SERVER_NAME,
359:                        found);
360:
361:                // Servers table
362:                // - Title table -
363:                // We are expecting "Servers in domain"
364:                table = utils.getTable(wr, 3);
365:                cell = table.getTableCell(0, 0);
366:                text = cell.getText();
367:                if (text.indexOf(TITLE_SERVERS) >= 0) {
368:                    found = true;
369:                } else {
370:                    found = false;
371:                }
372:                assertTrue("Can't find title " + TITLE_SERVERS, found);
373:                // - Action zone
374:                table = utils.getTable(wr, 4);
375:                cell = table.getTableCell(0, 0);
376:                text = cell.getText();
377:                if (text.indexOf("Action") >= 0) {
378:                    found = true;
379:                } else {
380:                    found = false;
381:                }
382:                assertTrue("Can't find Action zone", found);
383:                // Button zone
384:                table = utils.getTable(wr, 5);
385:                cell = table.getTableCell(0, 0);
386:                WebLink[] links = cell.getLinks();
387:                if (links.length >= 1) {
388:                    found = true;
389:                } else {
390:                    found = false;
391:                }
392:                assertTrue("Can't find link in Action zone", found);
393:                // Servers list
394:                table = utils.getTable(wr, 7);
395:                cell = table.getTableCell(0, 0);
396:                text = cell.getText();
397:                if (text.indexOf(MESSAGE_NO_SERVERS) >= 0) {
398:                    found = true;
399:                } else {
400:                    found = false;
401:                }
402:                assertTrue("Expecting " + MESSAGE_NO_SERVERS + ", found "
403:                        + text, found);
404:
405:                // Clusters table
406:                // - Title table -
407:                // We are expecting "Clusters"
408:                table = utils.getTable(wr, 9);
409:                cell = table.getTableCell(0, 0);
410:                text = cell.getText();
411:                if (text.indexOf(TITLE_CLUSTERS) >= 0) {
412:                    found = true;
413:                } else {
414:                    found = false;
415:                }
416:                assertTrue("Can't find title " + TITLE_CLUSTERS, found);
417:                // - Action zone
418:                table = utils.getTable(wr, 10);
419:                cell = table.getTableCell(0, 0);
420:                text = cell.getText();
421:                if (text.indexOf("Action") >= 0) {
422:                    found = true;
423:                } else {
424:                    found = false;
425:                }
426:                assertTrue("Can't find Action zone", found);
427:                // Button zone
428:                table = utils.getTable(wr, 11);
429:                cell = table.getTableCell(0, 0);
430:                links = cell.getLinks();
431:                if (links.length >= 1) {
432:                    found = true;
433:                } else {
434:                    found = false;
435:                }
436:                assertTrue("Can't find link in Action zone", found);
437:                // Clusters list
438:                table = utils.getTable(wr, 13);
439:                cell = table.getTableCell(0, 0);
440:                text = cell.getText();
441:                if (text.indexOf(MESSAGE_NO_CLUSTERS) >= 0) {
442:                    found = true;
443:                } else {
444:                    found = false;
445:                }
446:                assertTrue("Expecting " + MESSAGE_NO_CLUSTERS + ", found "
447:                        + text, found);
448:            }
449:
450:            /**
451:             * Tear Down cleanUp action
452:             * @throws Exception if an error occurs
453:             */
454:            public void tearDown() throws Exception {
455:                super.tearDown();
456:            }
457:
458:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.