butek 02/02/04 08:25:11
Modified: java/src/org/apache/axis/wsdl/toJava JavaTestCaseWriter.java
Log:
The generated test cases now have one operation per method. The old one put
all operations in a single method. So if one operation failed, the test stopped.
Now
all operations are run and the report tells us how many fail.
Revision Changes Path
1.14 +41 -44
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaTestCaseWriter.java
Index: JavaTestCaseWriter.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaTestCaseWriter.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- JavaTestCaseWriter.java 1 Feb 2002 18:04:08 -0000 1.13
+++ JavaTestCaseWriter.java 4 Feb 2002 16:25:11 -0000 1.14
@@ -128,9 +128,12 @@
}
String portName = Utils.xmlNameToJavaClass(p.getName());
+ PortType portType = binding.getPortType();
+ PortTypeEntry ptEntry =
+ symbolTable.getPortTypeEntry(portType.getQName());
writeComment(pw, p.getDocumentationElement());
- writeServiceTestCode(portName, binding, bEntry);
+ writeServiceTestCode(portName, portType, ptEntry, binding, bEntry);
}
finish();
} // writeFileBody
@@ -142,47 +145,10 @@
pw.close();
} // finish
- public final void writeServiceTestCode(
- String portName, Binding binding, BindingEntry bEntry)
- throws IOException {
- PortType portType = binding.getPortType();
- PortTypeEntry ptEntry =
- symbolTable.getPortTypeEntry(portType.getQName());
-
- // If there is not literal use, the interface name is the portType name.
- // Otherwise it is the binding name.
- String bindingType = bEntry.hasLiteral() ?
- bEntry.getName() : ptEntry.getName();
-
- pw.println();
- pw.println(" public void test" + portName + "() {");
- pw.print(" ");
- pw.print(bindingType);
- pw.println(" binding;");
- pw.println(" try {");
- pw.print(" binding = new ");
- pw.print(this.className.substring(0, this.className.length() -
"TestCase".length()));
- pw.print("().get");
- pw.print(portName);
- pw.println("();");
- pw.println(" }");
- pw.println(" catch (javax.xml.rpc.JAXRPCException jre) {");
- pw.print(" ");
- pw.println("throw new junit.framework.AssertionFailedError(\"JAX-RPC
Exception caught: \" + jre);");
- pw.println(" }");
-
- pw.println(" assertTrue(\"" +
- JavaUtils.getMessage("null00", "binding") +
- "\", binding != null);");
-
- this.writePortTestCode(portType, bEntry);
-
- pw.println(" }");
- } // writeServiceTestCode
-
- private final void writePortTestCode(PortType port, BindingEntry bEntry) throws
IOException {
- PortTypeEntry ptEntry = symbolTable.getPortTypeEntry(port.getQName());
- Iterator ops = port.getOperations().iterator();
+ private final void writeServiceTestCode(
+ String portName, PortType portType, PortTypeEntry ptEntry,
+ Binding binding, BindingEntry bEntry) throws IOException {
+ Iterator ops = portType.getOperations().iterator();
while (ops.hasNext()) {
Operation op = (Operation) ops.next();
OperationType type = op.getStyle();
@@ -196,6 +162,16 @@
continue;
}
+ String javaOpName = Utils.xmlNameToJavaClass(op.getName());
+ String testMethodName = "test" + portName + javaOpName;
+ pw.println(" public void " + testMethodName + "() {");
+
+ // If there is not literal use, the interface name is the portType name.
+ // Otherwise it is the binding name.
+ String bindingType = bEntry.hasLiteral() ?
+ bEntry.getName() : ptEntry.getName();
+ writeBindingAssignment(bindingType, portName);
+
pw.println(" try {");
if (params.returnType != null) {
pw.print(" ");
@@ -313,7 +289,7 @@
while (i.hasNext()) {
count++;
Fault f = (Fault) i.next();
- String namespace = port.getQName().getNamespaceURI();
+ String namespace = portType.getQName().getNamespaceURI();
pw.print(" catch (");
pw.print(Utils.getFullExceptionName(
f, symbolTable, namespace));
@@ -327,7 +303,28 @@
pw.print(" ");
pw.println("throw new junit.framework.AssertionFailedError(\"Remote
Exception caught: \" + re);");
pw.println(" }");
+ pw.println(" }");
+ pw.println();
}
- } // writePortTestCode
+ } // writeServiceTestCode
+
+ public final void writeBindingAssignment(
+ String bindingType, String portName) throws IOException {
+ pw.println(" " + bindingType + " binding;");
+ pw.println(" try {");
+ pw.print(" binding = new ");
+ pw.print(this.className.substring(
+ 0, this.className.length() - "TestCase".length()));
+ pw.println("().get" + portName + "();");
+ pw.println(" }");
+ pw.println(" catch (javax.xml.rpc.JAXRPCException jre) {");
+ pw.println(" throw new
junit.framework.AssertionFailedError(\"JAX-RPC Exception caught: \" + jre);");
+ pw.println(" }");
+
+ pw.println(" assertTrue(\"" +
+ JavaUtils.getMessage("null00", "binding") +
+ "\", binding != null);");
+ pw.println();
+ } // writeBindingAssignment
} // class JavaTestCasepw