Return-Path: Delivered-To: apmail-xml-axis-dev-archive@xml.apache.org Received: (qmail 1133 invoked by uid 500); 16 Oct 2001 18:58:51 -0000 Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@xml.apache.org Received: (qmail 1117 invoked by uid 500); 16 Oct 2001 18:58:51 -0000 Delivered-To: apmail-xml-axis-cvs@apache.org Date: 16 Oct 2001 18:52:55 -0000 Message-ID: <20011016185255.38748.qmail@icarus.apache.org> From: tomj@apache.org To: xml-axis-cvs@apache.org Subject: cvs commit: xml-axis/java/src/org/apache/axis/wsdl TestCaseEmitter.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N tomj 01/10/16 11:52:55 Modified: java/src/org/apache/axis/wsdl TestCaseEmitter.java Log: Remove extra \r chars at end of lines. Minor change to print exceptions. Revision Changes Path 1.5 +177 -177 xml-axis/java/src/org/apache/axis/wsdl/TestCaseEmitter.java Index: TestCaseEmitter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/TestCaseEmitter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- TestCaseEmitter.java 2001/10/16 15:42:34 1.4 +++ TestCaseEmitter.java 2001/10/16 18:52:55 1.5 @@ -51,135 +51,135 @@ * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . - */ -package org.apache.axis.wsdl; - -import javax.wsdl.Binding; -import javax.wsdl.Operation; -import javax.wsdl.PortType; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Iterator; - + */ +package org.apache.axis.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Iterator; + /** * Generate the TestCase code for use in testing services derived from the * generated stubs. * * @author Berin Loritsch - * @version CVS $Revision: 1.4 $ $Date: 2001/10/16 15:42:34 $ - */ - -public class TestCaseEmitter { - private final static int IMPORTS = 1; - private final static int HEADER = 2; - private final static int TESTS = 3; - private final static int DONE = 4; - - private final static String INDENT = " "; - - private final PrintWriter writer; - private final String className; - private final String packageName; - private final Emitter emitter; - private int state = IMPORTS; - - public TestCaseEmitter(PrintWriter testCase, String packageName, String className, Emitter emit) { - this.emitter = emit; - this.writer = testCase; - this.className = className; - if (packageName == null) { - this.packageName = null; - } else { - this.packageName = packageName; - } - this.initFile(); - } - - private final void initFile() { - if (this.packageName != null) { - writer.print("package "); - writer.print(this.packageName); - writer.println(";"); - } - - writer.println(); - } - - public final void writeHeader(String filename) { - if (this.state > IMPORTS) { - throw new IllegalStateException("You cannot write the header now!"); - } - - this.state = HEADER; - writer.println("/**"); - writer.print(" * "); - writer.println(filename); - writer.println(" *"); - writer.println(" * This file was auto-generated from WSDL"); - writer.println(" * by the Apache Axis Wsdl2java emitter."); - writer.println(" */"); - writer.print("public class "); - writer.print(this.className); - writer.println(" extends junit.framework.TestCase {"); - - writer.print(" public "); - writer.print(this.className); - writer.println("(String name) {"); - writer.println(" super(name);"); - writer.println(" }"); - } - - public final void finish() { - this.state = DONE; - writer.println("}"); - writer.println(); - writer.flush(); - writer.close(); - } - + * @version CVS $Revision: 1.5 $ $Date: 2001/10/16 18:52:55 $ + */ + +public class TestCaseEmitter { + private final static int IMPORTS = 1; + private final static int HEADER = 2; + private final static int TESTS = 3; + private final static int DONE = 4; + + private final static String INDENT = " "; + + private final PrintWriter writer; + private final String className; + private final String packageName; + private final Emitter emitter; + private int state = IMPORTS; + + public TestCaseEmitter(PrintWriter testCase, String packageName, String className, Emitter emit) { + this.emitter = emit; + this.writer = testCase; + this.className = className; + if (packageName == null) { + this.packageName = null; + } else { + this.packageName = packageName; + } + this.initFile(); + } + + private final void initFile() { + if (this.packageName != null) { + writer.print("package "); + writer.print(this.packageName); + writer.println(";"); + } + + writer.println(); + } + + public final void writeHeader(String filename) { + if (this.state > IMPORTS) { + throw new IllegalStateException("You cannot write the header now!"); + } + + this.state = HEADER; + writer.println("/**"); + writer.print(" * "); + writer.println(filename); + writer.println(" *"); + writer.println(" * This file was auto-generated from WSDL"); + writer.println(" * by the Apache Axis Wsdl2java emitter."); + writer.println(" */"); + writer.print("public class "); + writer.print(this.className); + writer.println(" extends junit.framework.TestCase {"); + + writer.print(" public "); + writer.print(this.className); + writer.println("(String name) {"); + writer.println(" super(name);"); + writer.println(" }"); + } + + public final void finish() { + this.state = DONE; + writer.println("}"); + writer.println(); + writer.flush(); + writer.close(); + } + /** * Generate setUp()/tearDown() code for the TestCase - */ - public final void writeInitCode() throws IOException { - if (this.state == DONE) { - throw new IllegalStateException("The test case is already done!"); - } - - this.state = TESTS; - } - - public final void writeServiceTestCode(String portName, Binding binding) throws IOException { - if (this.state > TESTS) { - throw new IllegalStateException("You may not write any more tests!"); - } - - this.state = TESTS; - PortType portType = binding.getPortType(); - String bindingType = portType.getQName().getLocalPart(); - - writer.println(); - writer.println(" public void test" + portName + "() {"); - writer.print(" "); - writer.print(bindingType); - writer.print(" binding = new "); - writer.print(this.className.substring(0, this.className.length() - "TestCase".length())); - writer.print("().get"); - writer.print(portName); - writer.println("();"); - - writer.println(" assertTrue(binding != null);"); - - this.writePortTestCode(portType); - - writer.println(" }"); - } - - private final void writePortTestCode(PortType port) throws IOException { - Iterator ops = port.getOperations().iterator(); - - while (ops.hasNext()) { - writer.println(" try {"); - Operation op = (Operation) ops.next(); + */ + public final void writeInitCode() throws IOException { + if (this.state == DONE) { + throw new IllegalStateException("The test case is already done!"); + } + + this.state = TESTS; + } + + public final void writeServiceTestCode(String portName, Binding binding) throws IOException { + if (this.state > TESTS) { + throw new IllegalStateException("You may not write any more tests!"); + } + + this.state = TESTS; + PortType portType = binding.getPortType(); + String bindingType = portType.getQName().getLocalPart(); + + writer.println(); + writer.println(" public void test" + portName + "() {"); + writer.print(" "); + writer.print(bindingType); + writer.print(" binding = new "); + writer.print(this.className.substring(0, this.className.length() - "TestCase".length())); + writer.print("().get"); + writer.print(portName); + writer.println("();"); + + writer.println(" assertTrue(binding != null);"); + + this.writePortTestCode(portType); + + writer.println(" }"); + } + + private final void writePortTestCode(PortType port) throws IOException { + Iterator ops = port.getOperations().iterator(); + + while (ops.hasNext()) { + writer.println(" try {"); + Operation op = (Operation) ops.next(); Emitter.Parameters params = this.emitter.parameters(op); if ( !"void".equals( params.returnType ) ) { @@ -197,45 +197,45 @@ writer.println("null;"); } } - - writer.print(INDENT); - - if ( !"void".equals(params.returnType) ) { - writer.print("value = "); - } - - writer.print("binding."); - writer.print(op.getName()); - writer.print("("); - - Iterator iparam = params.list.iterator(); - boolean isFirst = true; - - while (iparam.hasNext()) { - if (isFirst) { - isFirst = false; - } else { - writer.print(", "); - } - - Emitter.Parameter param = (Emitter.Parameter) iparam.next(); - String paramType = param.type; - if ( this.emitter.isPrimitiveType(paramType) ) { - if ( "boolean".equals(paramType) ) { - writer.print("true"); - } else { - writer.print("0"); - } - } else { - writer.print("new "); - writer.print(param.type); - writer.print("()"); - } - } - - writer.println(");"); - - if ( !"void".equals(params.returnType) ) { + + writer.print(INDENT); + + if ( !"void".equals(params.returnType) ) { + writer.print("value = "); + } + + writer.print("binding."); + writer.print(op.getName()); + writer.print("("); + + Iterator iparam = params.list.iterator(); + boolean isFirst = true; + + while (iparam.hasNext()) { + if (isFirst) { + isFirst = false; + } else { + writer.print(", "); + } + + Emitter.Parameter param = (Emitter.Parameter) iparam.next(); + String paramType = param.type; + if ( this.emitter.isPrimitiveType(paramType) ) { + if ( "boolean".equals(paramType) ) { + writer.print("true"); + } else { + writer.print("0"); + } + } else { + writer.print("new "); + writer.print(param.type); + writer.print("()"); + } + } + + writer.println(");"); + + if ( !"void".equals(params.returnType) ) { writer.print(INDENT); if ( this.emitter.isPrimitiveType( params.returnType ) ) { @@ -244,22 +244,22 @@ } else { writer.println("assertTrue(value != -3);"); } - } else { + } else { writer.println("assertTrue(value != null);"); - } - } - - writer.println(" } catch (java.rmi.RemoteException re) {"); - writer.print(INDENT); - writer.println("throw new junit.framework.AssertionFailedError(\"Remote Exception caught: \" + re.getMessage());"); - writer.println(" }"); - } - } - + } + } + + writer.println(" } catch (java.rmi.RemoteException re) {"); + writer.print(INDENT); + writer.println("throw new junit.framework.AssertionFailedError(\"Remote Exception caught: \" + re );"); + writer.println(" }"); + } + } + /** * Get the writer - */ - public final PrintWriter getWriter() { - return this.writer; - } -} \ No newline at end of file + */ + public final PrintWriter getWriter() { + return this.writer; + } +}