Source Code Cross Referenced for Connector15DCBTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » connector » deployment » jsr88 » 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 » EJB Server geronimo » plugins » org.apache.geronimo.connector.deployment.jsr88 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.connector.deployment.jsr88;
017:
018:        import java.io.ByteArrayInputStream;
019:        import java.io.ByteArrayOutputStream;
020:        import java.io.InputStream;
021:        import java.net.URL;
022:        import java.util.Collections;
023:        import java.util.HashSet;
024:        import java.util.Set;
025:        import javax.enterprise.deploy.model.DDBean;
026:        import javax.enterprise.deploy.model.DDBeanRoot;
027:        import javax.enterprise.deploy.shared.ModuleType;
028:        import javax.enterprise.deploy.spi.DConfigBean;
029:        import junit.framework.TestCase;
030:        import org.apache.geronimo.connector.deployment.RARConfiguration;
031:        import org.apache.geronimo.deployment.tools.loader.ConnectorDeployable;
032:        import org.apache.geronimo.deployment.service.jsr88.EnvironmentData;
033:        import org.apache.geronimo.deployment.service.jsr88.Artifact;
034:        import org.apache.geronimo.naming.deployment.jsr88.GBeanLocator;
035:        import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
036:        import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
037:
038:        /**
039:         * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
040:         */
041:        public class Connector15DCBTest extends TestCase {
042:            private ClassLoader classLoader;
043:
044:            public void testCreateDatabase() throws Exception {
045:                // Create and test the DDBeanRoot
046:                URL resource = classLoader.getResource("database.rar");
047:                assertNotNull(resource);
048:                ConnectorDeployable deployable = new ConnectorDeployable(
049:                        resource);
050:                assertEquals(ModuleType.RAR, deployable.getType());
051:                Set entrySet = new HashSet(Collections.list(deployable
052:                        .entries()));
053:                Set resultSet = new HashSet();
054:                resultSet.add("META-INF/");
055:                resultSet.add("META-INF/MANIFEST.MF");
056:                resultSet.add("META-INF/LICENSE.txt");
057:                resultSet.add("META-INF/ra.xml");
058:                resultSet.add("tranql-connector-1.0.jar");
059:                assertEquals(resultSet, entrySet);
060:                DDBeanRoot root = deployable.getDDBeanRoot();
061:                assertNotNull(root);
062:                assertEquals(ModuleType.RAR, root.getType());
063:                assertEquals(deployable, root.getDeployableObject());
064:                // Create the DConfigBeanRoot
065:                Connector15DCBRoot dcbRoot = new Connector15DCBRoot(root);
066:                assertNotNull(dcbRoot.getXpaths());
067:                assertEquals(1, dcbRoot.getXpaths().length);
068:                assertEquals("connector", dcbRoot.getXpaths()[0]);
069:                // Try the /connector element
070:                ConnectorDCB connector = (ConnectorDCB) dcbRoot
071:                        .getDConfigBean(root
072:                                .getChildBean(dcbRoot.getXpaths()[0])[0]);
073:                assertNotNull(connector);
074:                assertNull(connector.getEnvironment());
075:                EnvironmentData environment = new EnvironmentData();
076:                connector.setEnvironment(environment);
077:                Artifact configId = new Artifact();
078:                environment.setConfigId(configId);
079:                assertNull(configId.getArtifactId());
080:                assertNull(configId.getGroupId());
081:                assertNull(configId.getType());
082:                assertNull(configId.getVersion());
083:                configId.setGroupId("test");
084:                configId.setArtifactId("product");
085:                configId.setType("rar");
086:                configId.setVersion("1.0");
087:                Artifact parent = new Artifact();
088:                Artifact dependency = new Artifact();
089:                environment
090:                        .setDependencies(new Artifact[] { parent, dependency });
091:                assertNull(parent.getArtifactId());
092:                assertNull(parent.getGroupId());
093:                assertNull(parent.getType());
094:                assertNull(parent.getVersion());
095:                assertNull(dependency.getArtifactId());
096:                assertNull(dependency.getGroupId());
097:                assertNull(dependency.getType());
098:                assertNull(dependency.getVersion());
099:                parent.setGroupId("org.apache.geronimo.configs");
100:                parent.setArtifactId("j2ee-server");
101:                parent.setType("car");
102:                assertNull(parent.getVersion());
103:                dependency.setGroupId("postgresql");
104:                dependency.setArtifactId("postgresql-8.0");
105:                dependency.setType("jar");
106:                dependency.setVersion("313.jdbc3");
107:                // todo: Try the /connector/environment/hidden-classes element
108:                // todo: Try the /connector/environment/non-overridable-classes element
109:                // Try the /connector/resourceadapter element
110:                assertNotNull(connector.getResourceAdapter());
111:                assertEquals(1, connector.getResourceAdapter().length);
112:                ResourceAdapter adapter = connector.getResourceAdapter()[0];
113:                assertNotNull(adapter);
114:                // Try the /connector/resourceadapter/outbound-resourceadapter/connection-definition element
115:                assertNotNull(adapter.getConnectionDefinition());
116:                assertEquals(0, adapter.getConnectionDefinition().length);
117:                ConnectionDefinition definition = new ConnectionDefinition();
118:                adapter
119:                        .setConnectionDefinition(new ConnectionDefinition[] { definition });
120:                assertEquals(1, adapter.getConnectionDefinition().length);
121:                definition
122:                        .setConnectionFactoryInterface("javax.sql.DataSource");
123:                // Try the .../connection-definition/connectiondefinition-instance elements
124:                assertNotNull(definition.getConnectionInstances());
125:                assertEquals(0, definition.getConnectionInstances().length);
126:                ConnectionDefinitionInstance instance = new ConnectionDefinitionInstance();
127:                definition
128:                        .setConnectionInstance(new ConnectionDefinitionInstance[] { instance });
129:                assertEquals(1, definition.getConnectionInstances().length);
130:                assertNotNull(instance.getDDBean());
131:                // Try the .../connection-definition/connectiondefinition-instance/config-property-setting elements
132:                assertNotNull(instance.getConfigPropertySetting());
133:                assertEquals(6, instance.getConfigPropertySetting().length);
134:                int found = 0;
135:                for (int i = 0; i < 6; i++) {
136:                    ConfigPropertySetting setting = instance
137:                            .getConfigPropertySetting(i);
138:                    if (setting.getName().equals("Driver")) {
139:                        assertNull(setting.getValue());
140:                        setting.setValue("org.postgresql.Driver");
141:                        ++found;
142:                    } else if (setting.getName().equals("ConnectionURL")) {
143:                        assertNull(setting.getValue());
144:                        setting
145:                                .setValue("jdbc:postgresql://localhost/TestDatabase");
146:                        ++found;
147:                    } else if (setting.getName().equals("UserName")) {
148:                        assertNull(setting.getValue());
149:                        setting.setValue("dbuser");
150:                        ++found;
151:                    } else if (setting.getName().equals("Password")) {
152:                        assertNull(setting.getValue());
153:                        setting.setValue("dbpass");
154:                        ++found;
155:                    } else {
156:                        assertNotNull(setting.getValue());
157:                    }
158:                }
159:                assertEquals(4, found);
160:                // Try the .../connection-definition/connectionmanager elements
161:                ConnectionManager manager = instance.getConnectionManager();
162:                assertNotNull(manager);
163:                assertFalse(manager.isContainerManagedSecurity());
164:                assertFalse(manager.isPoolNone());
165:                assertNotNull(manager.getPoolSingle());
166:                assertNull(manager.getPoolPartitioned());
167:                assertFalse(manager.isTransactionLog());
168:                assertFalse(manager.isTransactionNone());
169:                assertFalse(manager.isTransactionXA());
170:                assertFalse(manager.isTransactionXACachingThread());
171:                assertFalse(manager.isTransactionXACachingTransaction());
172:                assertTrue(manager.isTransactionLocal());
173:                SinglePool pool = manager.getPoolSingle();
174:                assertNull(pool.getMinSize());
175:                assertNull(pool.getMaxSize());
176:                assertNull(pool.getIdleTimeoutMinutes());
177:                assertNull(pool.getBlockingTimeoutMillis());
178:                assertTrue(pool.isMatchOne());
179:                assertFalse(pool.isMatchAll());
180:                assertFalse(pool.isSelectOneAssumeMatch());
181:                pool.setMinSize(new Integer(2));
182:                pool.setMaxSize(new Integer(30));
183:                pool.setBlockingTimeoutMillis(new Integer(5000));
184:                //todo: Look at the XmlBeans tree and make sure the right stuff is in there
185:                System.out.println(dcbRoot.getConnectorDocument());
186:            }
187:
188:            public void testWriteWithNulls() throws Exception {
189:                InputStream in = classLoader.getResource("plan-with-nulls.xml")
190:                        .openStream();
191:
192:                // Create and test the DDBeanRoot
193:                URL resource = classLoader.getResource("database.rar");
194:                assertNotNull(resource);
195:                ConnectorDeployable deployable = new ConnectorDeployable(
196:                        resource);
197:                assertEquals(ModuleType.RAR, deployable.getType());
198:                DDBeanRoot root = deployable.getDDBeanRoot();
199:                assertNotNull(root);
200:                assertEquals(ModuleType.RAR, root.getType());
201:                assertEquals(deployable, root.getDeployableObject());
202:                // Create the DConfigBeanRoot
203:                Connector15DCBRoot dcbRoot = new Connector15DCBRoot(root);
204:                RARConfiguration configuration = new RARConfiguration(
205:                        deployable, dcbRoot);
206:                configuration.restore(in);
207:                // Try the /connector element
208:                ConnectorDCB connector = (ConnectorDCB) dcbRoot
209:                        .getDConfigBean(root
210:                                .getChildBean(dcbRoot.getXpaths()[0])[0]);
211:                assertNotNull(connector);
212:                // Try the /connector/resourceadapter element
213:                assertNotNull(connector.getResourceAdapter());
214:                assertEquals(1, connector.getResourceAdapter().length);
215:                ResourceAdapter adapter = connector.getResourceAdapter()[0];
216:                assertNotNull(adapter);
217:                // Try the /connector/resourceadapter/outbound-resourceadapter/connection-definition element
218:                assertNotNull(adapter.getConnectionDefinition());
219:                assertEquals(1, adapter.getConnectionDefinition().length);
220:                ConnectionDefinition definition = adapter
221:                        .getConnectionDefinition(0);
222:                // Try the .../connection-definition/connectiondefinition-instance elements
223:                assertNotNull(definition.getConnectionInstances());
224:                assertEquals(1, definition.getConnectionInstances().length);
225:                ConnectionDefinitionInstance instance = definition
226:                        .getConnectionInstances()[0];
227:                // Try the .../connection-definition/connectiondefinition-instance/config-property-setting elements
228:                assertNotNull(instance.getConfigPropertySetting());
229:                assertEquals(6, instance.getConfigPropertySetting().length);
230:                int nullCount = 0;
231:                for (int i = 0; i < 6; i++) {
232:                    if (instance.getConfigPropertySetting(i).getValue() == null) {
233:                        ++nullCount;
234:                    } else if (instance.getConfigPropertySetting(i).getValue()
235:                            .equals("")) {
236:                        instance.getConfigPropertySetting()[i].setValue(null);
237:                        ++nullCount;
238:                    }
239:                }
240:                // Read the generated XML and count config property setting elements (should be 4)
241:                assertEquals(2, nullCount);
242:                ByteArrayOutputStream pout = new ByteArrayOutputStream();
243:                dcbRoot.toXML(pout);
244:                pout.close();
245:                ByteArrayInputStream pin = new ByteArrayInputStream(pout
246:                        .toByteArray());
247:                GerConnectorDocument doc = GerConnectorDocument.Factory
248:                        .parse(pin);
249:                pin.close();
250:                GerConfigPropertySettingType[] settings = doc.getConnector()
251:                        .getResourceadapterArray(0)
252:                        .getOutboundResourceadapter()
253:                        .getConnectionDefinitionArray(0)
254:                        .getConnectiondefinitionInstanceArray(0)
255:                        .getConfigPropertySettingArray();
256:                assertEquals(2, settings.length);
257:                Set seen = new HashSet();
258:                for (int i = 0; i < settings.length; i++) {
259:                    GerConfigPropertySettingType setting = settings[i];
260:                    if (seen.contains(setting.getName())) {
261:                        fail("Duplicate for config property setting '"
262:                                + setting.getName() + "'");
263:                    }
264:                    seen.add(setting.getName());
265:                    // These two are set to their defaults and now no longer appear
266:                    //            if(setting.getName().equals("CommitBeforeAutocommit")) {
267:                    //                assertEquals("false", setting.getStringValue());
268:                    //            } else if(setting.getName().equals("ExceptionSorterClass")) {
269:                    //                assertEquals("org.tranql.connector.AllExceptionsAreFatalSorter", setting.getStringValue());
270:                    if (setting.getName().equals("Driver")) {
271:                        assertEquals("org.apache.derby.jdbc.EmbeddedDriver",
272:                                setting.getStringValue());
273:                    } else if (setting.getName().equals("ConnectionURL")) {
274:                        assertEquals("jdbc:derby:TestDatabase;create=true",
275:                                setting.getStringValue());
276:                    } else
277:                        fail("Unknown connection setting '" + setting.getName()
278:                                + "'");
279:                }
280:                // Make sure the original objects didn't lose track of the null config settings
281:                assertEquals(6, instance.getConfigPropertySetting().length);
282:                // Now set them to blank
283:                nullCount = 0;
284:                for (int i = 0; i < 6; i++) {
285:                    if (instance.getConfigPropertySetting()[i].getValue() == null
286:                            || instance.getConfigPropertySetting()[i]
287:                                    .isSetToDefault()) {
288:                        instance.getConfigPropertySetting()[i].setValue("");
289:                        ++nullCount;
290:                    }
291:                }
292:                assertEquals(4, nullCount);
293:                // Now make sure we write out with 6
294:                pout = new ByteArrayOutputStream();
295:                dcbRoot.toXML(pout);
296:                pout.close();
297:                pin = new ByteArrayInputStream(pout.toByteArray());
298:                doc = GerConnectorDocument.Factory.parse(pin);
299:                pin.close();
300:                settings = doc.getConnector().getResourceadapterArray(0)
301:                        .getOutboundResourceadapter()
302:                        .getConnectionDefinitionArray(0)
303:                        .getConnectiondefinitionInstanceArray(0)
304:                        .getConfigPropertySettingArray();
305:                assertEquals(6, settings.length);
306:                seen.clear();
307:                for (int i = 0; i < settings.length; i++) {
308:                    GerConfigPropertySettingType setting = settings[i];
309:                    if (seen.contains(setting.getName())) {
310:                        fail("Duplicate for config property setting '"
311:                                + setting.getName() + "'");
312:                    }
313:                    seen.add(setting.getName());
314:                    if (setting.getName().equals("UserName")) {
315:                        assertEquals("", setting.getStringValue());
316:                    } else if (setting.getName().equals("Password")) {
317:                        assertEquals("", setting.getStringValue());
318:                    } else if (setting.getName().equals(
319:                            "CommitBeforeAutocommit")) {
320:                        assertEquals("", setting.getStringValue());
321:                    } else if (setting.getName().equals("Driver")) {
322:                        assertEquals("org.apache.derby.jdbc.EmbeddedDriver",
323:                                setting.getStringValue());
324:                    } else if (setting.getName().equals("ExceptionSorterClass")) {
325:                        assertEquals("", setting.getStringValue());
326:                    } else if (setting.getName().equals("ConnectionURL")) {
327:                        assertEquals("jdbc:derby:TestDatabase;create=true",
328:                                setting.getStringValue());
329:                    } else
330:                        fail("Unknown connection setting '" + setting.getName()
331:                                + "'");
332:                }
333:            }
334:
335:            public void testCreateJMSResource() throws Exception {
336:                // Create and test the DDBeanRoot
337:                URL resource = classLoader.getResource("jms.rar");
338:                assertNotNull(resource);
339:                ConnectorDeployable deployable = new ConnectorDeployable(
340:                        resource);
341:                assertEquals(ModuleType.RAR, deployable.getType());
342:                Set entrySet = new HashSet(Collections.list(deployable
343:                        .entries()));
344:                assertTrue(entrySet.contains("META-INF/ra.xml"));
345:                assertTrue(entrySet.contains("activemq-ra-3.2.1.jar"));
346:                DDBeanRoot root = deployable.getDDBeanRoot();
347:                assertNotNull(root);
348:                assertEquals(ModuleType.RAR, root.getType());
349:                assertEquals(deployable, root.getDeployableObject());
350:                // Create the DConfigBeanRoot
351:                Connector15DCBRoot dcbRoot = new Connector15DCBRoot(root);
352:                assertNotNull(dcbRoot.getXpaths());
353:                assertEquals(1, dcbRoot.getXpaths().length);
354:                assertEquals("connector", dcbRoot.getXpaths()[0]);
355:                // Try the /connector element
356:                ConnectorDCB connector = (ConnectorDCB) dcbRoot
357:                        .getDConfigBean(root
358:                                .getChildBean(dcbRoot.getXpaths()[0])[0]);
359:                assertNotNull(connector);
360:                //        assertNull(connector.getConfigID());
361:                //        assertNull(connector.getInverseClassLoading());
362:                //        assertNull(connector.getParentID());
363:                //        assertNull(connector.getSuppressDefaultParentID());
364:                //        connector.setConfigID("MyJMS");
365:                //        connector.setParentID("geronimo/activemq/1.0/car");
366:                // Try the /connector/dependency element
367:                //        assertNotNull(connector.getArtifactType());
368:                //        assertEquals(0, connector.getArtifactType().length);
369:                //        Artifact dep = new Artifact();
370:                //        connector.setDependency(new Artifact[]{dep});
371:                //        assertEquals(1, connector.getArtifactType().length);
372:                //        dep.setURI("postgresql/postgresql-8.0/313.jdbc3/jar");
373:                //        assertNull(dep.getArtifactId());
374:                //        assertNull(dep.getGroupId());
375:                //        assertNull(dep.getType());
376:                //        assertNull(dep.getVersion());
377:                //        dep.setGroupId("postgresql");
378:                //        dep.setArtifactId("postgresql-8.0");
379:                //        dep.setVersion("313.jdbc3");
380:                //        assertNull(dep.getURI());
381:                //        assertNull(dep.getType());
382:                // todo: Try the /connector/import element
383:                // todo: Try the /connector/hidden-classes element
384:                // todo: Try the /connector/non-overridable-classes element
385:                // Try the /connector/resourceadapter element
386:                assertNotNull(connector.getResourceAdapter());
387:                assertEquals(1, connector.getResourceAdapter().length);
388:                ResourceAdapter adapter = connector.getResourceAdapter()[0];
389:                assertNotNull(adapter);
390:                // Try the /connector/resourceadapter/resourceadapter-instance element
391:                assertNull(adapter.getResourceAdapterInstance());
392:                adapter
393:                        .setResourceAdapterInstance(new ResourceAdapterInstance());
394:                ResourceAdapterInstance raInstance = adapter
395:                        .getResourceAdapterInstance();
396:                assertNull(raInstance.getResourceAdapterName());
397:                assertNotNull(raInstance.getConfigProperties());
398:                assertEquals(7, raInstance.getConfigPropertySetting().length);
399:                for (int i = 0; i < raInstance.getConfigPropertySetting().length; i++) {
400:                    ConfigPropertySetting config = raInstance
401:                            .getConfigPropertySetting()[i];
402:                    assertTrue(config.isSetToDefault());
403:                }
404:                int found = 0;
405:                for (int i = 0; i < 7; i++) {
406:                    ConfigPropertySetting setting = raInstance
407:                            .getConfigPropertySetting(i);
408:                    if (setting.getName().equals("ServerUrl")) {
409:                        setting.setValue("tcp://localhost:12345");
410:                        ++found;
411:                    } else if (setting.getName().equals("UserName")) {
412:                        setting.setValue("test-user");
413:                        ++found;
414:                    } else if (setting.getName().equals("Password")) {
415:                        setting.setValue("test-password");
416:                        ++found;
417:                    }
418:                }
419:                assertEquals(found, 3);
420:                // Try the /connector/resourceadapter/resourceadapter-instance/workmanager
421:                assertNull(raInstance.getWorkManager());
422:                GBeanLocator workManager = new GBeanLocator();
423:                raInstance.setWorkManager(workManager);
424:                workManager.setGBeanLink("DefaultWorkManager");
425:                // Try the /connector/resourceadapter/outbound-resourceadapter/connection-definition element
426:                assertNotNull(adapter.getConnectionDefinition());
427:                assertEquals(0, adapter.getConnectionDefinition().length);
428:                ConnectionDefinition definition = new ConnectionDefinition();
429:                adapter
430:                        .setConnectionDefinition(new ConnectionDefinition[] { definition });
431:                assertEquals(1, adapter.getConnectionDefinition().length);
432:                definition
433:                        .setConnectionFactoryInterface("javax.jms.ConnectionFactory");
434:                // Try the .../connection-definition/connectiondefinition-instance elements
435:                assertNotNull(definition.getConnectionInstances());
436:                assertEquals(0, definition.getConnectionInstances().length);
437:                ConnectionDefinitionInstance instance = new ConnectionDefinitionInstance();
438:                definition
439:                        .setConnectionInstance(new ConnectionDefinitionInstance[] { instance });
440:                assertEquals(1, definition.getConnectionInstances().length);
441:                assertNotNull(instance.getDDBean());
442:                instance.setName("Test JMS Resource");
443:                instance.setImplementedInterface(new String[] {
444:                        "javax.jms.QueueConnectorFactory",
445:                        "javax.jms.TopicConnectionFactory" });
446:                // Try the .../connection-definition/connectiondefinition-instance/config-property-setting elements
447:                assertNotNull(instance.getConfigPropertySetting());
448:                assertEquals(0, instance.getConfigPropertySetting().length);
449:                // Try the .../connection-definition/connectionmanager elements
450:                ConnectionManager manager = instance.getConnectionManager();
451:                assertNotNull(manager);
452:                assertFalse(manager.isContainerManagedSecurity());
453:                assertFalse(manager.isPoolNone());
454:                assertNotNull(manager.getPoolSingle());
455:                assertNull(manager.getPoolPartitioned());
456:                assertFalse(manager.isTransactionLog());
457:                assertFalse(manager.isTransactionNone());
458:                assertTrue(manager.isTransactionXA());
459:                assertFalse(manager.isTransactionXACachingThread());
460:                assertTrue(manager.isTransactionXACachingTransaction());
461:                assertFalse(manager.isTransactionLocal());
462:                SinglePool pool = manager.getPoolSingle();
463:                assertNull(pool.getMinSize());
464:                assertNull(pool.getMaxSize());
465:                assertNull(pool.getIdleTimeoutMinutes());
466:                assertNull(pool.getBlockingTimeoutMillis());
467:                assertTrue(pool.isMatchOne());
468:                assertFalse(pool.isMatchAll());
469:                assertFalse(pool.isSelectOneAssumeMatch());
470:                pool.setMinSize(new Integer(2));
471:                pool.setMaxSize(new Integer(30));
472:                pool.setBlockingTimeoutMillis(new Integer(5000));
473:                DDBean[] ddBeans = connector.getDDBean().getChildBean(
474:                        connector.getXpaths()[0]);
475:                assertNotNull(ddBeans);
476:                assertEquals(2, ddBeans.length);
477:                DConfigBean[] adminDCBs = new DConfigBean[ddBeans.length];
478:                for (int i = 0; i < adminDCBs.length; i++) {
479:                    adminDCBs[i] = connector.getDConfigBean(ddBeans[i]);
480:                    AdminObjectDCB dcb = (AdminObjectDCB) adminDCBs[i];
481:                    if (dcb.getAdminObjectClass().indexOf("Queue") > -1) {
482:                        assertEquals(0, dcb.getAdminObjectInstance().length);
483:                        AdminObjectInstance one = new AdminObjectInstance();
484:                        AdminObjectInstance two = new AdminObjectInstance();
485:                        dcb.setAdminObjectInstance(new AdminObjectInstance[] {
486:                                one, two });
487:                        one.setMessageDestinationName("TestQueue1");
488:                        one.getConfigPropertySetting()[0]
489:                                .setValue("PhysicalName1");
490:                        two.setMessageDestinationName("TestQueue2");
491:                        two.getConfigPropertySetting()[0]
492:                                .setValue("PhysicalName2");
493:                    } else if (dcb.getAdminObjectClass().indexOf("Topic") > -1) {
494:                        assertEquals(0, dcb.getAdminObjectInstance().length);
495:                    } else
496:                        fail("Unknown AdminobjectDCB admin object class '"
497:                                + dcb.getAdminObjectClass() + "'");
498:                }
499:
500:                //todo: Look at the XmlBeans tree and make sure the right stuff is in there
501:                //dcbRoot.toXML(System.out);
502:            }
503:
504:            public void testLoadJMSResources() throws Exception {
505:                InputStream in = classLoader.getResource("jms-plan.xml")
506:                        .openStream();
507:                // Create and test the DDBeanRoot
508:                URL resource = classLoader.getResource("jms.rar");
509:                assertNotNull(resource);
510:                ConnectorDeployable deployable = new ConnectorDeployable(
511:                        resource);
512:                assertEquals(ModuleType.RAR, deployable.getType());
513:                Set entrySet = new HashSet(Collections.list(deployable
514:                        .entries()));
515:                assertTrue(entrySet.contains("META-INF/ra.xml"));
516:                assertTrue(entrySet.contains("activemq-ra-3.2.1.jar"));
517:                DDBeanRoot root = deployable.getDDBeanRoot();
518:                assertNotNull(root);
519:                assertEquals(ModuleType.RAR, root.getType());
520:                assertEquals(deployable, root.getDeployableObject());
521:                // Create the DConfigBeanRoot
522:                Connector15DCBRoot dcbRoot = new Connector15DCBRoot(root);
523:                RARConfiguration configuration = new RARConfiguration(
524:                        deployable, dcbRoot);
525:                configuration.restore(in);
526:                // Try the /connector element
527:                ConnectorDCB connector = (ConnectorDCB) dcbRoot
528:                        .getDConfigBean(root
529:                                .getChildBean(dcbRoot.getXpaths()[0])[0]);
530:                assertNotNull(connector);
531:                // Try the /connector/resourceadapter element
532:                assertNotNull(connector.getResourceAdapter());
533:                assertEquals(1, connector.getResourceAdapter().length);
534:                ResourceAdapter adapter = connector.getResourceAdapter()[0];
535:                assertNotNull(adapter);
536:                // Try the /connector/resourceadapter/resourceadapter-instance element
537:                ResourceAdapterInstance raInstance = adapter
538:                        .getResourceAdapterInstance();
539:                assertNotNull(raInstance);
540:                assertEquals("Test ActiveMQ RA", raInstance
541:                        .getResourceAdapterName());
542:                assertEquals(7, raInstance.getConfigPropertySetting().length);
543:                int found = 0;
544:                Set seen = new HashSet();
545:                for (int i = 0; i < 7; i++) {
546:                    ConfigPropertySetting setting = raInstance
547:                            .getConfigPropertySetting(i);
548:                    if (seen.contains(setting.getName())) {
549:                        fail("Duplicate for config property setting '"
550:                                + setting.getName() + "'");
551:                    }
552:                    seen.add(setting.getName());
553:                    if (setting.getName().equals("ServerUrl")) {
554:                        assertEquals("tcp://localhost:61616", setting
555:                                .getValue());
556:                        ++found;
557:                    } else if (setting.getName().equals("UserName")) {
558:                        assertEquals("geronimo-user", setting.getValue());
559:                        ++found;
560:                    } else if (setting.getName().equals("Password")) {
561:                        assertEquals("geronimo-pw", setting.getValue());
562:                        ++found;
563:                    }
564:                }
565:                assertEquals(3, found);
566:                //todo: check the work manager
567:                // Try the /connector/resourceadapter/outbound-resourceadapter/connection-definition element
568:                assertNotNull(adapter.getConnectionDefinition());
569:                assertEquals(1, adapter.getConnectionDefinition().length);
570:                ConnectionDefinition definition = adapter
571:                        .getConnectionDefinition(0);
572:                // Try the .../connection-definition/connectiondefinition-instance elements
573:                assertNotNull(definition.getConnectionInstances());
574:                assertEquals(1, definition.getConnectionInstances().length);
575:                ConnectionDefinitionInstance instance = definition
576:                        .getConnectionInstances()[0];
577:                // Try the .../connection-definition/connectiondefinition-instance/config-property-setting elements
578:                assertNotNull(instance.getConfigPropertySetting());
579:                assertEquals(0, instance.getConfigPropertySetting().length);
580:                // Try the /connector/adminobject element
581:                DDBean[] ddBeans = connector.getDDBean().getChildBean(
582:                        connector.getXpaths()[0]);
583:                assertNotNull(ddBeans);
584:                assertEquals(2, ddBeans.length);
585:                DConfigBean[] adminDCBs = new DConfigBean[ddBeans.length];
586:                for (int i = 0; i < adminDCBs.length; i++) {
587:                    adminDCBs[i] = connector.getDConfigBean(ddBeans[i]);
588:                    AdminObjectDCB dcb = (AdminObjectDCB) adminDCBs[i];
589:                    if (dcb.getAdminObjectClass().indexOf("Queue") > -1) {
590:                        assertEquals(3, dcb.getAdminObjectInstance().length);
591:                        assertEquals("TestQueue1Name", dcb
592:                                .getAdminObjectInstance()[0]
593:                                .getMessageDestinationName());
594:                        assertEquals("TestQueue2Name", dcb
595:                                .getAdminObjectInstance()[1]
596:                                .getMessageDestinationName());
597:                        assertEquals("TestQueue3Name", dcb
598:                                .getAdminObjectInstance()[2]
599:                                .getMessageDestinationName());
600:                    } else if (dcb.getAdminObjectClass().indexOf("Topic") > -1) {
601:                        assertEquals(1, dcb.getAdminObjectInstance().length);
602:                        assertEquals("TestTopic1Name", dcb
603:                                .getAdminObjectInstance()[0]
604:                                .getMessageDestinationName());
605:                    } else
606:                        fail("Unknown AdminobjectDCB admin object class '"
607:                                + dcb.getAdminObjectClass() + "'");
608:                }
609:                // Make sure that saving clears out the null/default values
610:                ByteArrayOutputStream pout = new ByteArrayOutputStream();
611:                dcbRoot.toXML(pout);
612:                pout.close();
613:                ByteArrayInputStream pin = new ByteArrayInputStream(pout
614:                        .toByteArray());
615:                GerConnectorDocument doc = GerConnectorDocument.Factory
616:                        .parse(pin);
617:                pin.close();
618:                GerConfigPropertySettingType[] settings = doc.getConnector()
619:                        .getResourceadapterArray(0)
620:                        .getResourceadapterInstance()
621:                        .getConfigPropertySettingArray();
622:                assertEquals(2, settings.length);
623:                seen.clear();
624:                for (int i = 0; i < settings.length; i++) {
625:                    GerConfigPropertySettingType setting = settings[i];
626:                    if (seen.contains(setting.getName())) {
627:                        fail("Duplicate for config property setting '"
628:                                + setting.getName() + "'");
629:                    }
630:                    seen.add(setting.getName());
631:                    if (setting.getName().equals("UserName")) {
632:                        assertEquals("geronimo-user", setting.getStringValue());
633:                    } else if (setting.getName().equals("Password")) {
634:                        assertEquals("geronimo-pw", setting.getStringValue());
635:                    } else
636:                        fail("Unknown connection setting '" + setting.getName()
637:                                + "'");
638:                }
639:            }
640:
641:            protected void setUp() throws Exception {
642:                classLoader = Thread.currentThread().getContextClassLoader();
643:            }
644:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.