| 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.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 |
/** |
| 36 |
* This class contains the methods necessary for testing that the use inherited methods |
| 37 |
* function in the Java2WSDL tool works as specified. |
| 38 |
* |
| 39 |
* When using the Java2WSDL tool with the use inherited methods switch on, the tool |
| 40 |
* should generate the appropriate classes to include all of the inherited methods |
| 41 |
* of the specified interface (in addition to the actual methods in the interface). |
| 42 |
* |
| 43 |
* @version 1.00 21 Jan 2002 |
| 44 |
* @author Brent Ulbricht |
| 45 |
*/ |
| 46 |
public class InheritanceTestCase extends junit.framework.TestCase { |
| 47 |
|
| 48 |
/** |
| 49 |
* Constructor used in all tests utilizing the Junit Framework. |
| 50 |
*/ |
| 51 |
public InheritanceTestCase(String name) { |
| 52 |
super(name); |
| 53 |
} // Constructor |
| 54 |
|
| 55 |
/** |
| 56 |
* This method insures that two methods (getLastTradePrice and getRealtimeLastTradePrice) |
| 57 |
* can be called, and they return the expected stock values. The main goal is to verify |
| 58 |
* that the getLastTradePrice method does not cause any compile errors and returns the |
| 59 |
* expected stock value. |
| 60 |
* |
| 61 |
* The getLastTradePrice method originates from the test/wsdl/inheritance/StockQuoteProvider |
| 62 |
* interface. The InheritancePortType interface extends the StockQuoteProvider interface. |
| 63 |
* |
| 64 |
* When the WSDL is generated for the InheritancePortType interface and the use inherited |
| 65 |
* methods switch is used, all methods from the StockQuoteProvider and InheritancePortType |
| 66 |
* interfaces should be available for service. |
| 67 |
*/ |
| 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 |
// The getLastTradePrice method should return a value of 20.25 when sent the tickerSymbol |
| 78 |
// "SOAP". |
| 79 |
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 |
// The getRealtimeLastTradePrice method should return a value of 21.75 when sent the |
| 89 |
// tickerSymbol "AXIS". |
| 90 |
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 |
} // testInheritanceTest |
| 100 |
|
| 101 |
/** |
| 102 |
* This test validates the WSDL generated by Java2WSDL |
| 103 |
*/ |
| 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 |
//reader.setFeature("javax.wsdl.verbose", true); |
| 115 |
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 |
// Now check parts of the definition |
| 122 |
|
| 123 |
// types |
| 124 |
// The complex types Baby_bean and Child_bean should exist |
| 125 |
// The type Parent_bean should NOT exist |
| 126 |
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 |
// operations |
| 150 |
// The only ones we shold find are baby_method and child_method |
| 151 |
boolean babyOpFound = false; |
| 152 |
boolean childOpFound = false; |
| 153 |
|
| 154 |
// we iterate the portTypes, but we check to make sure there is only one |
| 155 |
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 |
} // testStopClasses |
| 174 |
|
| 175 |
} // InheritanceTestCase |
| 176 |
|