KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.geronimo.testsupport.TestSupport;
34
35 import org.apache.geronimo.connector.deployment.dconfigbean.ConfigPropertySettings;
36 import org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionDConfigBean;
37 import org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionInstance;
38 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
39 import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
40 import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
41 import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
42 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
43 import org.apache.xmlbeans.XmlOptions;
44
45 /**
46  *
47  *
48  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
49  *
50  * */

51 public class RAR_1_0DConfigBeanTest extends TestSupport {
52     private URL JavaDoc j2eeDD;
53     XmlOptions xmlOptions;
54     private List JavaDoc errors;
55
56     public void testNothing() {}
57
58     public void XtestDConfigBeans() throws Exception JavaDoc {
59         MockRARDeployable deployable = new MockRARDeployable(j2eeDD);
60         DDBeanRoot JavaDoc ddroot = deployable.getDDBeanRoot();
61         DeploymentConfiguration JavaDoc rarConfiguration = new RARConfigurer().createConfiguration(deployable);
62         DConfigBeanRoot JavaDoc root = rarConfiguration.getDConfigBeanRoot(ddroot);
63         assertNotNull(root);
64
65         //outbound
66
DDBean JavaDoc[] connectionDefinitiondds = ddroot.getChildBean(root.getXpaths()[0]);
67         assertEquals(1, connectionDefinitiondds.length);
68         ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = (ConnectionDefinitionDConfigBean)root.getDConfigBean(connectionDefinitiondds[0]);
69         assertNotNull(connectionDefinitionDConfigBean);
70         ConnectionDefinitionInstance connectionDefinitionInstance1 = new ConnectionDefinitionInstance();
71         connectionDefinitionDConfigBean.setConnectionDefinitionInstance(new ConnectionDefinitionInstance[] {connectionDefinitionInstance1});
72         DDBean JavaDoc[] connectionDefinitionConfigPropDDs = connectionDefinitiondds[0].getChildBean("config-property");
73         assertEquals(4, connectionDefinitionConfigPropDDs.length);
74         ConfigPropertySettings connectionDefinitionSetting1 = connectionDefinitionInstance1.getConfigProperty()[0];
75         connectionDefinitionSetting1.setConfigPropertyValue("TestCDValue1");
76         //connection manager properties
77
// connectionDefinitionInstance1.setBlockingTimeout(3000);
78

79         //check the results
80
ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
81         rarConfiguration.save(baos);
82         baos.flush();
83         byte[] bytes = baos.toByteArray();
84         baos.close();
85         InputStream JavaDoc is = new ByteArrayInputStream JavaDoc(bytes);
86         GerConnectorDocument gcDoc = GerConnectorDocument.Factory.parse(is);
87         GerResourceadapterType ra = gcDoc.getConnector().getResourceadapterArray()[0];
88
89         //connection definition
90
GerConnectionDefinitionType connectionDefinitionType = ra.getOutboundResourceadapter().getConnectionDefinitionArray(0);
91         GerConnectiondefinitionInstanceType connectiondefinitionInstanceType = connectionDefinitionType.getConnectiondefinitionInstanceArray(0);
92         assertEquals("TestCDValue1", connectiondefinitionInstanceType.getConfigPropertySettingArray(0).getStringValue());
93         //connection manager
94
GerConnectionmanagerType connectionmanagerType = connectiondefinitionInstanceType.getConnectionmanager();
95 // assertEquals(3000, connectionmanagerType.getBlockingTimeout().intValue());
96

97         //and read back into dconfigbeans
98
rarConfiguration.restore(new ByteArrayInputStream JavaDoc(bytes));
99
100         //outbound
101
connectionDefinitionDConfigBean = (ConnectionDefinitionDConfigBean)root.getDConfigBean(connectionDefinitiondds[0]);
102         assertNotNull(connectionDefinitionDConfigBean);
103         ConnectionDefinitionInstance[] connectionDefinitionInstances = connectionDefinitionDConfigBean.getConnectionDefinitionInstance();
104         connectionDefinitionSetting1 = connectionDefinitionInstances[0].getConfigProperty()[0];
105         assertEquals("TestCDValue1", connectionDefinitionSetting1.getConfigPropertyValue());
106         //connection manager
107
// assertEquals(3000, connectionDefinitionInstances[0].getBlockingTimeout());
108

109     }
110
111     protected void XsetUp() throws Exception JavaDoc {
112         File JavaDoc docDir = new File JavaDoc(BASEDIR, "src/test/data/connector_1_0");
113         j2eeDD = new File JavaDoc(docDir, "ra.xml").toURL();
114         xmlOptions = new XmlOptions();
115         xmlOptions.setLoadLineNumbers();
116         errors = new ArrayList JavaDoc();
117         xmlOptions.setErrorListener(errors);
118     }
119
120 }
121
Popular Tags