Source Code Cross Referenced for F_JonasAdminResourceDatasource.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_JonasAdminResourceDatasource.java 7381 2005-09-14 16:00:02Z kemlerp $
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 datasource Resource
045:         * @author Paul Kemler
046:         */
047:        public class F_JonasAdminResourceDatasource extends JonasAdminTestCase {
048:
049:            /**
050:             * URL of datasource resource
051:             */
052:            private static final String URL_JONASADMIN_DATASOURCE = "EditDeploy.do?type=datasource";
053:
054:            /**
055:             * URL of datasource resource
056:             */
057:            private static final String URL_JONASADMIN_LIST_DATASOURCES = "ListDatasources.do";
058:
059:            /**
060:             * URL of deploy
061:             */
062:            private static final String URL_JONASADMIN_DEPLOY = "EditDeploy.do";
063:
064:            /**
065:             * URL of create datasource
066:             */
067:            private static final String URL_JONASADMIN_CREATE_DATASOURCE = "EditDatasourceProperties.do?action=create";
068:
069:            /**
070:             * URL of Datasource resource viewTree
071:             */
072:            private static final String URL_JONASADMIN_VIEW_DATASOURCE = "viewTree.do?tree=domain*jonas*resources";
073:
074:            /**
075:             * number of tabs when you are in the datasource tabs
076:             */
077:            private static final int NUMBER_OF_TABS_FOR_DATASOURCE = 2;
078:
079:            /**
080:             * number of tabs when you are in the CONFIRM tabs
081:             */
082:            private static final int NUMBER_OF_TABS_FOR_CONFIRM = 3;
083:
084:            /**
085:             * number of tabs when you are in the 'new datasource' tabs
086:             */
087:            private static final int NUMBER_OF_TABS_FOR_NEW_DATASOURCE = 3;
088:
089:            /**
090:             * name of the datasource
091:             */
092:            private String name = "";
093:
094:            /**
095:             * Constructor with a specified name
096:             * @param s name
097:             */
098:            public F_JonasAdminResourceDatasource(String s) {
099:                super (s, URL_JONASADMIN);
100:            }
101:
102:            /**
103:             * Main method
104:             * @param args the arguments
105:             */
106:            public static void main(String[] args) {
107:
108:                String testtorun = null;
109:                // Get args
110:                for (int argn = 0; argn < args.length; argn++) {
111:                    String sArg = args[argn];
112:                    if (sArg.equals("-n")) {
113:                        testtorun = args[++argn];
114:                    }
115:                }
116:                if (testtorun == null) {
117:                    junit.textui.TestRunner.run(suite());
118:                } else {
119:                    junit.textui.TestRunner
120:                            .run(new F_JonasAdminResourceDatasource(testtorun));
121:                }
122:            }
123:
124:            /**
125:             * Get a new TestSuite for this class
126:             * @return a new TestSuite for this class
127:             */
128:            public static TestSuite suite() {
129:                return new TestSuite(F_JonasAdminResourceDatasource.class);
130:            }
131:
132:            /**
133:             * Setup need for these tests jonasAdmin is required
134:             * @throws Exception if it fails
135:             */
136:            protected void setUp() throws Exception {
137:                super .setUp();
138:
139:                if (wc.getCurrentPage().getURL() == null) {
140:                    useWar("jonasAdmin");
141:                    // login to jonas admin
142:                    try {
143:                        JonasAdminAuth.doValidAuth(wc, url);
144:                    } catch (Exception e) {
145:                        fail("authentification failed :  " + e);
146:                    }
147:                } else {
148:                    // if there was an error, the connection must be restablished
149:                    try {
150:                        wc.getFrameContents(FRAME_TREE);
151:                    } catch (Exception e) {
152:                        wc.getResponse(urlLogOut);
153:                        // login to jonas admin
154:                        try {
155:                            JonasAdminAuth.doValidAuth(wc, url);
156:                        } catch (Exception auth) {
157:                            fail("authentification failed :  " + auth);
158:                        }
159:                    }
160:                }
161:            }
162:
163:            /**
164:             * Test to deploy and undeploy a datasource
165:             * @throws Exception if error occurs
166:             */
167:            public void testUndeployDeployDatasource() throws Exception {
168:
169:                WebResponse wr;
170:                WebLink link;
171:                WebTable table;
172:                WebTable tabTable;
173:                int selectedTab;
174:                /*
175:                 * To get some utils for WebTable
176:                 */
177:                JonasAdminUtils utils = new JonasAdminUtils();
178:
179:                // Disable errors of javascript
180:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
181:                // Disable exception thrown on error status
182:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
183:
184:                if (jProp.isDbm()) {
185:                    // Add datasource
186:                    name = "new_datasource";
187:                    Properties properties = new Properties();
188:                    properties.put("datasource.name", name);
189:                    properties.put("datasource.url",
190:                            "jdbc:hsqldb:hsql://localhost:9001/db_jonas");
191:                    properties.put("datasource.classname",
192:                            "org.hsqldb.jdbcDriver");
193:                    properties.put("datasource.username", "jonas");
194:                    properties.put("datasource.password", "jonas");
195:                    properties.put("datasource.mapper", "rdb.hsql");
196:                    properties.put("jdbc.connchecklevel", "0");
197:                    properties.put("jdbc.connmaxage", "1440");
198:                    properties.put("jdbc.maxopentime", "60");
199:                    properties.put("jdbc.connteststmt", "select 1");
200:                    properties.put("jdbc.minconpool", "10");
201:                    properties.put("jdbc.maxconpool", "30");
202:                    properties.put("jdbc.samplingperiod", "30");
203:                    properties.put("jdbc.maxwaittime", "5");
204:                    properties.put("jdbc.maxwaiters", "100");
205:
206:                    useDatasource(name, properties);
207:
208:                    // Go to database
209:                    wr = wc.getFrameContents(FRAME_TREE);
210:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
211:                            URL_JONASADMIN_DATASOURCE);
212:                    link.click();
213:                    wr = wc.getFrameContents(FRAME_CONTENT);
214:                    selectedTab = 1;
215:
216:                    // Verify tabs
217:                    tabTable = utils.getTabTable(wr);
218:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_DATASOURCE,
219:                            selectedTab, "Problem in 'Deployment' tab.");
220:                    // - links
221:                    assertTrue("The link " + URL_JONASADMIN_LIST_DATASOURCES
222:                            + " is not found in the second tab. ", tabTable
223:                            .getTableCell(0, 2).getLinks()[0].getURLString()
224:                            .endsWith(URL_JONASADMIN_LIST_DATASOURCES));
225:
226:                    String txt = getDeployTable(wr, true);
227:
228:                    if (txt.indexOf(name) == -1) {
229:                        fail("The file" + name + " was not found as deployed.");
230:                    }
231:
232:                    // Undeploy datasource
233:                    WebForm[] webForms = wr.getForms();
234:                    WebForm webForm = webForms[0];
235:
236:                    String params = webForm.getParameterValue("undeploy");
237:                    WebForm.Scriptable script = webForm.getScriptableObject();
238:                    if (params.length() == 0) {
239:                        params += name;
240:                    } else {
241:                        params += "," + name;
242:                    }
243:                    script.setParameterValue("undeploy", params);
244:
245:                    SubmitButton button = webForm.getSubmitButtons()[0];
246:                    button.click();
247:
248:                    // Confirm
249:                    WebResponse submitUndeploy = wc
250:                            .getFrameContents(FRAME_CONTENT);
251:                    selectedTab = 2;
252:
253:                    // Verify tabs
254:                    tabTable = utils.getTabTable(submitUndeploy);
255:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab,
256:                            "Problem in 'Confirm' tab.");
257:                    // - links
258:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
259:                            + " is not found in the first tab. ", tabTable
260:                            .getTableCell(0, 0).getLinks()[0].getURLString()
261:                            .endsWith(URL_JONASADMIN_DEPLOY));
262:                    assertTrue("The link " + URL_JONASADMIN_LIST_DATASOURCES
263:                            + " is not found in the third tab. ", tabTable
264:                            .getTableCell(0, 4).getLinks()[0].getURLString()
265:                            .endsWith(URL_JONASADMIN_LIST_DATASOURCES));
266:
267:                    webForms = submitUndeploy.getForms();
268:                    webForm = webForms[0];
269:
270:                    button = webForm.getSubmitButtons()[0];
271:                    button.click();
272:                    wr = wc.getFrameContents(FRAME_CONTENT);
273:
274:                    // Verify tabs
275:                    tabTable = utils.getTabTable(wr);
276:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab,
277:                            "Problem in 'Result' tab.");
278:                    // - links
279:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
280:                            + " is not found in the first tab. ", tabTable
281:                            .getTableCell(0, 0).getLinks()[0].getURLString()
282:                            .endsWith(URL_JONASADMIN_DEPLOY));
283:                    assertTrue("The link " + URL_JONASADMIN_LIST_DATASOURCES
284:                            + " is not found in the third tab. ", tabTable
285:                            .getTableCell(0, 4).getLinks()[0].getURLString()
286:                            .endsWith(URL_JONASADMIN_LIST_DATASOURCES));
287:
288:                    // Go back to Deployment
289:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
290:                            URL_JONASADMIN_DEPLOY);
291:                    link.click();
292:                    wr = wc.getFrameContents(FRAME_CONTENT);
293:                    selectedTab = 1;
294:
295:                    // Verify tabs
296:                    tabTable = utils.getTabTable(wr);
297:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_DATASOURCE,
298:                            selectedTab, "Problem in 'Deployment' tab.");
299:                    // - links
300:                    assertTrue("The link " + URL_JONASADMIN_LIST_DATASOURCES
301:                            + " is not found in the second tab. ", tabTable
302:                            .getTableCell(0, 2).getLinks()[0].getURLString()
303:                            .endsWith(URL_JONASADMIN_LIST_DATASOURCES));
304:
305:                    txt = getDeployTable(wr, true);
306:
307:                    if (txt.indexOf(name) != -1) {
308:                        fail("The jonasAdmin webApp has not removed. " + name);
309:                    }
310:
311:                    // now deploy
312:                    webForms = wr.getForms();
313:                    webForm = webForms[0];
314:
315:                    params = webForm.getParameterValue("deploy");
316:                    script = webForm.getScriptableObject();
317:
318:                    if (params.length() == 0) {
319:                        params += name;
320:                    } else {
321:                        params += "," + name;
322:                    }
323:
324:                    script.setParameterValue("deploy", params);
325:                    button = webForm.getSubmitButtons()[0];
326:                    button.click();
327:
328:                    // Confirm
329:                    submitUndeploy = wc.getFrameContents(FRAME_CONTENT);
330:                    // war is in the table
331:                    webForms = submitUndeploy.getForms();
332:                    webForm = webForms[0];
333:
334:                    button = webForm.getSubmitButtons()[0];
335:                    button.click();
336:
337:                    // Go back to Deployment
338:                    wr = wc.getFrameContents(FRAME_CONTENT);
339:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
340:                            URL_JONASADMIN_DEPLOY);
341:                    link.click();
342:                    wr = wc.getFrameContents(FRAME_CONTENT);
343:
344:                    txt = getDeployTable(wr, true);
345:
346:                    if (txt.indexOf(name) == -1) {
347:                        fail("The file " + name + " was not found as deployed.");
348:                    }
349:                }
350:            }
351:
352:            /**
353:             * Test to create a new datasource
354:             * @throws Exception if error occurs
355:             */
356:            public void testCreateNewDatasource() throws Exception {
357:
358:                WebResponse wr;
359:                WebLink link;
360:                WebTable table;
361:                WebTable tabTable;
362:                int selectedTab;
363:                // Name of the datasource
364:                name = "new_datasource_";
365:                // JNDI name The JNDI name to use the datasource
366:                String jndiName = "";
367:                // Description Description of the datasource
368:                String descr = "";
369:                // URL URL to access to the database
370:                String urlDatasource = "jdbc:hsqldb:hsql://localhost:9001/db_jonas";
371:                // JDBC Driver JDBC driver class name to access to the database
372:                String driver = "org.hsqldb.jdbcDriver";
373:                // User name User name or login to log in the database
374:                String user = "jonas";
375:                // User password User password to log in the database
376:                String password = "jonas";
377:                // Mapper Mapper used for the datasource
378:                String mapper = "rdb.hsql";
379:
380:                /*
381:                 * To get some utils for WebTable
382:                 */
383:                JonasAdminUtils utils = new JonasAdminUtils();
384:
385:                // Disable errors of javascript
386:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
387:                // Disable exception thrown on error status
388:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
389:
390:                if (jProp.isDbm()) {
391:                    // Go to database
392:                    wr = wc.getFrameContents(FRAME_TREE);
393:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
394:                            URL_JONASADMIN_DATASOURCE);
395:                    link.click();
396:                    wr = wc.getFrameContents(FRAME_CONTENT);
397:                    selectedTab = 1;
398:
399:                    // Go to datasources
400:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
401:                            URL_JONASADMIN_LIST_DATASOURCES);
402:                    link.click();
403:                    wr = wc.getFrameContents(FRAME_CONTENT);
404:                    selectedTab = 2;
405:
406:                    // Verify tabs
407:                    tabTable = utils.getTabTable(wr);
408:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_DATASOURCE,
409:                            selectedTab, "Problem in 'Datasources' tab.");
410:                    // - links
411:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
412:                            + " is not found in the first tab. ", tabTable
413:                            .getTableCell(0, 0).getLinks()[0].getURLString()
414:                            .endsWith(URL_JONASADMIN_DEPLOY));
415:
416:                    // Find a new name
417:                    boolean found = false;
418:                    int i = 0;
419:                    while (!found) {
420:                        if ((wr.getText().indexOf(name + i) == -1)) {
421:                            name = name + i;
422:                            jndiName = name;
423:                            found = true;
424:                        }
425:                        i++;
426:                    }
427:
428:                    // Create a new datasource
429:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
430:                            URL_JONASADMIN_CREATE_DATASOURCE);
431:                    link.click();
432:                    wr = wc.getFrameContents(FRAME_CONTENT);
433:                    selectedTab = 3;
434:
435:                    // Verify tabs
436:                    tabTable = utils.getTabTable(wr);
437:                    testTabs(tabTable, NUMBER_OF_TABS_FOR_NEW_DATASOURCE,
438:                            selectedTab, "Problem in 'New Datasource' tab.");
439:                    // - links
440:                    assertTrue("The link " + URL_JONASADMIN_DEPLOY
441:                            + " is not found in the first tab. ", tabTable
442:                            .getTableCell(0, 0).getLinks()[0].getURLString()
443:                            .endsWith(URL_JONASADMIN_DEPLOY));
444:                    assertTrue("The link " + URL_JONASADMIN_LIST_DATASOURCES
445:                            + " is not found in the third tab. ", tabTable
446:                            .getTableCell(0, 2).getLinks()[0].getURLString()
447:                            .endsWith(URL_JONASADMIN_LIST_DATASOURCES));
448:
449:                    WebForm form = wr.getForms()[0];
450:                    createNewDatasource(form, name, jndiName, descr,
451:                            urlDatasource, driver, user, password, mapper);
452:                    wr = wc.getFrameContents(FRAME_CONTENT);
453:
454:                    // Verify if the datasource is deployed
455:                    assertTrue("The created datasource ('" + name
456:                            + "') is not deployed. ", isLoadedDatasource(name));
457:                    table = utils.getTable(wr, 3);
458:                    int datasourceRow = utils.getRow(name, table, 1).intValue();
459:                    if (datasourceRow == -1) {
460:                        fail("The datasource '"
461:                                + name
462:                                + "' is not found in datasource table. Restart jonas and try again. ");
463:                    } else {
464:                        // Verify if there is an image to indicate that the datasource is deployed
465:                        TableCell cell = table.getTableCell(datasourceRow, 0);
466:                        assertEquals("There is no a image to indicate that '"
467:                                + name + "' datasource is deployed. ", 1, cell
468:                                .getImages().length);
469:                    }
470:                }
471:
472:            }
473:
474:            /**
475:             * Test to view empty value error message
476:             * @throws Exception if error occurs
477:             */
478:            public void testCreateDatasourceWithEmptyValue() throws Exception {
479:
480:                WebResponse wr;
481:                WebLink link;
482:                WebTable table;
483:                WebTable tabTable;
484:                int selectedTab;
485:                // Name Name of the datasource
486:                name = "";
487:                // JNDI name The JNDI name to use the datasource
488:                String jndiName = "";
489:                // Description Description of the datasource
490:                String descr = "";
491:                // URL URL to access to the database
492:                String urlDatasource = "";
493:                // JDBC Driver JDBC driver class name to access to the database
494:                String driver = "";
495:                // User name User name or login to log in the database
496:                String user = "";
497:                // User password User password to log in the database
498:                String password = "";
499:                // Mapper Mapper used for the datasource
500:                String mapper = "";
501:
502:                /*
503:                 * To get some utils for WebTable
504:                 */
505:                JonasAdminUtils utils = new JonasAdminUtils();
506:
507:                // Disable errors of javascript
508:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
509:                // Disable exception thrown on error status
510:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
511:
512:                if (jProp.isDbm()) {
513:                    // Go to database
514:                    wr = wc.getFrameContents(FRAME_TREE);
515:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
516:                            URL_JONASADMIN_DATASOURCE);
517:                    link.click();
518:                    wr = wc.getFrameContents(FRAME_CONTENT);
519:                    selectedTab = 1;
520:
521:                    // Go to datasources
522:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
523:                            URL_JONASADMIN_LIST_DATASOURCES);
524:                    link.click();
525:                    wr = wc.getFrameContents(FRAME_CONTENT);
526:                    selectedTab = 2;
527:
528:                    // Create a new datasource
529:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
530:                            URL_JONASADMIN_CREATE_DATASOURCE);
531:                    link.click();
532:                    wr = wc.getFrameContents(FRAME_CONTENT);
533:                    selectedTab = 3;
534:
535:                    WebForm form = wr.getForms()[0];
536:                    createNewDatasource(form, name, jndiName, descr,
537:                            urlDatasource, driver, user, password, mapper);
538:                    wr = wc.getFrameContents(FRAME_CONTENT);
539:
540:                    // Verify error messages
541:                    table = utils.getTable(wr, 0);
542:                    TableCell cell = table.getTableCell(0, 0);
543:
544:                    // class        errors
545:                    assertEquals(
546:                            "The value  of the class attribut of the cell is not 'errors'. ",
547:                            "errors", cell.getAttribute("class"));
548:                    // Name cannot be empty
549:                    String emptyName = "Name cannot be empty";
550:                    assertTrue(
551:                            "The message '" + emptyName + "' is not found. ",
552:                            cell.getText().indexOf(emptyName) != -1);
553:                    // JNDI name cannot be empty
554:                    String emptyJndiName = "JNDI name cannot be empty";
555:                    assertTrue("The message '" + emptyJndiName
556:                            + "' is not found. ", cell.getText().indexOf(
557:                            emptyJndiName) != -1);
558:                    // JDBC Driver cannot be empty
559:                    String emptyJdbcDriver = "JDBC Driver cannot be empty";
560:                    assertTrue("The message '" + emptyJdbcDriver
561:                            + "' is not found. ", cell.getText().indexOf(
562:                            emptyJdbcDriver) != -1);
563:                }
564:
565:            }
566:
567:            /**
568:             * Tear Down
569:             * cleanUp action
570:             */
571:            public void tearDown() throws Exception {
572:
573:                if (jProp.isDbm()) {
574:                    // remove created datasource file
575:                    if (!name.equals("")) {
576:                        // Undeploy datasource
577:                        unUseDatasource(name);
578:                        // Delete file
579:                        JonasAdminFiles.deleteConfigFile(name + ".properties");
580:                        name = "";
581:                    }
582:                }
583:
584:                super .tearDown();
585:            }
586:
587:            /**
588:             * Return the text of the deployed table or the deployable table
589:             * @param wr the WebResponse to use
590:             * @param deployed if true return the text deployed table, if false text of
591:             *        deployable
592:             * @return the text of the deployed table or the deployable table
593:             * @throws Exception if an error occurs
594:             */
595:            private String getDeployTable(WebResponse wr, boolean deployed)
596:                    throws Exception {
597:
598:                // Extract right table
599:                JonasAdminUtils utils = new JonasAdminUtils();
600:                WebTable table = utils.getTable(wr, 0);
601:
602:                TableCell deployableCell = table.getTableCell(1, 0);
603:                TableCell deployedCell = table.getTableCell(1, 2);
604:
605:                if (deployed) {
606:                    return deployedCell.getText();
607:                } else {
608:                    return deployableCell.getText();
609:                }
610:            }
611:
612:            /**
613:             * Create a new datasource in jonasAdmin
614:             * @param form datasource form
615:             * @param name the name of the datasource
616:             * @param datasourceName JNDI name
617:             * @param datasourceDescription the description of the datasource
618:             * @param datasourceUrl url to access to the databse
619:             * @param datasourceClassname JDBC driver class name to access to the
620:             *        database
621:             * @param datasourceUsername User name or login to log in the database
622:             * @param datasourcePassword User password to log in the database
623:             * @param datasourceMapper Mapper used for the datasource
624:             * @throws Exception if an error occurs when button is clicked.
625:             */
626:            private void createNewDatasource(WebForm form, String name,
627:                    String datasourceName, String datasourceDescription,
628:                    String datasourceUrl, String datasourceClassname,
629:                    String datasourceUsername, String datasourcePassword,
630:                    String datasourceMapper) throws Exception {
631:                SubmitButton button = form.getSubmitButtons()[0];
632:
633:                form.setParameter("name", name);
634:                form.setParameter("datasourceName", datasourceName);
635:                form.setParameter("datasourceDescription",
636:                        datasourceDescription);
637:                form.setParameter("datasourceUrl", datasourceUrl);
638:                form.setParameter("datasourceClassname", datasourceClassname);
639:                form.setParameter("datasourceUsername", datasourceUsername);
640:                form.setParameter("datasourcePassword", datasourcePassword);
641:                form.setParameter("datasourceMapper", datasourceMapper);
642:
643:                button.click();
644:            }
645:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.