KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > deployment > RAR_1_5DConfigBeanTest


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
18 package org.apache.geronimo.connector.deployment;
19
20 import java.io.ByteArrayInputStream JavaDoc;
21 import java.io.ByteArrayOutputStream JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 import javax.enterprise.deploy.model.DDBean JavaDoc;
29 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
30 import javax.enterprise.deploy.spi.DConfigBeanRoot JavaDoc;
31 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
32
33 import junit.framework.TestCase;
34 import org.apache.geronimo.connector.deployment.dconfigbean.AdminObjectDConfigBean;
35 import org.apache.geronimo.connector.deployment.dconfigbean.AdminObjectInstance;
36 import org.apache.geronimo.connector.deployment.dconfigbean.ConfigPropertySettingDConfigBean;
37 import org.apache.geronimo.connector.deployment.dconfigbean.ConfigPropertySettings;
38 import org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionDConfigBean;
39 import org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionInstance;
40 import org.apache.geronimo.connector.deployment.dconfigbean.ResourceAdapterDConfigBean;
41 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
42 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
43 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
44 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
45 import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
46 import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
47 import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
48 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterInstanceType;
49 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
50 import org.apache.xmlbeans.XmlOptions;
51
52 /**
53  *
54  *
55  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
56  *
57  * */

