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 org.apache.geronimo.testsupport.TestSupport;
032:
033: import org.apache.geronimo.connector.deployment.dconfigbean.ConfigPropertySettings;
034: import org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionDConfigBean;
035: import org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionInstance;
036: import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
037: import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
038: import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
039: import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
040: import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
041: import org.apache.xmlbeans.XmlOptions;
042:
043: /**
044: *
045: *
046: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
047: *
048: * */
049: public class RAR_1_0DConfigBeanTest extends TestSupport {
050: private URL j2eeDD;
051: XmlOptions xmlOptions;
052: private List errors;
053:
054: public void testNothing() {
055: }
056:
057: public void XtestDConfigBeans() throws Exception {
058: MockRARDeployable deployable = new MockRARDeployable(j2eeDD);
059: DDBeanRoot ddroot = deployable.getDDBeanRoot();
060: DeploymentConfiguration rarConfiguration = new RARConfigurer()
061: .createConfiguration(deployable);
062: DConfigBeanRoot root = rarConfiguration
063: .getDConfigBeanRoot(ddroot);
064: assertNotNull(root);
065:
066: //outbound
067: DDBean[] connectionDefinitiondds = ddroot.getChildBean(root
068: .getXpaths()[0]);
069: assertEquals(1, connectionDefinitiondds.length);
070: ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = (ConnectionDefinitionDConfigBean) root
071: .getDConfigBean(connectionDefinitiondds[0]);
072: assertNotNull(connectionDefinitionDConfigBean);
073: ConnectionDefinitionInstance connectionDefinitionInstance1 = new ConnectionDefinitionInstance();
074: connectionDefinitionDConfigBean
075: .setConnectionDefinitionInstance(new ConnectionDefinitionInstance[] { connectionDefinitionInstance1 });
076: DDBean[] connectionDefinitionConfigPropDDs = connectionDefinitiondds[0]
077: .getChildBean("config-property");
078: assertEquals(4, connectionDefinitionConfigPropDDs.length);
079: ConfigPropertySettings connectionDefinitionSetting1 = connectionDefinitionInstance1
080: .getConfigProperty()[0];
081: connectionDefinitionSetting1
082: .setConfigPropertyValue("TestCDValue1");
083: //connection manager properties
084: // connectionDefinitionInstance1.setBlockingTimeout(3000);
085:
086: //check the results
087: ByteArrayOutputStream baos = new ByteArrayOutputStream();
088: rarConfiguration.save(baos);
089: baos.flush();
090: byte[] bytes = baos.toByteArray();
091: baos.close();
092: InputStream is = new ByteArrayInputStream(bytes);
093: GerConnectorDocument gcDoc = GerConnectorDocument.Factory
094: .parse(is);
095: GerResourceadapterType ra = gcDoc.getConnector()
096: .getResourceadapterArray()[0];
097:
098: //connection definition
099: GerConnectionDefinitionType connectionDefinitionType = ra
100: .getOutboundResourceadapter()
101: .getConnectionDefinitionArray(0);
102: GerConnectiondefinitionInstanceType connectiondefinitionInstanceType = connectionDefinitionType
103: .getConnectiondefinitionInstanceArray(0);
104: assertEquals("TestCDValue1", connectiondefinitionInstanceType
105: .getConfigPropertySettingArray(0).getStringValue());
106: //connection manager
107: GerConnectionmanagerType connectionmanagerType = connectiondefinitionInstanceType
108: .getConnectionmanager();
109: // assertEquals(3000, connectionmanagerType.getBlockingTimeout().intValue());
110:
111: //and read back into dconfigbeans
112: rarConfiguration.restore(new ByteArrayInputStream(bytes));
113:
114: //outbound
115: connectionDefinitionDConfigBean = (ConnectionDefinitionDConfigBean) root
116: .getDConfigBean(connectionDefinitiondds[0]);
117: assertNotNull(connectionDefinitionDConfigBean);
118: ConnectionDefinitionInstance[] connectionDefinitionInstances = connectionDefinitionDConfigBean
119: .getConnectionDefinitionInstance();
120: connectionDefinitionSetting1 = connectionDefinitionInstances[0]
121: .getConfigProperty()[0];
122: assertEquals("TestCDValue1", connectionDefinitionSetting1
123: .getConfigPropertyValue());
124: //connection manager
125: // assertEquals(3000, connectionDefinitionInstances[0].getBlockingTimeout());
126:
127: }
128:
129: protected void XsetUp() throws Exception {
130: File docDir = new File(BASEDIR, "src/test/data/connector_1_0");
131: j2eeDD = new File(docDir, "ra.xml").toURL();
132: xmlOptions = new XmlOptions();
133: xmlOptions.setLoadLineNumbers();
134: errors = new ArrayList();
135: xmlOptions.setErrorListener(errors);
136: }
137:
138: }
|