1 17 18 package org.apache.geronimo.connector.deployment; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.ByteArrayOutputStream ; 22 import java.io.File ; 23 import java.io.InputStream ; 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 import javax.enterprise.deploy.model.DDBean ; 29 import javax.enterprise.deploy.model.DDBeanRoot ; 30 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 31 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 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 51 public class RAR_1_0DConfigBeanTest extends TestSupport { 52 private URL j2eeDD; 53 XmlOptions xmlOptions; 54 private List errors; 55 56 public void testNothing() {} 57 58 public void XtestDConfigBeans() throws Exception { 59 MockRARDeployable deployable = new MockRARDeployable(j2eeDD); 60 DDBeanRoot ddroot = deployable.getDDBeanRoot(); 61 DeploymentConfiguration rarConfiguration = new RARConfigurer().createConfiguration(deployable); 62 DConfigBeanRoot root = rarConfiguration.getDConfigBeanRoot(ddroot); 63 assertNotNull(root); 64 65 DDBean [] 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 [] connectionDefinitionConfigPropDDs = connectionDefinitiondds[0].getChildBean("config-property"); 73 assertEquals(4, connectionDefinitionConfigPropDDs.length); 74 ConfigPropertySettings connectionDefinitionSetting1 = connectionDefinitionInstance1.getConfigProperty()[0]; 75 connectionDefinitionSetting1.setConfigPropertyValue("TestCDValue1"); 76 79 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 81 rarConfiguration.save(baos); 82 baos.flush(); 83 byte[] bytes = baos.toByteArray(); 84 baos.close(); 85 InputStream is = new ByteArrayInputStream (bytes); 86 GerConnectorDocument gcDoc = GerConnectorDocument.Factory.parse(is); 87 GerResourceadapterType ra = gcDoc.getConnector().getResourceadapterArray()[0]; 88 89 GerConnectionDefinitionType connectionDefinitionType = ra.getOutboundResourceadapter().getConnectionDefinitionArray(0); 91 GerConnectiondefinitionInstanceType connectiondefinitionInstanceType = connectionDefinitionType.getConnectiondefinitionInstanceArray(0); 92 assertEquals("TestCDValue1", connectiondefinitionInstanceType.getConfigPropertySettingArray(0).getStringValue()); 93 GerConnectionmanagerType connectionmanagerType = connectiondefinitionInstanceType.getConnectionmanager(); 95 97 rarConfiguration.restore(new ByteArrayInputStream (bytes)); 99 100 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 109 } 110 111 protected void XsetUp() throws Exception { 112 File docDir = new File (BASEDIR, "src/test/data/connector_1_0"); 113 j2eeDD = new File (docDir, "ra.xml").toURL(); 114 xmlOptions = new XmlOptions(); 115 xmlOptions.setLoadLineNumbers(); 116 errors = new ArrayList (); 117 xmlOptions.setErrorListener(errors); 118 } 119 120 } 121 | Popular Tags |