58 public class RAR_1_5DConfigBeanTest extends TestCase {
59     public void testNothing() {}
60     /* In the process of replacing the Connector 1.5 DConfigBeans
61     private static final File basedir = new File(System.getProperty("basedir", System.getProperty("user.dir")));
62     private URL j2eeDD;
63     XmlOptions xmlOptions;
64     private List errors;
65
66
67     public void testDConfigBeans() throws Exception {
68         MockRARDeployable deployable = new MockRARDeployable(j2eeDD);
69         DDBeanRoot ddroot = deployable.getDDBeanRoot();
70         DeploymentConfiguration rarConfiguration = new RARConfigurer().createConfiguration(deployable);
71         DConfigBeanRoot root = rarConfiguration.getDConfigBeanRoot(ddroot);
72         assertNotNull(root);
73
74         //resource adapter
75         DDBean resourceAdapterdd = ddroot.getChildBean(root.getXpaths()[0])[0];
76         ResourceAdapterDConfigBean resourceAdapterDConfigBean = (ResourceAdapterDConfigBean) root.getDConfigBean(resourceAdapterdd);
77         assertNotNull(resourceAdapterDConfigBean);
78         resourceAdapterDConfigBean.setResourceAdapterName("TestRAName");
79         DDBean[] resourceAdapterProperties = resourceAdapterdd.getChildBean(resourceAdapterDConfigBean.getXpaths()[0]);
80         assertEquals(1, resourceAdapterProperties.length);
81         ConfigPropertySettingDConfigBean resourceAdapterSetting = (ConfigPropertySettingDConfigBean)resourceAdapterDConfigBean.getDConfigBean(resourceAdapterProperties[0]);
82         assertNotNull(resourceAdapterSetting);
83         assertEquals("StringValue", resourceAdapterSetting.getConfigPropertyValue());
84         resourceAdapterSetting.setConfigPropertyValue("TestRAValue");
85
86 // //admin objects
87 // DDBean[] adminObjectdds = resourceAdapterdd.getChildBean(resourceAdapterDConfigBean.getXpaths()[2]);
88 // assertEquals(1, adminObjectdds.length);
89 // AdminObjectDConfigBean adminObjectDConfigBean = (AdminObjectDConfigBean)resourceAdapterDConfigBean.getDConfigBean(adminObjectdds[0]);
90 // assertNotNull(adminObjectDConfigBean);
91 // AdminObjectInstance adminObjectInstance1 = new AdminObjectInstance();
92 // adminObjectDConfigBean.setAdminObjectInstance(new AdminObjectInstance[] {adminObjectInstance1});
93 // ConfigPropertySettings adminObjectSetting1 = adminObjectInstance1.getConfigProperty()[0];
94 // adminObjectSetting1.setConfigPropertyValue("TestAOValue1");
95 //
96 // //add a second admin object in first position
97 // AdminObjectInstance adminObjectInstance2 = new AdminObjectInstance();
98 // adminObjectDConfigBean.setAdminObjectInstance(new AdminObjectInstance[] {adminObjectInstance2, adminObjectInstance1});
99 // ConfigPropertySettings adminObjectSetting2 = adminObjectInstance2.getConfigProperty()[0];
100 // adminObjectSetting2.setConfigPropertyValue("TestAOValue2");
101
102         //outbound
103         DDBean[] connectionDefinitiondds = resourceAdapterdd.getChildBean(resourceAdapterDConfigBean.getXpaths()[1]);
104         assertEquals(2, connectionDefinitiondds.length);
105         ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = (ConnectionDefinitionDConfigBean)resourceAdapterDConfigBean.getDConfigBean(connectionDefinitiondds[0]);
106         assertNotNull(connectionDefinitionDConfigBean);
107         ConnectionDefinitionInstance connectionDefinitionInstance1 = new ConnectionDefinitionInstance();
108         connectionDefinitionDConfigBean.setConnectionDefinitionInstance(new ConnectionDefinitionInstance[] {connectionDefinitionInstance1});
109         DDBean[] connectionDefinitionConfigPropDDs = connectionDefinitiondds[0].getChildBean("config-property");
110         assertEquals(4, connectionDefinitionConfigPropDDs.length);
111         ConfigPropertySettings connectionDefinitionSetting1 = connectionDefinitionInstance1.getConfigProperty()[0];
112         connectionDefinitionSetting1.setConfigPropertyValue("TestCDValue1");
113         //connection manager properties
114 // connectionDefinitionInstance1.setBlockingTimeout(3000);
115
116         //check the results
117         ByteArrayOutputStream baos = new ByteArrayOutputStream();
118         rarConfiguration.save(baos);
119         baos.flush();
120         byte[] bytes = baos.toByteArray();
121         baos.close();
122         InputStream is = new ByteArrayInputStream(bytes);
123         GerConnectorDocument gcDoc = GerConnectorDocument.Factory.parse(is);
124         GerResourceadapterType ra = gcDoc.getConnector().getResourceadapterArray()[0];
125         GerResourceadapterInstanceType rai = ra.getResourceadapterInstance();
126         assertEquals("TestRAName", rai.getResourceadapterName());
127         GerConfigPropertySettingType rasetting = rai.getConfigPropertySettingArray(0);
128         assertEquals("TestRAValue", rasetting.getStringValue());
129
130         //admin object
131 // GerAdminobjectType adminobjectType1 = ra.getAdminobjectArray(0);
132 // GerAdminobjectInstanceType adminobjectInstanceType2 = adminobjectType1.getAdminobjectInstanceArray(0);
133 // assertEquals("TestAOValue1", adminobjectInstanceType2.getConfigPropertySettingArray(0).getStringValue());
134 // GerAdminobjectInstanceType adminobjectInstanceType1 = adminobjectType1.getAdminobjectInstanceArray(1);
135 // assertEquals("TestAOValue2", adminobjectInstanceType1.getConfigPropertySettingArray(0).getStringValue());
136
137         //connection definition
138         GerConnectionDefinitionType connectionDefinitionType = ra.getOutboundResourceadapter().getConnectionDefinitionArray(0);
139         GerConnectiondefinitionInstanceType connectiondefinitionInstanceType = connectionDefinitionType.getConnectiondefinitionInstanceArray(0);
140         assertEquals("TestCDValue1", connectiondefinitionInstanceType.getConfigPropertySettingArray(0).getStringValue());
141         //connection manager
142         GerConnectionmanagerType connectionmanagerType = connectiondefinitionInstanceType.getConnectionmanager();
143 // assertEquals(3000, connectionmanagerType.getBlockingTimeout().intValue());
144
145         //and read back into dconfigbeans
146         rarConfiguration.restore(new ByteArrayInputStream(bytes));
147         //resource adapter
148         resourceAdapterDConfigBean = (ResourceAdapterDConfigBean) root.getDConfigBean(resourceAdapterdd);
149         assertNotNull(resourceAdapterDConfigBean);
150         assertEquals("TestRAName", resourceAdapterDConfigBean.getResourceAdapterName());
151         resourceAdapterSetting = (ConfigPropertySettingDConfigBean)resourceAdapterDConfigBean.getDConfigBean(resourceAdapterProperties[0]);
152         assertNotNull(resourceAdapterSetting);
153         assertEquals("TestRAValue", resourceAdapterSetting.getConfigPropertyValue());
154
155 // //admin objects
156 // adminObjectDConfigBean = (AdminObjectDConfigBean)resourceAdapterDConfigBean.getDConfigBean(adminObjectdds[0]);
157 // assertNotNull(adminObjectDConfigBean);
158 // AdminObjectInstance[] adminObjectInstances = adminObjectDConfigBean.getAdminObjectInstance();
159 // assertEquals(2, adminObjectInstances.length);
160 // adminObjectSetting1 = adminObjectInstances[1].getConfigProperty()[0];
161 // assertEquals("TestAOValue2", adminObjectSetting1.getConfigPropertyValue());
162 //
163 // //second admin object is in first position ..not any longer:-(((
164 // adminObjectSetting2 = adminObjectInstances[0].getConfigProperty()[0];
165 // assertEquals("TestAOValue1", adminObjectSetting2.getConfigPropertyValue());
166
167         //outbound
168         connectionDefinitionDConfigBean = (ConnectionDefinitionDConfigBean)resourceAdapterDConfigBean.getDConfigBean(connectionDefinitiondds[0]);
169         assertNotNull(connectionDefinitionDConfigBean);
170         ConnectionDefinitionInstance[] connectionDefinitionInstances = connectionDefinitionDConfigBean.getConnectionDefinitionInstance();
171         connectionDefinitionSetting1 = connectionDefinitionInstances[0].getConfigProperty()[0];
172         assertEquals("TestCDValue1", connectionDefinitionSetting1.getConfigPropertyValue());
173         //connection manager
174 // assertEquals(3000, connectionDefinitionInstances[0].getBlockingTimeout());
175
176     }
177
178
179
180     protected void setUp() throws Exception {
181         File docDir = new File(basedir, "src/test-data/connector_1_5");
182         j2eeDD = new File(docDir, "ra.xml").toURL();
183         xmlOptions = new XmlOptions();
184         xmlOptions.setLoadLineNumbers();
185         errors = new ArrayList();
186         xmlOptions.setErrorListener(errors);
187     }
188 */

189 }
190
Popular Tags