1 17 package org.apache.geronimo.connector.deployment; 18 19 import java.net.URL ; 20 21 import javax.xml.namespace.QName ; 22 23 import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil; 24 import org.apache.geronimo.schema.SchemaConversionUtils; 25 import org.apache.geronimo.testsupport.TestSupport; 26 import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument; 27 import org.apache.geronimo.xbeans.geronimo.GerConnectorType; 28 import org.apache.geronimo.xbeans.j2ee.ConnectorDocument; 29 import org.apache.xmlbeans.XmlException; 30 import org.apache.xmlbeans.XmlObject; 31 32 34 public class PlanParsingTest extends TestSupport { 35 private final static QName CONNECTOR_QNAME = GerConnectorDocument.type.getDocumentElementName(); 36 private ClassLoader classLoader = this.getClass().getClassLoader(); 37 38 public void testLoadGeronimoDeploymentDescriptor10() throws Exception { 39 URL srcXml = classLoader.getResource("connector_1_0/geronimo-ra.xml"); 40 XmlObject plan = XmlBeansUtil.parse(srcXml, getClass().getClassLoader()); 41 GerConnectorDocument connectorDocument = (GerConnectorDocument) plan.changeType(GerConnectorDocument.type); 42 GerConnectorType connector = (GerConnectorType) SchemaConversionUtils.fixGeronimoSchema(connectorDocument, CONNECTOR_QNAME, GerConnectorType.type); 43 XmlBeansUtil.validateDD(connector); 44 assertEquals(1, connectorDocument.getConnector().getResourceadapterArray().length); 45 } 46 47 public void testLoadJ2eeDeploymentDescriptor() throws Exception { 48 URL srcXml = classLoader.getResource("connector_1_5/ra.xml"); 49 XmlObject plan = XmlBeansUtil.parse(srcXml, getClass().getClassLoader()); 50 ConnectorDocument connectorDocument = (ConnectorDocument) plan.changeType(ConnectorDocument.type); 51 assertNotNull(connectorDocument.getConnector().getResourceadapter()); 52 XmlBeansUtil.validateDD(connectorDocument); 53 } 54 55 public void testLoadGeronimoDeploymentDescriptor15() throws Exception { 56 URL srcXml = classLoader.getResource("connector_1_5/geronimo-ra.xml"); 57 XmlObject plan = XmlBeansUtil.parse(srcXml, getClass().getClassLoader()); 58 GerConnectorDocument connectorDocument = (GerConnectorDocument) plan.changeType(GerConnectorDocument.type); 59 GerConnectorType connector = (GerConnectorType) SchemaConversionUtils.fixGeronimoSchema(connectorDocument, CONNECTOR_QNAME, GerConnectorType.type); 60 assertEquals(1, connector.getResourceadapterArray().length); 61 } 62 63 public void testResourceAdapterNameUniqueness() throws Exception { 64 URL srcXml = classLoader.getResource("data/dup-resourceadapter-name.xml"); 65 XmlObject plan = XmlBeansUtil.parse(srcXml, getClass().getClassLoader()); 66 GerConnectorDocument doc = (GerConnectorDocument) plan.changeType(GerConnectorDocument.type); 67 if (doc == null) { 68 doc = (GerConnectorDocument) plan; 69 } 70 try { 71 XmlBeansUtil.validateDD(doc); 72 fail("dup resource adapter name is invalid"); 73 } catch (XmlException e) { 74 } 76 } 77 78 public void testConnectionFactoryNameUniqueness() throws Exception { 79 URL srcXml = classLoader.getResource("data/dup-connectionfactoryinstance-name.xml"); 80 XmlObject plan = XmlBeansUtil.parse(srcXml, getClass().getClassLoader()); 81 GerConnectorDocument doc = (GerConnectorDocument) plan.changeType(GerConnectorDocument.type); 82 if (doc == null) { 83 doc = (GerConnectorDocument) plan; 84 } 85 try { 86 XmlBeansUtil.validateDD(doc); 87 fail("dup connection factory name is invalid"); 88 } catch (XmlException e) { 89 } 91 } 92 93 public void testAdminObjectNameUniqueness() throws Exception { 94 URL srcXml = classLoader.getResource("data/dup-admin-object-name.xml"); 95 XmlObject plan = XmlBeansUtil.parse(srcXml, getClass().getClassLoader()); 96 GerConnectorDocument doc = (GerConnectorDocument) plan.changeType(GerConnectorDocument.type); 97 if (doc == null) { 98 doc = (GerConnectorDocument) plan; 99 } 100 try { 101 XmlBeansUtil.validateDD(doc); 102 fail("dup admin object name is invalid"); 103 } catch (XmlException e) { 104 } 106 } 107 108 public void testRectifyPlan() throws Exception { 109 URL srcXml = classLoader.getResource("data/old-schema-plan.xml"); 110 XmlObject plan = XmlBeansUtil.parse(srcXml, getClass().getClassLoader()); 111 GerConnectorDocument doc = (GerConnectorDocument) plan.changeType(GerConnectorDocument.type); 112 if (doc == null) { 113 doc = (GerConnectorDocument) plan; 114 } 115 GerConnectorType gerConnector = doc.getConnector(); 116 ConnectorPlanRectifier.rectifyPlan(gerConnector); 117 gerConnector = (GerConnectorType) SchemaConversionUtils.fixGeronimoSchema(gerConnector, CONNECTOR_QNAME, GerConnectorType.type); 118 } 119 } 120 | Popular Tags |