KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > deployment > jsr88 > Connector15DCBTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.connector.deployment.jsr88;
18
19 import java.io.ByteArrayInputStream JavaDoc;
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Set JavaDoc;
26 import javax.enterprise.deploy.model.DDBean JavaDoc;
27 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
28 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
29 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
30 import junit.framework.TestCase;
31 import org.apache.geronimo.connector.deployment.RARConfiguration;
32 import org.apache.geronimo.deployment.tools.loader.ConnectorDeployable;
33 import org.apache.geronimo.deployment.service.jsr88.EnvironmentData;
34 import org.apache.geronimo.deployment.service.jsr88.Artifact;
35 import org.apache.geronimo.naming.deployment.jsr88.GBeanLocator;
36 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
37 import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
38
39 /**
40  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
41  */

42 public class Connector15DCBTest extends TestCase {
43     private ClassLoader JavaDoc classLoader;
44
45     public void testCreateDatabase() throws Exception JavaDoc {
46         // Create and test the DDBeanRoot
47
URL JavaDoc resource = classLoader.getResource("database.rar");
48         assertNotNull(resource);
49         ConnectorDeployable deployable = new ConnectorDeployable(resource);
50         assertEquals(ModuleType.RAR, deployable.getType());
51         Set JavaDoc entrySet = new HashSet JavaDoc(Collections.list(deployable.entries()));
52         Set JavaDoc resultSet = new HashSet JavaDoc();
53         resultSet.add("META-INF/");
54         resultSet.add("META-INF/MANIFEST.MF");
55         resultSet.add("META-INF/LICENSE.txt");
56         resultSet.add("META-INF/ra.xml");
57         resultSet.add("tranql-connector-1.0.jar");
58         assertEquals(resultSet, entrySet);
59         DDBeanRoot JavaDoc root = deployable.getDDBeanRoot();
60         assertNotNull(root);
61         assertEquals(ModuleType.RAR, root.getType());
62         assertEquals(deployable, root.getDeployableObject());
63         // Create the DConfigBeanRoot
64
Connector15DCBRoot dcbRoot = new Connector15DCBRoot(root);
65         assertNotNull(dcbRoot.getXpaths());
66         assertEquals(1, dcbRoot.getXpaths().length);
67         assertEquals("connector", dcbRoot.getXpaths()[0]);
68         // Try the /connector element
69
ConnectorDCB connector = (ConnectorDCB) dcbRoot.getDConfigBean(root.getChildBean(dcbRoot.getXpaths()[0])[0]);
70         assertNotNull(connector);
71         assertNull(connector.getEnvironment());
72         EnvironmentData environment = new EnvironmentData();
73         connector.setEnvironment(environment);
74         Artifact configId = new Artifact();
75         environment.setConfigId(configId);
76         assertNull(configId.getArtifactId());
77         assertNull(configId.getGroupId());
78         assertNull(configId.getType());
79         assertNull(configId.getVersion());
80         configId.setGroupId("test");
81         configId.setArtifactId("product");
82         configId.setType("rar");
83         configId.setVersion("1.0");
84         Artifact parent = new Artifact();
85         Artifact dependency = new Artifact();
86         environment.setDependencies(new Artifact[]{parent, dependency});
87         assertNull(parent.getArtifactId());
88         assertNull(parent.getGroupId());
89         assertNull(parent.getType());
90         assertNull(parent.getVersion());
91         assertNull(dependency.getArtifactId());
92         assertNull(dependency.getGroupId());
93         assertNull(dependency.getType());
94         assertNull(dependency.getVersion());
95         parent.setGroupId("org.apache.geronimo.configs");
96         parent.setArtifactId("j2ee-server");
97         parent.setType("car");
98         assertNull(parent.getVersion());
99         dependency.setGroupId("postgresql");
100         dependency.setArtifactId("postgresql-8.0");
101         dependency.setType("jar");
102         dependency.setVersion("313.jdbc3");
103         // todo: Try the /connector/environment/hidden-classes element
104
// todo: Try the /connector/environment/non-overridable-classes element
105
// Try the /connector/resourceadapter element
106
assertNotNull(connector.getResourceAdapter());
107         assertEquals(1, connector.getResourceAdapter().length);
108         ResourceAdapter adapter = connector.getResourceAdapter()[0];
109         assertNotNull(adapter);
110         // Try the /connector/resourceadapter/outbound-resourceadapter/connection-definition element
111
assertNotNull(adapter.getConnectionDefinition());
112         assertEquals(0, adapter.getConnectionDefinition().length);
113         ConnectionDefinition definition = new ConnectionDefinition();
114         adapter.setConnectionDefinition(new ConnectionDefinition[]{definition});
115         assertEquals(1, adapter.getConnectionDefinition().length);
116         definition.setConnectionFactoryInterface("javax.sql.DataSource");
117         // Try the .../connection-definition/connectiondefinition-instance elements
118
assertNotNull(definition.getConnectionInstances());
119         assertEquals(0, definition.getConnectionInstances().length);
120         ConnectionDefinitionInstance instance = new ConnectionDefinitionInstance();
121         definition.setConnectionInstance(new ConnectionDefinitionInstance[]{instance});
122         assertEquals(1, definition.getConnectionInstances().length);
123         assertNotNull(instance.getDDBean());
124         // Try the .../connection-definition/connectiondefinition-instance/config-property-setting elements
125
assertNotNull(instance.getConfigPropertySetting());
126         assertEquals(6, instance.getConfigPropertySetting().length);
127         int found = 0;
128         for (int i = 0; i < 6; i++) {
129             ConfigPropertySetting setting = instance.getConfigPropertySetting(i);
130             if(setting.getName().equals("Driver")) {
131                 assertNull(setting.getValue());
132                 setting.setValue("org.postgresql.Driver");
133                 ++found;
134             } else if(setting.getName().equals("ConnectionURL")) {
135                 assertNull(setting.getValue());
136                 setting.setValue("jdbc:postgresql://localhost/TestDatabase");
137                 ++found;
138             } else if(setting.getName().equals("UserName")) {
139                 assertNull(setting.getValue());
140                 setting.setValue("dbuser");
141                 ++found;
142             } else if(setting.getName().equals("Password")) {
143                 assertNull(setting.getValue());
144                 setting.setValue("dbpass");
145                 ++found;
146             } else {
147                 assertNotNull(setting.getValue());
148             }
149         }
150         assertEquals(4, found);
151         // Try the .../connection-definition/connectionmanager elements
152
ConnectionManager manager = instance.getConnectionManager();
153         assertNotNull(manager);
154         assertFalse(manager.isContainerManagedSecurity());
155         assertFalse(manager.isPoolNone());
156         assertNotNull(manager.getPoolSingle());
157         assertNull(manager.getPoolPartitioned());
158         assertFalse(manager.isTransactionLog());
159         assertFalse(manager.isTransactionNone());
160         assertFalse(manager.isTransactionXA());
161         assertFalse(manager.isTransactionXACachingThread());
162         assertFalse(manager.isTransactionXACachingTransaction());
163         assertTrue(manager.isTransactionLocal());
164         SinglePool pool = manager.getPoolSingle();
165         assertNull(pool.getMinSize());
166         assertNull(pool.getMaxSize());
167         assertNull(pool.getIdleTimeoutMinutes());
168         assertNull(pool.getBlockingTimeoutMillis());
169         assertTrue(pool.isMatchOne());
170         assertFalse(pool.isMatchAll());
171         assertFalse(pool.isSelectOneAssumeMatch());
172         pool.setMinSize(new Integer JavaDoc(2));
173         pool.setMaxSize(new Integer JavaDoc(30));
174         pool.setBlockingTimeoutMillis(new Integer JavaDoc(5000));
175         //todo: Look at the XmlBeans tree and make sure the right stuff is in there
176
System.out.println(dcbRoot.getConnectorDocument());
177     }
178
179     public void testWriteWithNulls() throws Exception JavaDoc {
180         InputStream JavaDoc in = classLoader.getResource("plan-with-nulls.xml").openStream();
181
182         // Create and test the DDBeanRoot
183
URL JavaDoc resource = classLoader.getResource("database.rar");
184         assertNotNull(resource);
185         ConnectorDeployable deployable = new ConnectorDeployable(resource);
186         assertEquals(ModuleType.RAR, deployable.getType());
187         DDBeanRoot JavaDoc root = deployable.getDDBeanRoot();
188         assertNotNull(root);
189         assertEquals(ModuleType.RAR, root.getType());
190         assertEquals(deployable, root.getDeployableObject());
191         // Create the DConfigBeanRoot
192
Connector15DCBRoot dcbRoot = new Connector15DCBRoot(root);
193         RARConfiguration configuration = new RARConfiguration(deployable, dcbRoot);
194         configuration.restore(in);
195         // Try the /connector element
196
ConnectorDCB connector = (ConnectorDCB) dcbRoot.getDConfigBean(root.getChildBean(dcbRoot.getXpaths()[0])[0]);
197         assertNotNull(connector);
198         // Try the /connector/resourceadapter element
199
assertNotNull(connector.getResourceAdapter());
200         assertEquals(1, connector.getResourceAdapter().length);
201         ResourceAdapter adapter = connector.getResourceAdapter()[0];
202         assertNotNull(adapter);
203         // Try the /connector/resourceadapter/outbound-resourceadapter/connection-definition element
204
assertNotNull(adapter.getConnectionDefinition());
205         assertEquals(1, adapter.getConnectionDefinition().length);
206         ConnectionDefinition definition = adapter.getConnectionDefinition(0);
207         // Try the .../connection-definition/connectiondefinition-instance elements
208
assertNotNull(definition.getConnectionInstances());
209         assertEquals(1, definition.getConnectionInstances().length);
210         ConnectionDefinitionInstance instance = definition.getConnectionInstances()[0];
211         // Try the .../connection-definition/connectiondefinition-instance/config-property-setting elements
212
assertNotNull(instance.getConfigPropertySetting());
213         assertEquals(6, instance.getConfigPropertySetting().length);
214         int nullCount = 0;
215         for (int i = 0; i < 6; i++) {
216             if(instance.getConfigPropertySetting(i).getValue() == null) {
217                 ++nullCount;
218             } else if(instance.getConfigPropertySetting(i).getValue().equals("")) {
219                 instance.getConfigPropertySetting()[i].setValue(null);
220                 ++nullCount;
221             }
222         }
223         // Read the generated XML and count config property setting elements (should be 4)
224
assertEquals(2, nullCount);
225         ByteArrayOutputStream JavaDoc pout = new ByteArrayOutputStream JavaDoc();
226         dcbRoot.toXML(pout);
227         pout.close();
228         ByteArrayInputStream JavaDoc pin = new ByteArrayInputStream JavaDoc(pout.toByteArray());
229         GerConnectorDocument doc = GerConnectorDocument.Factory.parse(pin);
230         pin.close();
231         GerConfigPropertySettingType[] settings = doc.getConnector().getResourceadapterArray(0).
232                 getOutboundResourceadapter().getConnectionDefinitionArray(0).
233                 getConnectiondefinitionInstanceArray(0).getConfigPropertySettingArray();
234         assertEquals(2, settings.length);
235         Set JavaDoc seen = new HashSet JavaDoc();
236         for (int i = 0; i < settings.length; i++) {
237             GerConfigPropertySettingType setting = settings[i];
238             if(seen.contains(setting.getName())) {
239                 fail("Duplicate for config property setting '"+setting.getName()+"'");
240             }
241             seen.add(setting.getName());
242 // These two are set to their defaults and now no longer appear
243
// if(setting.getName().equals("CommitBeforeAutocommit")) {
244
// assertEquals("false", setting.getStringValue());
245
// } else if(setting.getName().equals("ExceptionSorterClass")) {
246
// assertEquals("org.tranql.connector.AllExceptionsAreFatalSorter", setting.getStringValue());
247
if(setting.getName().equals("Driver")) {
248                 assertEquals("org.apache.derby.jdbc.EmbeddedDriver", setting.getStringValue());
249             } else if(setting.getName().equals("ConnectionURL")) {
250                 assertEquals("jdbc:derby:TestDatabase;create=true", setting.getStringValue());
251             } else fail("Unknown connection setting '"+setting.getName()+"'");
252         }
253         // Make sure the original objects didn't lose track of the null config settings
254
assertEquals(6, instance.getConfigPropertySetting().length);
255         // Now set them to blank
256
nullCount = 0;
257         for (int i = 0; i < 6; i++) {
258             if(instance.getConfigPropertySetting()[i].getValue() == null || instance.getConfigPropertySetting()[i].isSetToDefault()) {
259                 instance.getConfigPropertySetting()[i].setValue("");
260                 ++nullCount;
261             }
262         }
263         assertEquals(4, nullCount);
264         // Now make sure we write out with 6
265
pout = new ByteArrayOutputStream JavaDoc();
266         dcbRoot.toXML(pout);
267         pout.close();
268         pin = new ByteArrayInputStream JavaDoc(pout.toByteArray());
269         doc = GerConnectorDocument.Factory.parse(pin);
270         pin.close();
271         settings = doc.getConnector().getResourceadapterArray(0).
272                 getOutboundResourceadapter().getConnectionDefinitionArray(0).
273                 getConnectiondefinitionInstanceArray(0).getConfigPropertySettingArray();
274         assertEquals(6, settings.length);
275         seen.clear();
276         for (int i = 0; i < settings.length; i++) {
277             GerConfigPropertySettingType setting = settings[i];
278             if(seen.contains(setting.getName())) {
279                 fail("Duplicate for config property setting '"+setting.getName()+"'");
280             }
281             seen.add(setting.getName());
282             if(setting.getName().equals("UserName")) {
283                 assertEquals("", setting.getStringValue());
284             } else if(setting.getName().equals("Password")) {
285                 assertEquals("", setting.getStringValue());
286             } else if(setting.getName().equals("CommitBeforeAutocommit")) {
287                 assertEquals("", setting.getStringValue());
288             } else if(setting.getName().equals("Driver")) {
289                 assertEquals("org.apache.derby.jdbc.EmbeddedDriver", setting.getStringValue());
290             } else if(setting.getName().equals("ExceptionSorterClass")) {
291                 assertEquals("", setting.getStringValue());
292             } else if(setting.getName().equals("ConnectionURL")) {
293                 assertEquals("jdbc:derby:TestDatabase;create=true", setting.getStringValue());
294             } else fail("Unknown connection setting '"+setting.getName()+"'");
295         }
296     }
297
298     public void testCreateJMSResource() throws Exception JavaDoc {
299         // Create and test the DDBeanRoot
300
URL JavaDoc resource = classLoader.getResource("jms.rar");
301         assertNotNull(resource);
302         ConnectorDeployable deployable = new ConnectorDeployable(resource);
303         assertEquals(ModuleType.RAR, deployable.getType());
304         Set JavaDoc entrySet = new HashSet JavaDoc(Collections.list(deployable.entries()));
305         assertTrue(entrySet.contains("META-INF/ra.xml"));
306         assertTrue(entrySet.contains("activemq-ra-3.2.1.jar"));
307         DDBeanRoot JavaDoc root = deployable.getDDBeanRoot();
308         assertNotNull(root);
309         assertEquals(ModuleType.RAR, root.getType());
310         assertEquals(deployable, root.getDeployableObject());
311         // Create the DConfigBeanRoot
312
Connector15DCBRoot dcbRoot = new Connector15DCBRoot(root);
313         assertNotNull(dcbRoot.getXpaths());
314         assertEquals(1, dcbRoot.getXpaths().length);
315         assertEquals("connector", dcbRoot.getXpaths()[0]);
316         // Try the /connector element
317
ConnectorDCB connector = (ConnectorDCB) dcbRoot.getDConfigBean(root.getChildBean(dcbRoot.getXpaths()[0])[0]);
318         assertNotNull(connector);
319 // assertNull(connector.getConfigID());
320
// assertNull(connector.getInverseClassLoading());
321
// assertNull(connector.getParentID());
322
// assertNull(connector.getSuppressDefaultParentID());
323
// connector.setConfigID("MyJMS");
324
// connector.setParentID("geronimo/activemq/1.0/car");
325
// Try the /connector/dependency element
326
// assertNotNull(connector.getArtifactType());
327
// assertEquals(0, connector.getArtifactType().length);
328
// Artifact dep = new Artifact();
329
// connector.setDependency(new Artifact[]{dep});
330
// assertEquals(1, connector.getArtifactType().length);
331
// dep.setURI("postgresql/postgresql-8.0/313.jdbc3/jar");
332
// assertNull(dep.getArtifactId());
333
// assertNull(dep.getGroupId());
334
// assertNull(dep.getType());
335
// assertNull(dep.getVersion());
336
// dep.setGroupId("postgresql");
337
// dep.setArtifactId("postgresql-8.0");
338
// dep.setVersion("313.jdbc3");
339
// assertNull(dep.getURI());
340
// assertNull(dep.getType());
341
// todo: Try the /connector/import element
342
// todo: Try the /connector/hidden-classes element
343
// todo: Try the /connector/non-overridable-classes element
344
// Try the /connector/resourceadapter element
345
assertNotNull(connector.getResourceAdapter());
346         assertEquals(1, connector.getResourceAdapter().length);
347         ResourceAdapter adapter = connector.getResourceAdapter()[0];
348         assertNotNull(adapter);
349         // Try the /connector/resourceadapter/resourceadapter-instance element
350
assertNull(adapter.getResourceAdapterInstance());
351         adapter.setResourceAdapterInstance(new ResourceAdapterInstance());
352         ResourceAdapterInstance raInstance = adapter.getResourceAdapterInstance();
353         assertNull(raInstance.getResourceAdapterName());
354         assertNotNull(raInstance.getConfigProperties());
355         assertEquals(7, raInstance.getConfigPropertySetting().length);
356         for (int i = 0; i < raInstance.getConfigPropertySetting().length; i++) {
357             ConfigPropertySetting config = raInstance.getConfigPropertySetting()[i];
358             assertTrue(config.isSetToDefault());
359         }
360         int found = 0;
361         for (int i = 0; i < 7; i++) {
362             ConfigPropertySetting setting = raInstance.getConfigPropertySetting(i);
363             if(setting.getName().equals("ServerUrl")) {
364                 setting.setValue("tcp://localhost:12345");
365                 ++found;
366             } else if(setting.getName().equals("UserName")) {
367                 setting.setValue("test-user");
368                 ++found;
369             } else if(setting.getName().equals("Password")) {
370                 setting.setValue("test-password");
371                 ++found;
372             }
373         }
374         assertEquals(found, 3);
375         // Try the /connector/resourceadapter/resourceadapter-instance/workmanager
376
assertNull(raInstance.getWorkManager());
377         GBeanLocator workManager = new GBeanLocator();
378         raInstance.setWorkManager(workManager);
379         workManager.setGBeanLink("DefaultWorkManager");
380         // Try the /connector/resourceadapter/outbound-resourceadapter/connection-definition element
381
assertNotNull(adapter.getConnectionDefinition());
382         assertEquals(0, adapter.getConnectionDefinition().length);
383         ConnectionDefinition definition = new ConnectionDefinition();
384         adapter.setConnectionDefinition(new ConnectionDefinition[]{definition});
385         assertEquals(1, adapter.getConnectionDefinition().length);
386         definition.setConnectionFactoryInterface("javax.jms.ConnectionFactory");
387         // Try the .../connection-definition/connectiondefinition-instance elements
388
assertNotNull(definition.getConnectionInstances());
389         assertEquals(0, definition.getConnectionInstances().length);
390         ConnectionDefinitionInstance instance = new ConnectionDefinitionInstance();
391         definition.setConnectionInstance(new ConnectionDefinitionInstance[]{instance});
392         assertEquals(1, definition.getConnectionInstances().length);
393         assertNotNull(instance.getDDBean());
394         instance.setName("Test JMS Resource");
395         instance.setImplementedInterface(new String JavaDoc[]{"javax.jms.QueueConnectorFactory","javax.jms.TopicConnectionFactory"});
396         // Try the .../connection-definition/connectiondefinition-instance/config-property-setting elements
397
assertNotNull(instance.getConfigPropertySetting());
398         assertEquals(0, instance.getConfigPropertySetting().length);
399         // Try the .../connection-definition/connectionmanager elements
400
ConnectionManager manager = instance.getConnectionManager();
401         assertNotNull(manager);
402         assertFalse(manager.isContainerManagedSecurity());
403         assertFalse(manager.isPoolNone());
404         assertNotNull(manager.getPoolSingle());
405         assertNull(manager.getPoolPartitioned());
406         assertFalse(manager.isTransactionLog());
407         assertFalse(manager.isTransactionNone());
408         assertTrue(manager.isTransactionXA());
409         assertFalse(manager.isTransactionXACachingThread());
410         assertTrue(manager.isTransactionXACachingTransaction());
411         assertFalse(manager.isTransactionLocal());
412         SinglePool pool = manager.getPoolSingle();
413         assertNull(pool.getMinSize());
414         assertNull(pool.getMaxSize());
415         assertNull(pool.getIdleTimeoutMinutes());
416         assertNull(pool.getBlockingTimeoutMillis());
417         assertTrue(pool.isMatchOne());
418         assertFalse(pool.isMatchAll());
419         assertFalse(pool.isSelectOneAssumeMatch());
420         pool.setMinSize(new Integer JavaDoc(2));
421         pool.setMaxSize(new Integer JavaDoc(30));
422         pool.setBlockingTimeoutMillis(new Integer JavaDoc(5000));
423         DDBean JavaDoc[] ddBeans = connector.getDDBean().getChildBean(connector.getXpaths()[0]);
424         assertNotNull(ddBeans);
425         assertEquals(2, ddBeans.length);
426         DConfigBean JavaDoc[] adminDCBs = new DConfigBean JavaDoc[ddBeans.length];
427         for (int i = 0; i < adminDCBs.length; i++) {
428             adminDCBs[i] = connector.getDConfigBean(ddBeans[i]);
429             AdminObjectDCB dcb = (AdminObjectDCB) adminDCBs[i];
430             if(dcb.getAdminObjectClass().indexOf("Queue") > -1) {
431                 assertEquals(0, dcb.getAdminObjectInstance().length);
432                 AdminObjectInstance one = new AdminObjectInstance();
433                 AdminObjectInstance two = new AdminObjectInstance();
434                 dcb.setAdminObjectInstance(new AdminObjectInstance[]{one, two});
435                 one.setMessageDestinationName("TestQueue1");
436                 one.getConfigPropertySetting()[0].setValue("PhysicalName1");
437                 two.setMessageDestinationName("TestQueue2");
438                 two.getConfigPropertySetting()[0].setValue("PhysicalName2");
439             } else if(dcb.getAdminObjectClass().indexOf("Topic") > -1) {
440                 assertEquals(0, dcb.getAdminObjectInstance().length);
441             } else fail("Unknown AdminobjectDCB admin object class '"+dcb.getAdminObjectClass()+"'");
442         }
443
444
445         //todo: Look at the XmlBeans tree and make sure the right stuff is in there
446
//dcbRoot.toXML(System.out);
447
}
448
449     public void testLoadJMSResources() throws Exception JavaDoc {
450         InputStream JavaDoc in = classLoader.getResource("jms-plan.xml").openStream();
451         // Create and test the DDBeanRoot
452
URL JavaDoc resource = classLoader.getResource("jms.rar");
453         assertNotNull(resource);
454         ConnectorDeployable deployable = new ConnectorDeployable(resource);
455         assertEquals(ModuleType.RAR, deployable.getType());
456         Set JavaDoc entrySet = new HashSet JavaDoc(Collections.list(deployable.entries()));
457         assertTrue(entrySet.contains("META-INF/ra.xml"));
458         assertTrue(entrySet.contains("activemq-ra-3.2.1.jar"));
459         DDBeanRoot JavaDoc root = deployable.getDDBeanRoot();
460         assertNotNull(root);
461         assertEquals(ModuleType.RAR, root.getType());
462         assertEquals(deployable, root.getDeployableObject());
463         // Create the DConfigBeanRoot
464
Connector15DCBRoot dcbRoot = new Connector15DCBRoot(root);
465         RARConfiguration configuration = new RARConfiguration(deployable, dcbRoot);
466         configuration.restore(in);
467         // Try the /connector element
468
ConnectorDCB connector = (ConnectorDCB) dcbRoot.getDConfigBean(root.getChildBean(dcbRoot.getXpaths()[0])[0]);
469         assertNotNull(connector);
470         // Try the /connector/resourceadapter element
471
assertNotNull(connector.getResourceAdapter());
472         assertEquals(1, connector.getResourceAdapter().length);
473         ResourceAdapter adapter = connector.getResourceAdapter()[0];
474         assertNotNull(adapter);
475         // Try the /connector/resourceadapter/resourceadapter-instance element
476
ResourceAdapterInstance raInstance = adapter.getResourceAdapterInstance();
477         assertNotNull(raInstance);
478         assertEquals("Test ActiveMQ RA", raInstance.getResourceAdapterName());
479         assertEquals(7, raInstance.getConfigPropertySetting().length);
480         int found = 0;
481         Set JavaDoc seen = new HashSet JavaDoc();
482         for (int i = 0; i < 7; i++) {
483             ConfigPropertySetting setting = raInstance.getConfigPropertySetting(i);
484             if(seen.contains(setting.getName())) {
485                 fail("Duplicate for config property setting '"+setting.getName()+"'");
486             }
487             seen.add(setting.getName());
488             if(setting.getName().equals("ServerUrl")) {
489                 assertEquals("tcp://localhost:61616", setting.getValue());
490                 ++found;
491             } else if(setting.getName().equals("UserName")) {
492                 assertEquals("geronimo-user", setting.getValue());
493                 ++found;
494             } else if(setting.getName().equals("Password")) {
495                 assertEquals("geronimo-pw", setting.getValue());
496                 ++found;
497             }
498         }
499         assertEquals(3, found);
500         //todo: check the work manager
501
// Try the /connector/resourceadapter/outbound-resourceadapter/connection-definition element
502
assertNotNull(adapter.getConnectionDefinition());
503         assertEquals(1, adapter.getConnectionDefinition().length);
504         ConnectionDefinition definition = adapter.getConnectionDefinition(0);
505         // Try the .../connection-definition/connectiondefinition-instance elements
506
assertNotNull(definition.getConnectionInstances());
507         assertEquals(1, definition.getConnectionInstances().length);
508         ConnectionDefinitionInstance instance = definition.getConnectionInstances()[0];
509         // Try the .../connection-definition/connectiondefinition-instance/config-property-setting elements
510
assertNotNull(instance.getConfigPropertySetting());
511         assertEquals(0, instance.getConfigPropertySetting().length);
512         // Try the /connector/adminobject element
513
DDBean JavaDoc[] ddBeans = connector.getDDBean().getChildBean(connector.getXpaths()[0]);
514         assertNotNull(ddBeans);
515         assertEquals(2, ddBeans.length);
516         DConfigBean JavaDoc[] adminDCBs = new DConfigBean JavaDoc[ddBeans.length];
517         for (int i = 0; i < adminDCBs.length; i++) {
518             adminDCBs[i] = connector.getDConfigBean(ddBeans[i]);
519             AdminObjectDCB dcb = (AdminObjectDCB) adminDCBs[i];
520             if(dcb.getAdminObjectClass().indexOf("Queue") > -1) {
521                 assertEquals(3, dcb.getAdminObjectInstance().length);
522                 assertEquals("TestQueue1Name", dcb.getAdminObjectInstance()[0].getMessageDestinationName());
523                 assertEquals("TestQueue2Name", dcb.getAdminObjectInstance()[1].getMessageDestinationName());
524                 assertEquals("TestQueue3Name", dcb.getAdminObjectInstance()[2].getMessageDestinationName());
525             } else if(dcb.getAdminObjectClass().indexOf("Topic") > -1) {
526                 assertEquals(1, dcb.getAdminObjectInstance().length);
527                 assertEquals("TestTopic1Name", dcb.getAdminObjectInstance()[0].getMessageDestinationName());
528             } else fail("Unknown AdminobjectDCB admin object class '"+dcb.getAdminObjectClass()+"'");
529         }
530         // Make sure that saving clears out the null/default values
531
ByteArrayOutputStream JavaDoc pout = new ByteArrayOutputStream JavaDoc();
532         dcbRoot.toXML(pout);
533         pout.close();
534         ByteArrayInputStream JavaDoc pin = new ByteArrayInputStream JavaDoc(pout.toByteArray());
535         GerConnectorDocument doc = GerConnectorDocument.Factory.parse(pin);
536         pin.close();
537         GerConfigPropertySettingType[] settings = doc.getConnector().getResourceadapterArray(0).
538                 getResourceadapterInstance().getConfigPropertySettingArray();
539         assertEquals(2, settings.length);
540         seen.clear();
541         for (int i = 0; i < settings.length; i++) {
542             GerConfigPropertySettingType setting = settings[i];
543             if(seen.contains(setting.getName())) {
544                 fail("Duplicate for config property setting '"+setting.getName()+"'");
545             }
546             seen.add(setting.getName());
547             if(setting.getName().equals("UserName")) {
548                 assertEquals("geronimo-user", setting.getStringValue());
549             } else if(setting.getName().equals("Password")) {
550                 assertEquals("geronimo-pw", setting.getStringValue());
551             } else fail("Unknown connection setting '"+setting.getName()+"'");
552         }
553     }
554
555     protected void setUp() throws Exception JavaDoc {
556         classLoader = Thread.currentThread().getContextClassLoader();
557     }
558 }
559
Popular Tags