String path = "build" + File.separator + "work" + File.separator +
"test" + File.separator + "wsdl" + File.separator +
"schemaImport" + File.separator + "foo.wsdl";
Document doc = null;
Definition def = null;
// Make sure that the WSDL appears to be valid
try {
doc = XMLUtils.newDocument(path);
assertNotNull("Unable to locate WSDL file: " + path, doc);
WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
def = reader.readWSDL(path, doc);
assertNotNull("unable to generate WSDL definition from document: "
+ path, def);
assertEquals("Expected xmlns:foo to be set to urn:ImportSchemaTest",
"urn:ImportSchemaTest", def.getNamespace("foo"));
} catch (Exception e) {
throw new junit.framework.AssertionFailedError("Exception caught: "
+ e);
}
// Now check that the schema was properly imported. It is assumed
// that WSDL generation is validated in other unit tests. Here, we
// are only interested in the schema importing functionality.
NodeList typeList = doc.getElementsByTagName("wsdl:types");
Node typeNode = typeList.item(0);
assertNotNull("types section of the WSDL document", typeNode);
Element typeElem = (Element) typeNode;
NodeList nodeList = typeElem.getElementsByTagName("xs:complexType");
assertTrue("Could not located imported schema",
nodeList.getLength() > 0);
Element elt = (Element) nodeList.item(0);
assertEquals("Unexpected complexType", "foo", elt.getAttribute("name"));
nodeList = elt.getElementsByTagName("xs:documentation");
assertTrue("Could not find schema documentation",
nodeList.getLength() > 0);