1 16 17 package test.wsdl.inheritance; 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.Operation; 27 import javax.wsdl.PortType; 28 import javax.wsdl.factory.WSDLFactory; 29 import javax.wsdl.xml.WSDLReader; 30 import javax.xml.rpc.ServiceException ; 31 import java.io.File ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 35 46 public class InheritanceTestCase extends junit.framework.TestCase { 47 48 51 public InheritanceTestCase(String name) { 52 super(name); 53 } 55 68 public void testInheritanceTest() { 69 test.wsdl.inheritance.InheritancePortType binding; 70 try { 71 binding = new InheritancePortTypeServiceLocator().getInheritanceTest(); 72 } catch (ServiceException jre) { 73 throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 74 } 75 assertTrue("binding is null", binding != null); 76 77 try { 80 float expected = 20.25F; 81 float actual = binding.getLastTradePrice(new java.lang.String ("SOAP")); 82 float delta = 0.0F; 83 assertEquals("The actual and expected values did not match.", expected, actual, delta); 84 } catch (java.rmi.RemoteException re) { 85 throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re); 86 } 87 88 try { 91 float expected = 21.75F; 92 float actual = binding.getRealtimeLastTradePrice(new java.lang.String ("AXIS")); 93 float delta = 0.0F; 94 assertEquals("The actual and expected values did not match.", expected, actual, delta); 95 } catch (java.rmi.RemoteException re) { 96 throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re); 97 } 98 99 } 101 104 public void testStopClasses() { 105 String path = "build" + File.separator + "work" + File.separator + 106 "test" + File.separator + "wsdl" + File.separator + 107 "inheritance" + File.separator + "StopExclude.wsdl"; 108 Document doc = null; 109 Definition def = null; 110 try { 111 doc = XMLUtils.newDocument(path); 112 assertNotNull("Unable to locate WSDL file: " + path, doc); 113 WSDLReader reader = WSDLFactory.newInstance().newWSDLReader(); 114 def = reader.readWSDL(path, doc); 116 assertNotNull("unable to generate WSDL definition from document: " + path, def); 117 } catch (Exception e) { 118 throw new junit.framework.AssertionFailedError("Exception caught: " + e); 119 } 120 121 123 NodeList typeList = doc.getElementsByTagName("wsdl:types"); 127 Node typeNode = typeList.item(0); 128 assertNotNull("types section of the WSDL document", typeNode); 129 Element typeElem = (Element ) typeNode; 130 131 boolean babyFound = false; 132 boolean childFound = false; 133 NodeList nodeList = typeElem.getElementsByTagName("complexType"); 134 for (int i = 0; i < nodeList.getLength(); i++) { 135 Node n = nodeList.item(i); 136 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue(); 137 if (name.equals("Baby_bean")) 138 babyFound = true; 139 else if (name.equals("Child_bean")) 140 childFound = true; 141 else if (name.equals("Parent_bean")) 142 assertTrue("Parent_bean found in WSDL types section", false); 143 else 144 assertTrue("Unknown node found in types section: " + name, false); 145 } 146 assertTrue("Baby_bean not found in WSDL types section", babyFound); 147 assertTrue("Child_bean not found in WSDL types section", childFound); 148 149 boolean babyOpFound = false; 152 boolean childOpFound = false; 153 154 Iterator ip = def.getPortTypes().values().iterator(); 156 PortType portType = (PortType) ip.next(); 157 List operationList = portType.getOperations(); 158 for (int i = 0; i < operationList.size(); ++i) { 159 String opName = ((Operation) operationList.get(i)).getName(); 160 if (opName.equals("baby_method")) 161 babyOpFound = true; 162 else if (opName.equals("child_method")) 163 childOpFound = true; 164 else if (opName.equals("parent_method")) 165 assertTrue("parent_method operation found in WSDL", false); 166 else 167 assertTrue("Invalid operation found in WSDL: " + opName, false); 168 } 169 assertTrue("WSDL has more than one portType", !ip.hasNext()); 170 assertTrue("baby_method operation not found in WSDL", babyOpFound); 171 assertTrue("child_method operation not found in WSDL ", childOpFound); 172 173 } 175 } 177 | Popular Tags |