KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.geronimo.connector.deployment;
18
19 import java.net.URL JavaDoc;
20
21 import javax.xml.namespace.QName JavaDoc;
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 /**
33  */

34 public class PlanParsingTest extends TestSupport {
35     private final static QName JavaDoc CONNECTOR_QNAME = GerConnectorDocument.type.getDocumentElementName();
36     private ClassLoader JavaDoc classLoader = this.getClass().getClassLoader();
37
38     public void testLoadGeronimoDeploymentDescriptor10() throws Exception JavaDoc {
39         URL JavaDoc 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 JavaDoc {
48         URL JavaDoc 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 JavaDoc {
56         URL JavaDoc 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 JavaDoc {
64         URL JavaDoc 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             //expected
75
}
76     }
77
78     public void testConnectionFactoryNameUniqueness() throws Exception JavaDoc {
79         URL JavaDoc 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             //expected
90
}
91     }
92
93     public void testAdminObjectNameUniqueness() throws Exception JavaDoc {
94         URL JavaDoc 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             //expected
105
}
106     }
107
108     public void testRectifyPlan() throws Exception JavaDoc {
109         URL JavaDoc 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