Source Code Cross Referenced for F_JonasAdminResourceMail.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jonasadmin » test » resource » 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.resource 
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_JonasAdminResourceMail.java 8102 2006-03-09 15:06:20Z danesa $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.jonasadmin.test.resource;
025:
026:        import java.util.Properties;
027:
028:        import junit.framework.TestSuite;
029:
030:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
031:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminFiles;
032:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
033:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
034:
035:        import com.meterware.httpunit.HttpUnitOptions;
036:        import com.meterware.httpunit.SubmitButton;
037:        import com.meterware.httpunit.TableCell;
038:        import com.meterware.httpunit.WebForm;
039:        import com.meterware.httpunit.WebLink;
040:        import com.meterware.httpunit.WebResponse;
041:        import com.meterware.httpunit.WebTable;
042:
043:        /**
044:         * Class for testing Resource
045:         * @author Paul Kemler
046:         *
047:         */
048:        public class F_JonasAdminResourceMail extends JonasAdminTestCase {
049:
050:            /**
051:             * URL of mail service
052:             */
053:            private static final String URL_JONASADMIN_MAIL_SERVICE = "EditMailService.do";
054:
055:            /**
056:             * URL of Mail resource
057:             */
058:            private static final String URL_JONASADMIN_MAIL = "EditDeploy.do?type=mail";
059:
060:            /**
061:             * URL of list mail factories
062:             */
063:            private static final String URL_JONASADMIN_LIST_MAIL_FACTORIES = "ListMailFactories.do";
064:
065:            /**
066:             * URL of deploy
067:             */
068:            private static final String URL_JONASADMIN_DEPLOY = "EditDeploy.do";
069:
070:            /**
071:             * URL of create mail factory
072:             */
073:            private static final String URL_JONASADMIN_CREATE_MAIL_FACTORY = "EditMailFactoryProperties.do?action=create";
074:
075:            /**
076:             * URL of Mail resource viewTree
077:             */
078:            private static final String URL_JONASADMIN_VIEW_MAIL = "viewTree.do?tree=domain*jonas*resources";
079:
080:            /**
081:             * number of tabs when you are in the mail tabs
082:             */
083:            private static final int NUMBER_OF_TABS_FOR_MAIL = 2;
084:
085:            /**
086:             * number of tabs when you are in the CONFIRM tabs
087:             */
088:            private static final int NUMBER_OF_TABS_FOR_CONFIRM = 2;
089:
090:            /**
091:             * number of tabs when you are in the 'new mail factory' tabs
092:             */
093:            private static final int NUMBER_OF_TABS_FOR_NEW_MAIL_FACTORY = 3;
094:
095:            /**
096:             * name of the mail factory
097:             */
098:            private String name = "";
099:
100:            /**
101:             * Constructor with a specified name
102:             * @param s name
103:             */
104:            public F_JonasAdminResourceMail(String s) {
105:                super (s, URL_JONASADMIN);
106:            }
107:
108:            /**
109:             * Main method
110:             * @param args the arguments
111:             */
112:            public static void main(String[] args) {
113:
114:                String testtorun = null;
115:                // Get args
116:                for (int argn = 0; argn < args.length; argn++) {
117:                    String sArg = args[argn];
118:                    if (sArg.equals("-n")) {
119:                        testtorun = args[++argn];
120:                    }
121:                }
122:                if (testtorun == null) {
123:                    junit.textui.TestRunner.run(suite());
124:                } else {
125:                    junit.textui.TestRunner.run(new F_JonasAdminResourceMail(
126:                            testtorun));
127:                }
128:            }
129:
130:            /**
131:             * Get a new TestSuite for this class
132:             * @return a new TestSuite for this class
133:             */
134:            public static TestSuite suite() {
135:                return new TestSuite(F_JonasAdminResourceMail.class);
136:            }
137:
138:            /**
139:             * Setup need for these tests
140:             * jonasAdmin is required
141:             * @throws Exception if it fails
142:             */
143:            protected void setUp() throws Exception {
144:                super .setUp();
145:
146:                if (wc.getCurrentPage().getURL() == null) {
147:                    useWar("jonasAdmin");
148:                    // login to jonas admin
149:                    try {
150:                        JonasAdminAuth.doValidAuth(wc, url);
151:                    } catch (Exception e) {
152:                        fail("authentification failed :  " + e);
153:                    }
154:                } else {
155:                    // if there was an error, the connection must be restablished
156:                    try {
157:                        wc.getFrameContents(FRAME_TREE);
158:                    } catch (Exception e) {
159:                        wc.getResponse(urlLogOut);
160:                        // login to jonas admin
161:                        try {
162:                            JonasAdminAuth.doValidAuth(wc, url);
163:                        } catch (Exception auth) {
164:                            fail("authentification failed :  " + auth);
165:                        }
166:                    }
167:                }
168:            }
169:
170:            /**
171:             * Test to deploy and undeploy a mail factory
172:             * @throws Exception if error occurs
173:             */
174:            public void testUndeployDeployMailFactory() throws Exception {
175:
176:                WebResponse wr;
177:                WebLink link;
178:                WebTable table;
179:                WebTable tabTable;
180:                int selectedTab;
181:                /*
182:                 * To get some utils for WebTable
183:                 */
184:                JonasAdminUtils utils = new JonasAdminUtils();
185:
186:                // Disable errors of javascript
187:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
188:                // Disable exception thrown on error status
189:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
190:
191:                if (jProp.isMail()) {
192:                    // Add mail factory
193:                    name = "new_mailFactory";
194:                    Properties properties = new Properties();
195:                    // mail.authentication.password=
196:                    properties.put("mail.authentication.password", "");
197:                    // mail.factory.type=javax.mail.Session
198:                    properties.put("mail.factory.type", "javax.mail.Session");
199:                    // mail.authentication.username=
200:                    properties.put("mail.authentication.username", "");
201:                    // mail.host=
202:                    properties.put("mail.host", "");
203:                    // mail.factory.name=   name
204:                    properties.put("mail.factory.name", name);
205:
206:                    // Add a mail factory
207:                    if (isInMailFactoryList(name)) {
208:
209:                        // remove mail factory
210:                        unBindMailFactory(name);
211:                    }
212:                    createMailFactory(name, properties);
213:
214:                    // Go to Mail
215:                    wr = wc.getFrameContents(FRAME_TREE);
216:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
217:                            URL_JONASADMIN_MAIL);
218:                    link.click();
219:                    wr = wc.getFrameContents(FRAME_CONTENT);
220:                    selectedTab = 1;
221:
222:                    // Verify tabs
223:                    tabTable = utils.getTabTable(wr);
224:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_MAIL, selectedTab,
225:                            "Problem in 'Deployment' tab.");
226:                    // - links
227:                    assertTrue("The link " + URL_JONASADMIN_LIST_MAIL_FACTORIES
228:                            + " is not found in the second tab. ", tabTable
229:                            .getTableCell(0, 2).getLinks()[0].getURLString()
230:                            .endsWith(URL_JONASADMIN_LIST_MAIL_FACTORIES));
231:
232:                    String txt = getDeployTable(wr, true);
233:
234:                    if (txt.indexOf(name) == -1) {
235:                        fail("The file" + name + " was not found as deployed.");
236:                    }
237:
238:                    // Undeploy mail factory
239:                    WebForm[] webForms = wr.getForms();
240:                    WebForm webForm = webForms[0];
241:
242:                    String params = webForm.getParameterValue("undeploy");
243:                    WebForm.Scriptable script = webForm.getScriptableObject();
244:                    if (params.length() == 0) {
245:                        params += name;
246:                    } else {
247:                        params += "," + name;
248:                    }
249:                    script.setParameterValue("undeploy", params);
250:
251:                    SubmitButton button = webForm.getSubmitButtons()[0];
252:                    button.click();
253:
254:                    // Confirm
255:                    WebResponse submitUndeploy = wc
256:                            .getFrameContents(FRAME_CONTENT);
257:                    selectedTab = 2;
258:
259:                    // Verify tabs
260:                    tabTable = utils.getTabTable(submitUndeploy);
261:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab,
262:                            "Problem in 'Confirm' tab.");
263:                    // - links
264:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
265:                            + " is not found in the first tab. ", tabTable
266:                            .getTableCell(0, 0).getLinks()[0].getURLString()
267:                            .endsWith(URL_JONASADMIN_DEPLOY));
268:                    webForms = submitUndeploy.getForms();
269:                    webForm = webForms[0];
270:
271:                    button = webForm.getSubmitButtons()[0];
272:                    button.click();
273:                    wr = wc.getFrameContents(FRAME_CONTENT);
274:
275:                    // Verify tabs
276:                    tabTable = utils.getTabTable(wr);
277:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab,
278:                            "Problem in 'Result' tab.");
279:                    // - links
280:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
281:                            + " is not found in the first tab. ", tabTable
282:                            .getTableCell(0, 0).getLinks()[0].getURLString()
283:                            .endsWith(URL_JONASADMIN_DEPLOY));
284:
285:                    // Go back to Deployment
286:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
287:                            URL_JONASADMIN_DEPLOY);
288:                    link.click();
289:                    wr = wc.getFrameContents(FRAME_CONTENT);
290:                    selectedTab = 1;
291:
292:                    // Verify tabs
293:                    tabTable = utils.getTabTable(wr);
294:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_MAIL, selectedTab,
295:                            "Problem in 'Deployment' tab.");
296:                    // - links
297:                    assertTrue("The link " + URL_JONASADMIN_LIST_MAIL_FACTORIES
298:                            + " is not found in the second tab. ", tabTable
299:                            .getTableCell(0, 2).getLinks()[0].getURLString()
300:                            .endsWith(URL_JONASADMIN_LIST_MAIL_FACTORIES));
301:
302:                    txt = getDeployTable(wr, true);
303:
304:                    if (txt.indexOf(name) != -1) {
305:                        fail("The jonasAdmin webApp has not removed " + name);
306:                    }
307:
308:                    // now deploy
309:                    webForms = wr.getForms();
310:                    webForm = webForms[0];
311:
312:                    params = webForm.getParameterValue("deploy");
313:                    script = webForm.getScriptableObject();
314:
315:                    if (params.length() == 0) {
316:                        params += name;
317:                    } else {
318:                        params += "," + name;
319:                    }
320:
321:                    script.setParameterValue("deploy", params);
322:                    button = webForm.getSubmitButtons()[0];
323:                    button.click();
324:
325:                    // Confirm
326:                    submitUndeploy = wc.getFrameContents(FRAME_CONTENT);
327:                    // war is in the table
328:                    webForms = submitUndeploy.getForms();
329:                    webForm = webForms[0];
330:
331:                    button = webForm.getSubmitButtons()[0];
332:                    button.click();
333:
334:                    // Go back to Deployment
335:                    wr = wc.getFrameContents(FRAME_CONTENT);
336:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
337:                            URL_JONASADMIN_DEPLOY);
338:                    link.click();
339:                    wr = wc.getFrameContents(FRAME_CONTENT);
340:
341:                    txt = getDeployTable(wr, true);
342:
343:                    if (txt.indexOf(name) == -1) {
344:                        fail("The file " + name + " was not found as deployed.");
345:                    }
346:                }
347:            }
348:
349:            /**
350:             * Test to create a new mail factory
351:             * @throws Exception if error occurs
352:             */
353:            public void testCreateNewSessionMailFactory() throws Exception {
354:
355:                WebResponse wr;
356:                WebLink link;
357:                WebTable table;
358:                WebTable tabTable;
359:                int selectedTab;
360:                // Name of the mail factory
361:                name = "new_mailFactory_";
362:                String username = "";
363:                String password = "";
364:                String sessionProps = "";
365:                String to = "";
366:                String subject = "";
367:                String cc = "";
368:                String bcc = "";
369:
370:                /*
371:                 * To get some utils for WebTable
372:                 */
373:                JonasAdminUtils utils = new JonasAdminUtils();
374:
375:                // Disable errors of javascript
376:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
377:                // Disable exception thrown on error status
378:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
379:
380:                if (jProp.isMail()) {
381:
382:                    // Go to mail
383:                    wr = wc.getFrameContents(FRAME_TREE);
384:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
385:                            URL_JONASADMIN_MAIL);
386:                    link.click();
387:                    wr = wc.getFrameContents(FRAME_CONTENT);
388:                    selectedTab = 1;
389:
390:                    // Go to mail factories
391:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
392:                            URL_JONASADMIN_LIST_MAIL_FACTORIES);
393:                    link.click();
394:                    wr = wc.getFrameContents(FRAME_CONTENT);
395:                    selectedTab = 2;
396:
397:                    // Verify tabs
398:                    tabTable = utils.getTabTable(wr);
399:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_MAIL, selectedTab,
400:                            "Problem in 'Mail Factories' tab.");
401:                    // - links
402:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
403:                            + " is not found in the first tab. ", tabTable
404:                            .getTableCell(0, 0).getLinks()[0].getURLString()
405:                            .endsWith(URL_JONASADMIN_DEPLOY));
406:
407:                    // Find a new name
408:                    boolean found = false;
409:                    int i = 0;
410:                    while (!found) {
411:                        if ((wr.getText().indexOf(name + i) == -1)) {
412:                            name = name + i;
413:                            found = true;
414:                        }
415:                        i++;
416:                    }
417:
418:                    // Create a new Session Mail Factory
419:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
420:                            URL_JONASADMIN_CREATE_MAIL_FACTORY);
421:                    link.click();
422:                    wr = wc.getFrameContents(FRAME_CONTENT);
423:                    selectedTab = 3;
424:
425:                    // Verify tabs
426:                    tabTable = utils.getTabTable(wr);
427:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_NEW_MAIL_FACTORY,
428:                            selectedTab, "Problem in 'New mail factory' tab.");
429:                    // - links
430:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
431:                            + " is not found in the first tab. ", tabTable
432:                            .getTableCell(0, 0).getLinks()[0].getURLString()
433:                            .endsWith(URL_JONASADMIN_DEPLOY));
434:                    assertTrue("The link " + URL_JONASADMIN_LIST_MAIL_FACTORIES
435:                            + " is not found in the third tab. ", tabTable
436:                            .getTableCell(0, 2).getLinks()[0].getURLString()
437:                            .endsWith(URL_JONASADMIN_LIST_MAIL_FACTORIES));
438:
439:                    WebForm form = wr.getForms()[0];
440:
441:                    createSessionFactory(form, name, name, username, password,
442:                            sessionProps, to, subject, cc, bcc);
443:
444:                    wr = wc.getFrameContents(FRAME_CONTENT);
445:
446:                    // Verify if the mail factory is deployed
447:                    assertTrue(
448:                            "The created mail factory ('"
449:                                    + name
450:                                    + "') is not deployed. Restart jonas and try again. ",
451:                            isInMailFactoryList(name));
452:                    table = utils.getTable(wr, 3);
453:                    int mailFactoryRow = utils.getRow(name, table, 1)
454:                            .intValue();
455:                    if (mailFactoryRow == -1) {
456:                        fail("The mail factory '"
457:                                + name
458:                                + "' is not found in mail factory table. Restart jonas and try again. ");
459:                    } else {
460:                        // Verify if there is an image to indicate that the mail factory is deployed
461:                        TableCell cell = table.getTableCell(mailFactoryRow, 0);
462:                        assertEquals("There is no a image to indicate that '"
463:                                + name + "' mail factory is deployed. ", 1,
464:                                cell.getImages().length);
465:                    }
466:                }
467:            }
468:
469:            /**
470:             * Test to create a new MimePartDatasource mail factory
471:             * @throws Exception if error occurs
472:             */
473:            public void testCreateNewMimePartDSMailFactory() throws Exception {
474:
475:                WebResponse wr;
476:                WebLink link;
477:                WebTable table;
478:                WebTable tabTable;
479:                int selectedTab;
480:                // Name of the mail factory
481:                name = "new_mimePartDS_mailFactory_";
482:                String username = "";
483:                String password = "";
484:                String sessionProps = "";
485:                String to = "";
486:                String subject = "";
487:                String cc = "";
488:                String bcc = "";
489:
490:                /*
491:                 * To get some utils for WebTable
492:                 */
493:                JonasAdminUtils utils = new JonasAdminUtils();
494:
495:                // Disable errors of javascript
496:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
497:                // Disable exception thrown on error status
498:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
499:
500:                if (jProp.isMail()) {
501:
502:                    // Go to mail
503:                    wr = wc.getFrameContents(FRAME_TREE);
504:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
505:                            URL_JONASADMIN_MAIL);
506:                    link.click();
507:                    wr = wc.getFrameContents(FRAME_CONTENT);
508:                    selectedTab = 1;
509:
510:                    // Go to mail factories
511:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
512:                            URL_JONASADMIN_LIST_MAIL_FACTORIES);
513:                    link.click();
514:                    wr = wc.getFrameContents(FRAME_CONTENT);
515:                    selectedTab = 2;
516:
517:                    // Verify tabs
518:                    tabTable = utils.getTabTable(wr);
519:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_MAIL, selectedTab,
520:                            "Problem in 'Mail Factories' tab.");
521:                    // - links
522:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
523:                            + " is not found in the first tab. ", tabTable
524:                            .getTableCell(0, 0).getLinks()[0].getURLString()
525:                            .endsWith(URL_JONASADMIN_DEPLOY));
526:
527:                    // Find a new name
528:                    boolean found = false;
529:                    int i = 0;
530:                    while (!found) {
531:                        if ((wr.getText().indexOf(name + i) == -1)) {
532:                            name = name + i;
533:                            found = true;
534:                        }
535:                        i++;
536:                    }
537:
538:                    // Create a new MimePartDataSource Mail Factory
539:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
540:                            URL_JONASADMIN_CREATE_MAIL_FACTORY);
541:                    link.click();
542:                    wr = wc.getFrameContents(FRAME_CONTENT);
543:                    selectedTab = 3;
544:
545:                    // Verify tabs
546:                    tabTable = utils.getTabTable(wr);
547:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_NEW_MAIL_FACTORY,
548:                            selectedTab, "Problem in 'New mail factory' tab.");
549:                    // - links
550:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
551:                            + " is not found in the first tab. ", tabTable
552:                            .getTableCell(0, 0).getLinks()[0].getURLString()
553:                            .endsWith(URL_JONASADMIN_DEPLOY));
554:                    assertTrue("The link " + URL_JONASADMIN_LIST_MAIL_FACTORIES
555:                            + " is not found in the third tab. ", tabTable
556:                            .getTableCell(0, 2).getLinks()[0].getURLString()
557:                            .endsWith(URL_JONASADMIN_LIST_MAIL_FACTORIES));
558:
559:                    WebForm form = wr.getForms()[0];
560:
561:                    createMimePartDataSourceFactory(form, name, name, username,
562:                            password, sessionProps, to, subject, cc, bcc);
563:
564:                    wr = wc.getFrameContents(FRAME_CONTENT);
565:
566:                    // Verify if the mail factory is deployed
567:                    assertTrue(
568:                            "The created mail factory ('"
569:                                    + name
570:                                    + "') is not deployed. Restart jonas and try again. ",
571:                            isInMailFactoryList(name));
572:                    table = utils.getTable(wr, 3);
573:                    int mailFactoryRow = utils.getRow(name, table, 1)
574:                            .intValue();
575:                    if (mailFactoryRow == -1) {
576:                        fail("The mail factory '"
577:                                + name
578:                                + "' is not found in mail factory table. Restart jonas and try again. ");
579:                    } else {
580:                        // Verify if there is an image to indicate that the mail factory is deployed
581:                        TableCell cell = table.getTableCell(mailFactoryRow, 0);
582:                        assertEquals("There is no a image to indicate that '"
583:                                + name + "' mail factory is deployed. ", 1,
584:                                cell.getImages().length);
585:                    }
586:                }
587:            }
588:
589:            /**
590:             * Test to view empty value error message
591:             * @throws Exception if error occurs
592:             */
593:            public void testCreateMailFactoryWithEmptyValue() throws Exception {
594:
595:                WebResponse wr;
596:                WebLink link;
597:                WebTable table;
598:                WebTable tabTable;
599:                int selectedTab;
600:
601:                /*
602:                 * To get some utils for WebTable
603:                 */
604:                JonasAdminUtils utils = new JonasAdminUtils();
605:
606:                // Disable errors of javascript
607:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
608:                // Disable exception thrown on error status
609:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
610:
611:                if (jProp.isMail()) {
612:                    // Go to mail
613:                    wr = wc.getFrameContents(FRAME_TREE);
614:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
615:                            URL_JONASADMIN_MAIL);
616:                    link.click();
617:                    wr = wc.getFrameContents(FRAME_CONTENT);
618:                    selectedTab = 1;
619:
620:                    // Go to mail factories
621:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
622:                            URL_JONASADMIN_LIST_MAIL_FACTORIES);
623:                    link.click();
624:                    wr = wc.getFrameContents(FRAME_CONTENT);
625:                    selectedTab = 2;
626:
627:                    // Create a new mail factory
628:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
629:                            URL_JONASADMIN_CREATE_MAIL_FACTORY);
630:                    link.click();
631:                    wr = wc.getFrameContents(FRAME_CONTENT);
632:                    selectedTab = 3;
633:
634:                    WebForm form = wr.getForms()[0];
635:                    createNewEmptyMailFactory(form);
636:                    wr = wc.getFrameContents(FRAME_CONTENT);
637:
638:                    // Verify error messages
639:                    table = utils.getTable(wr, 0);
640:                    TableCell cell = table.getTableCell(0, 0);
641:
642:                    // class        errors
643:                    assertEquals(
644:                            "The value  of the class attribut of the cell is not 'errors'. ",
645:                            "errors", cell.getAttribute("class"));
646:                    // Can't accept empty Jndi name
647:                    String emptyJndiName = "Can't accept empty Jndi name";
648:                    assertTrue("The message '" + emptyJndiName
649:                            + "' is not found. ", cell.getText().indexOf(
650:                            emptyJndiName) != -1);
651:                    // Can't accept empty factory name
652:                    String emptyFactoryName = "Can't accept empty factory name";
653:                    assertTrue("The message '" + emptyFactoryName
654:                            + "' is not found. ", cell.getText().indexOf(
655:                            emptyFactoryName) != -1);
656:                    // Please check in the type
657:                    String emptyType = "Can't accept empty factory name";
658:                    assertTrue(
659:                            "The message '" + emptyType + "' is not found. ",
660:                            cell.getText().indexOf(emptyType) != -1);
661:                }
662:
663:            }
664:
665:            /**
666:             * Tear Down
667:             * cleanUp action
668:             */
669:            public void tearDown() throws Exception {
670:                if (jProp.isMail()) {// remove created mail factory file
671:                    if (!name.equals("")) {
672:                        if (isInMailFactoryList(name)) {
673:                            // remove mail factory
674:                            unBindMailFactory(name);
675:                            // Delete file
676:                            JonasAdminFiles.deleteConfigFile(name
677:                                    + ".properties");
678:                            name = "";
679:                        }
680:                    }
681:                }
682:                super .tearDown();
683:            }
684:
685:            /**
686:             * Create a new session Mail Factory
687:             * @param form the form
688:             * @param mailFactoryName the name
689:             * @param type "Session" or "MimePartDataSource"
690:             * @param jndiName the Jndi name
691:             * @param username username
692:             * @param password password
693:             * @param sessionProps Mail session configuration
694:             * @param to MimePartDataSource configuration
695:             * @param subject MimePartDataSource configuration
696:             * @param cc MimePartDataSource configuration
697:             * @param bcc MimePartDataSource configuration
698:             * @throws Exception if an error occurs
699:             */
700:            private void createSessionFactory(WebForm form,
701:                    String mailFactoryName, String jndiName, String username,
702:                    String password, String sessionProps, String to,
703:                    String subject, String cc, String bcc) throws Exception {
704:
705:                form.setParameter("mailFactoryName", mailFactoryName);
706:                form.setParameter("type", "javax.mail.Session");
707:                form.setParameter("jndiName", jndiName);
708:                form.setParameter("username", username);
709:                form.setParameter("password", password);
710:                form.setParameter("sessionProps", sessionProps);
711:                form.setParameter("to", to);
712:                form.setParameter("subject", subject);
713:                form.setParameter("cc", cc);
714:                form.setParameter("bcc", bcc);
715:
716:                SubmitButton button = form.getSubmitButtons()[0];
717:                button.click();
718:            }
719:
720:            /**
721:             * Create a new session Mail Factory
722:             * @param form the form
723:             * @param mailFactoryName the name
724:             * @param type "Session" or "MimePartDataSource"
725:             * @param jndiName the Jndi name
726:             * @param username username
727:             * @param password password
728:             * @param sessionProps Mail session configuration
729:             * @param to MimePartDataSource configuration
730:             * @param subject MimePartDataSource configuration
731:             * @param cc MimePartDataSource configuration
732:             * @param bcc MimePartDataSource configuration
733:             * @throws Exception if an error occurs
734:             */
735:            private void createMimePartDataSourceFactory(WebForm form,
736:                    String mailFactoryName, String jndiName, String username,
737:                    String password, String sessionProps, String to,
738:                    String subject, String cc, String bcc) throws Exception {
739:
740:                form.setParameter("mailFactoryName", mailFactoryName);
741:                form.setParameter("type",
742:                        "javax.mail.internet.MimePartDataSource");
743:                form.setParameter("jndiName", jndiName);
744:                form.setParameter("username", username);
745:                form.setParameter("password", password);
746:                form.setParameter("sessionProps", sessionProps);
747:                form.setParameter("to", to);
748:                form.setParameter("subject", subject);
749:                form.setParameter("cc", cc);
750:                form.setParameter("bcc", bcc);
751:
752:                SubmitButton button = form.getSubmitButtons()[0];
753:                button.click();
754:            }
755:
756:            /**
757:             * Create an empty Mail Factory
758:             * @param form the form
759:             * @throws Exception if an error occurs
760:             */
761:            private void createNewEmptyMailFactory(WebForm form)
762:                    throws Exception {
763:
764:                form.setParameter("mailFactoryName", "");
765:                form.setParameter("jndiName", "");
766:                form.setParameter("username", "");
767:                form.setParameter("password", "");
768:                form.setParameter("sessionProps", "");
769:                form.setParameter("to", "");
770:                form.setParameter("subject", "");
771:                form.setParameter("cc", "");
772:                form.setParameter("bcc", "");
773:
774:                SubmitButton button = form.getSubmitButtons()[0];
775:                button.click();
776:            }
777:
778:            /**
779:             * Return the text of the deployed table or the deployable table
780:             * @param wr the WebResponse to use
781:             * @param deployed if true return the text deployed table, if false text of
782:             *        deployable
783:             * @return the text of the deployed table or the deployable table
784:             * @throws Exception if an error occurs
785:             */
786:            private String getDeployTable(WebResponse wr, boolean deployed)
787:                    throws Exception {
788:
789:                // Extract right table
790:                JonasAdminUtils utils = new JonasAdminUtils();
791:                WebTable table = utils.getTable(wr, 0);
792:
793:                TableCell deployableCell = table.getTableCell(1, 0);
794:                TableCell deployedCell = table.getTableCell(1, 2);
795:
796:                if (deployed) {
797:                    return deployedCell.getText();
798:                } else {
799:                    return deployableCell.getText();
800:                }
801:            }
802:
803:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.