1 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 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 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 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 | Popular Tags |