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.net.URL;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
023: import org.apache.geronimo.schema.SchemaConversionUtils;
024: import org.apache.geronimo.testsupport.TestSupport;
025: import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
026: import org.apache.geronimo.xbeans.geronimo.GerConnectorType;
027: import org.apache.geronimo.xbeans.j2ee.ConnectorDocument;
028: import org.apache.xmlbeans.XmlException;
029: import org.apache.xmlbeans.XmlObject;
030:
031: /**
032: */
033: public class PlanParsingTest extends TestSupport {
034: private final static QName CONNECTOR_QNAME = GerConnectorDocument.type
035: .getDocumentElementName();
036: private ClassLoader classLoader = this .getClass().getClassLoader();
037:
038: public void testLoadGeronimoDeploymentDescriptor10()
039: throws Exception {
040: URL srcXml = classLoader
041: .getResource("connector_1_0/geronimo-ra.xml");
042: XmlObject plan = XmlBeansUtil.parse(srcXml, getClass()
043: .getClassLoader());
044: GerConnectorDocument connectorDocument = (GerConnectorDocument) plan
045: .changeType(GerConnectorDocument.type);
046: GerConnectorType connector = (GerConnectorType) SchemaConversionUtils
047: .fixGeronimoSchema(connectorDocument, CONNECTOR_QNAME,
048: GerConnectorType.type);
049: XmlBeansUtil.validateDD(connector);
050: assertEquals(1, connectorDocument.getConnector()
051: .getResourceadapterArray().length);
052: }
053:
054: public void testLoadJ2eeDeploymentDescriptor() throws Exception {
055: URL srcXml = classLoader.getResource("connector_1_5/ra.xml");
056: XmlObject plan = XmlBeansUtil.parse(srcXml, getClass()
057: .getClassLoader());
058: ConnectorDocument connectorDocument = (ConnectorDocument) plan
059: .changeType(ConnectorDocument.type);
060: assertNotNull(connectorDocument.getConnector()
061: .getResourceadapter());
062: XmlBeansUtil.validateDD(connectorDocument);
063: }
064:
065: public void testLoadGeronimoDeploymentDescriptor15()
066: throws Exception {
067: URL srcXml = classLoader
068: .getResource("connector_1_5/geronimo-ra.xml");
069: XmlObject plan = XmlBeansUtil.parse(srcXml, getClass()
070: .getClassLoader());
071: GerConnectorDocument connectorDocument = (GerConnectorDocument) plan
072: .changeType(GerConnectorDocument.type);
073: GerConnectorType connector = (GerConnectorType) SchemaConversionUtils
074: .fixGeronimoSchema(connectorDocument, CONNECTOR_QNAME,
075: GerConnectorType.type);
076: assertEquals(1, connector.getResourceadapterArray().length);
077: }
078:
079: public void testResourceAdapterNameUniqueness() throws Exception {
080: URL srcXml = classLoader
081: .getResource("data/dup-resourceadapter-name.xml");
082: XmlObject plan = XmlBeansUtil.parse(srcXml, getClass()
083: .getClassLoader());
084: GerConnectorDocument doc = (GerConnectorDocument) plan
085: .changeType(GerConnectorDocument.type);
086: if (doc == null) {
087: doc = (GerConnectorDocument) plan;
088: }
089: try {
090: XmlBeansUtil.validateDD(doc);
091: fail("dup resource adapter name is invalid");
092: } catch (XmlException e) {
093: //expected
094: }
095: }
096:
097: public void testConnectionFactoryNameUniqueness() throws Exception {
098: URL srcXml = classLoader
099: .getResource("data/dup-connectionfactoryinstance-name.xml");
100: XmlObject plan = XmlBeansUtil.parse(srcXml, getClass()
101: .getClassLoader());
102: GerConnectorDocument doc = (GerConnectorDocument) plan
103: .changeType(GerConnectorDocument.type);
104: if (doc == null) {
105: doc = (GerConnectorDocument) plan;
106: }
107: try {
108: XmlBeansUtil.validateDD(doc);
109: fail("dup connection factory name is invalid");
110: } catch (XmlException e) {
111: //expected
112: }
113: }
114:
115: public void testAdminObjectNameUniqueness() throws Exception {
116: URL srcXml = classLoader
117: .getResource("data/dup-admin-object-name.xml");
118: XmlObject plan = XmlBeansUtil.parse(srcXml, getClass()
119: .getClassLoader());
120: GerConnectorDocument doc = (GerConnectorDocument) plan
121: .changeType(GerConnectorDocument.type);
122: if (doc == null) {
123: doc = (GerConnectorDocument) plan;
124: }
125: try {
126: XmlBeansUtil.validateDD(doc);
127: fail("dup admin object name is invalid");
128: } catch (XmlException e) {
129: //expected
130: }
131: }
132:
133: public void testRectifyPlan() throws Exception {
134: URL srcXml = classLoader
135: .getResource("data/old-schema-plan.xml");
136: XmlObject plan = XmlBeansUtil.parse(srcXml, getClass()
137: .getClassLoader());
138: GerConnectorDocument doc = (GerConnectorDocument) plan
139: .changeType(GerConnectorDocument.type);
140: if (doc == null) {
141: doc = (GerConnectorDocument) plan;
142: }
143: GerConnectorType gerConnector = doc.getConnector();
144: ConnectorPlanRectifier.rectifyPlan(gerConnector);
145: gerConnector = (GerConnectorType) SchemaConversionUtils
146: .fixGeronimoSchema(gerConnector, CONNECTOR_QNAME,
147: GerConnectorType.type);
148: }
149: }
|