Debian Codegraph @

test/wsdl/schemaImport/SchemaImportTestCase.java

raw
1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package test.wsdl.schemaImport;
18
19 import org.apache.axis.utils.XMLUtils;
20 import org.w3c.dom.Document;
21 import org.w3c.dom.Element;
22 import org.w3c.dom.Node;
23 import org.w3c.dom.NodeList;
24
25 import javax.wsdl.Definition;
26 import javax.wsdl.factory.WSDLFactory;
27 import javax.wsdl.xml.WSDLReader;
28 import java.io.File;
29
30 /**
31 * This class contains the methods necessary for testing that the XML Schema
32 * import support is functional within WSDL2Java. This test will generate a
33 * WSDL file and then validate that the schema has been appropriate imported
34 * into said WSDL.
35 *
36 * @version 1.00 01 Nov 2002
37 * @author Doug Bitting ([email protected])
38 */
39 public class SchemaImportTestCase extends junit.framework.TestCase {
40 public SchemaImportTestCase(String name) {
41 super(name);
42 }
43
44 public void testSchemaImport() {
45 String path = "build" + File.separator + "work" + File.separator +
46 "test" + File.separator + "wsdl" + File.separator +
47 "schemaImport" + File.separator + "foo.wsdl";
48 Document doc = null;
49 Definition def = null;
50
51 // Make sure that the WSDL appears to be valid
52 try {
53 doc = XMLUtils.newDocument(path);
54 assertNotNull("Unable to locate WSDL file: " + path, doc);
55 WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
56 def = reader.readWSDL(path, doc);
57 assertNotNull("unable to generate WSDL definition from document: "
58 + path, def);
59 assertEquals("Expected xmlns:foo to be set to urn:ImportSchemaTest",
60 "urn:ImportSchemaTest", def.getNamespace("foo"));
61 } catch (Exception e) {
62 throw new junit.framework.AssertionFailedError("Exception caught: "
63 + e);
64 }
65
66 // Now check that the schema was properly imported. It is assumed
67 // that WSDL generation is validated in other unit tests. Here, we
68 // are only interested in the schema importing functionality.
69 NodeList typeList = doc.getElementsByTagName("wsdl:types");
70 Node typeNode = typeList.item(0);
71 assertNotNull("types section of the WSDL document", typeNode);
72 Element typeElem = (Element) typeNode;
73
74 NodeList nodeList = typeElem.getElementsByTagName("xs:complexType");
75 assertTrue("Could not located imported schema",
76 nodeList.getLength() > 0);
77 Element elt = (Element) nodeList.item(0);
78 assertEquals("Unexpected complexType", "foo", elt.getAttribute("name"));
79 nodeList = elt.getElementsByTagName("xs:documentation");
80 assertTrue("Could not find schema documentation",
81 nodeList.getLength() > 0);
82 }
83 }
84 // End of SchemaImportTestCase.java