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;
017:
018: import java.io.ByteArrayInputStream;
019: import java.io.ByteArrayOutputStream;
020: import java.io.File;
021: import java.io.InputStream;
022: import java.net.URL;
023: import java.util.ArrayList;
024: import java.util.List;
025:
026: import javax.enterprise.deploy.model.DDBean;
027: import javax.enterprise.deploy.model.DDBeanRoot;
028: import javax.enterprise.deploy.spi.DConfigBeanRoot;
029: import javax.enterprise.deploy.spi.DeploymentConfiguration;
030:
031: import junit.framework.TestCase;
032: import org.apache.geronimo.connector.deployment.dconfigbean.AdminObjectDConfigBean;
033: import org.apache.geronimo.connector.deployment.dconfigbean.AdminObjectInstance;
034: import org.apache.geronimo.connector.deployment.dconfigbean.ConfigPropertySettingDConfigBean;
035: import org.apache.geronimo.connector.deployment.dconfigbean.ConfigPropertySettings;
036: import org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionDConfigBean;
037: import org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionInstance;
038: import org.apache.geronimo.connector.deployment.dconfigbean.ResourceAdapterDConfigBean;
039: import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
040: import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
041: import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
042: import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
043: import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
044: import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
045: import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
046: import org.apache.geronimo.xbeans.geronimo.GerResourceadapterInstanceType;
047: import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
048: import org.apache.xmlbeans.XmlOptions;
049:
050: /**
051: *
052: *
053: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
054: *
055: * */
056: public class RAR_1_5DConfigBeanTest extends TestCase {
057: public void testNothing() {
058: }
059: /* In the process of replacing the Connector 1.5 DConfigBeans
060: private static final File basedir = new File(System.getProperty("basedir", System.getProperty("user.dir")));
061: private URL j2eeDD;
062: XmlOptions xmlOptions;
063: private List errors;
064:
065:
066: public void testDConfigBeans() throws Exception {
067: MockRARDeployable deployable = new MockRARDeployable(j2eeDD);
068: DDBeanRoot ddroot = deployable.getDDBeanRoot();
069: DeploymentConfiguration rarConfiguration = new RARConfigurer().createConfiguration(deployable);
070: DConfigBeanRoot root = rarConfiguration.getDConfigBeanRoot(ddroot);
071: assertNotNull(root);
072:
073: //resource adapter
074: DDBean resourceAdapterdd = ddroot.getChildBean(root.getXpaths()[0])[0];
075: ResourceAdapterDConfigBean resourceAdapterDConfigBean = (ResourceAdapterDConfigBean) root.getDConfigBean(resourceAdapterdd);
076: assertNotNull(resourceAdapterDConfigBean);
077: resourceAdapterDConfigBean.setResourceAdapterName("TestRAName");
078: DDBean[] resourceAdapterProperties = resourceAdapterdd.getChildBean(resourceAdapterDConfigBean.getXpaths()[0]);
079: assertEquals(1, resourceAdapterProperties.length);
080: ConfigPropertySettingDConfigBean resourceAdapterSetting = (ConfigPropertySettingDConfigBean)resourceAdapterDConfigBean.getDConfigBean(resourceAdapterProperties[0]);
081: assertNotNull(resourceAdapterSetting);
082: assertEquals("StringValue", resourceAdapterSetting.getConfigPropertyValue());
083: resourceAdapterSetting.setConfigPropertyValue("TestRAValue");
084:
085: // //admin objects
086: // DDBean[] adminObjectdds = resourceAdapterdd.getChildBean(resourceAdapterDConfigBean.getXpaths()[2]);
087: // assertEquals(1, adminObjectdds.length);
088: // AdminObjectDConfigBean adminObjectDConfigBean = (AdminObjectDConfigBean)resourceAdapterDConfigBean.getDConfigBean(adminObjectdds[0]);
089: // assertNotNull(adminObjectDConfigBean);
090: // AdminObjectInstance adminObjectInstance1 = new AdminObjectInstance();
091: // adminObjectDConfigBean.setAdminObjectInstance(new AdminObjectInstance[] {adminObjectInstance1});
092: // ConfigPropertySettings adminObjectSetting1 = adminObjectInstance1.getConfigProperty()[0];
093: // adminObjectSetting1.setConfigPropertyValue("TestAOValue1");
094: //
095: // //add a second admin object in first position
096: // AdminObjectInstance adminObjectInstance2 = new AdminObjectInstance();
097: // adminObjectDConfigBean.setAdminObjectInstance(new AdminObjectInstance[] {adminObjectInstance2, adminObjectInstance1});
098: // ConfigPropertySettings adminObjectSetting2 = adminObjectInstance2.getConfigProperty()[0];
099: // adminObjectSetting2.setConfigPropertyValue("TestAOValue2");
100:
101: //outbound
102: DDBean[] connectionDefinitiondds = resourceAdapterdd.getChildBean(resourceAdapterDConfigBean.getXpaths()[1]);
103: assertEquals(2, connectionDefinitiondds.length);
104: ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = (ConnectionDefinitionDConfigBean)resourceAdapterDConfigBean.getDConfigBean(connectionDefinitiondds[0]);
105: assertNotNull(connectionDefinitionDConfigBean);
106: ConnectionDefinitionInstance connectionDefinitionInstance1 = new ConnectionDefinitionInstance();
107: connectionDefinitionDConfigBean.setConnectionDefinitionInstance(new ConnectionDefinitionInstance[] {connectionDefinitionInstance1});
108: DDBean[] connectionDefinitionConfigPropDDs = connectionDefinitiondds[0].getChildBean("config-property");
109: assertEquals(4, connectionDefinitionConfigPropDDs.length);
110: ConfigPropertySettings connectionDefinitionSetting1 = connectionDefinitionInstance1.getConfigProperty()[0];
111: connectionDefinitionSetting1.setConfigPropertyValue("TestCDValue1");
112: //connection manager properties
113: // connectionDefinitionInstance1.setBlockingTimeout(3000);
114:
115: //check the results
116: ByteArrayOutputStream baos = new ByteArrayOutputStream();
117: rarConfiguration.save(baos);
118: baos.flush();
119: byte[] bytes = baos.toByteArray();
120: baos.close();
121: InputStream is = new ByteArrayInputStream(bytes);
122: GerConnectorDocument gcDoc = GerConnectorDocument.Factory.parse(is);
123: GerResourceadapterType ra = gcDoc.getConnector().getResourceadapterArray()[0];
124: GerResourceadapterInstanceType rai = ra.getResourceadapterInstance();
125: assertEquals("TestRAName", rai.getResourceadapterName());
126: GerConfigPropertySettingType rasetting = rai.getConfigPropertySettingArray(0);
127: assertEquals("TestRAValue", rasetting.getStringValue());
128:
129: //admin object
130: // GerAdminobjectType adminobjectType1 = ra.getAdminobjectArray(0);
131: // GerAdminobjectInstanceType adminobjectInstanceType2 = adminobjectType1.getAdminobjectInstanceArray(0);
132: // assertEquals("TestAOValue1", adminobjectInstanceType2.getConfigPropertySettingArray(0).getStringValue());
133: // GerAdminobjectInstanceType adminobjectInstanceType1 = adminobjectType1.getAdminobjectInstanceArray(1);
134: // assertEquals("TestAOValue2", adminobjectInstanceType1.getConfigPropertySettingArray(0).getStringValue());
135:
136: //connection definition
137: GerConnectionDefinitionType connectionDefinitionType = ra.getOutboundResourceadapter().getConnectionDefinitionArray(0);
138: GerConnectiondefinitionInstanceType connectiondefinitionInstanceType = connectionDefinitionType.getConnectiondefinitionInstanceArray(0);
139: assertEquals("TestCDValue1", connectiondefinitionInstanceType.getConfigPropertySettingArray(0).getStringValue());
140: //connection manager
141: GerConnectionmanagerType connectionmanagerType = connectiondefinitionInstanceType.getConnectionmanager();
142: // assertEquals(3000, connectionmanagerType.getBlockingTimeout().intValue());
143:
144: //and read back into dconfigbeans
145: rarConfiguration.restore(new ByteArrayInputStream(bytes));
146: //resource adapter
147: resourceAdapterDConfigBean = (ResourceAdapterDConfigBean) root.getDConfigBean(resourceAdapterdd);
148: assertNotNull(resourceAdapterDConfigBean);
149: assertEquals("TestRAName", resourceAdapterDConfigBean.getResourceAdapterName());
150: resourceAdapterSetting = (ConfigPropertySettingDConfigBean)resourceAdapterDConfigBean.getDConfigBean(resourceAdapterProperties[0]);
151: assertNotNull(resourceAdapterSetting);
152: assertEquals("TestRAValue", resourceAdapterSetting.getConfigPropertyValue());
153:
154: // //admin objects
155: // adminObjectDConfigBean = (AdminObjectDConfigBean)resourceAdapterDConfigBean.getDConfigBean(adminObjectdds[0]);
156: // assertNotNull(adminObjectDConfigBean);
157: // AdminObjectInstance[] adminObjectInstances = adminObjectDConfigBean.getAdminObjectInstance();
158: // assertEquals(2, adminObjectInstances.length);
159: // adminObjectSetting1 = adminObjectInstances[1].getConfigProperty()[0];
160: // assertEquals("TestAOValue2", adminObjectSetting1.getConfigPropertyValue());
161: //
162: // //second admin object is in first position ..not any longer:-(((
163: // adminObjectSetting2 = adminObjectInstances[0].getConfigProperty()[0];
164: // assertEquals("TestAOValue1", adminObjectSetting2.getConfigPropertyValue());
165:
166: //outbound
167: connectionDefinitionDConfigBean = (ConnectionDefinitionDConfigBean)resourceAdapterDConfigBean.getDConfigBean(connectionDefinitiondds[0]);
168: assertNotNull(connectionDefinitionDConfigBean);
169: ConnectionDefinitionInstance[] connectionDefinitionInstances = connectionDefinitionDConfigBean.getConnectionDefinitionInstance();
170: connectionDefinitionSetting1 = connectionDefinitionInstances[0].getConfigProperty()[0];
171: assertEquals("TestCDValue1", connectionDefinitionSetting1.getConfigPropertyValue());
172: //connection manager
173: // assertEquals(3000, connectionDefinitionInstances[0].getBlockingTimeout());
174:
175: }
176:
177:
178:
179: protected void setUp() throws Exception {
180: File docDir = new File(basedir, "src/test-data/connector_1_5");
181: j2eeDD = new File(docDir, "ra.xml").toURL();
182: xmlOptions = new XmlOptions();
183: xmlOptions.setLoadLineNumbers();
184: errors = new ArrayList();
185: xmlOptions.setErrorListener(errors);
186: }
187: */
188: }
|