butek 2002/09/25 07:50:23 Added: java/test/badWSDL build.xml mismatchedOperation.wsdl PackageTests.java WSDL2JavaFailuresTestCase.java Log: I added a test for bad WSDL files that everyone can use. If you expect WSDL2Java to fail on a particular WSDL file and you wish to test that failure, simply dump your WSDL file into test/badWSDL/. This test runs WSDL2Java on all WSDL files in this directory and passes if WSDL2Java fails. Revision Changes Path 1.1 xml-axis/java/test/badWSDL/build.xml Index: build.xml =================================================================== <?xml version="1.0" ?> <!DOCTYPE project [ <!ENTITY properties SYSTEM "file:../../xmls/properties.xml"> <!ENTITY paths SYSTEM "file:../../xmls/path_refs.xml"> <!ENTITY taskdefs SYSTEM "file:../../xmls/taskdefs.xml"> <!ENTITY taskdefs_post_compile SYSTEM "file:../../xmls/taskdefs_post_compile.xml"> <!ENTITY targets SYSTEM "file:../../xmls/targets.xml"> ]> <!-- =================================================================== <description> Test/Sample Component file for Axis Notes: This is a build file for use with the Jakarta Ant build tool. Prerequisites: jakarta-ant from http://jakarta.apache.org Build Instructions: To compile ant compile To execute ant run Author: Matt Seibert [EMAIL PROTECTED] Copyright: Copyright (c) 2002-2003 Apache Software Foundation. </description> ==================================================================== --> <project default="compile"> <property name="axis.home" location="../.." /> <property name="componentName" value="test/badWSDL" /> &properties; &paths; &taskdefs; &taskdefs_post_compile; &targets; <target name="clean"> <echo message="Removing ${build.dir}/classes/${componentName} and ${build.dir}/work/${componentName}" /> <delete dir="${build.dir}/classes/${componentName}"/> <delete dir="${build.dir}/work/${componentName}"/> </target> <target name="copy" depends="setenv"/> <target name="compile" depends="copy"> <echo message="Compiling test.badWSDL"/> <!-- Test WSDL2Java on bad WSDL files. - <copy todir="${build.dir}/work/test/badWSDL" overwrite="yes"> <fileset dir="${axis.home}/test/badWSDL"> <include name="*TestCase.java"/> </fileset> </copy> <javac srcdir="${build.dir}/work" destdir="${build.dest}" fork="${javac.fork}" debug="${debug}"> <classpath refid="classpath" /> <include name="test/badWSDL/*.java" /> </javac> --> <javac srcdir="${axis.home}" destdir="${build.dest}" debug="${debug}" fork="${javac.fork}"> <classpath> <path refid="classpath"/> </classpath> <include name="test/badWSDL/*.java"/> </javac> </target> <target name="run" > <antcall target="execute-Component" /> </target> </project> 1.1 xml-axis/java/test/badWSDL/mismatchedOperation.wsdl Index: mismatchedOperation.wsdl =================================================================== <?xml version="1.0" ?> <definitions name="urn:GetQuote" targetNamespace="urn:xmltoday-delayed-quotes" xmlns:tns="urn:xmltoday-delayed-quotes" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <!-- message declns --> <message name="GetQuoteRequest"> <part name="symbol" type="xsd:string"/> </message> <message name="GetQuoteResponse"> <part name="result" type="xsd:float"/> </message> <!-- port type declns --> <portType name="GetQuote"> <operation name="getQuote" > <input message="tns:GetQuoteRequest"/> <output message="tns:GetQuoteResponse"/> </operation> </portType> <!-- binding declns --> <binding name="GetQuoteBinding" type="tns:GetQuote"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="getQuote"> <soap:operation soapAction="getQuote"/> <input name="justName"> ****** here is the difference **** <soap:body use="encoded" namespace="urn:xmltoday-delayed-quotes" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <soap:body use="encoded" namespace="urn:xmltoday-delayed-quotes" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding> <!-- service decln --> <service name="GetQuoteService"> <port name="GetQuote" binding="tns:GetQuoteBinding"> <soap:address location="http://localhost:8080/axis/servlet/AxisServlet"/> </port> </service> </definitions> 1.1 xml-axis/java/test/badWSDL/PackageTests.java Index: PackageTests.java =================================================================== package test.badWSDL; import junit.framework.Test; import junit.framework.TestSuite; /** */ public class PackageTests { public static void main (String[] args) { junit.textui.TestRunner.run (suite()); } public static Test suite() { TestSuite suite = new TestSuite("All bad WSDL tests"); suite.addTest(WSDL2JavaFailuresTestCase.suite()); return suite; } } 1.1 xml-axis/java/test/badWSDL/WSDL2JavaFailuresTestCase.java Index: WSDL2JavaFailuresTestCase.java =================================================================== package test.badWSDL; import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.axis.wsdl.toJava.Emitter; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; /** * This test grabs each WSDL file in the directory and runs WSDL2Java against them. * They should all fail. If one does not, this test fails. */ public class WSDL2JavaFailuresTestCase extends TestCase { private static final String badWSDL = "test" + File.separatorChar + "badWSDL"; private String wsdl; public WSDL2JavaFailuresTestCase(String wsdl) { super("testWSDLFailures"); this.wsdl = wsdl; } /** * Create a test suite with a single test for each WSDL file in this * directory. */ public static Test suite() { TestSuite tests = new TestSuite(); String[] wsdls = getWSDLs(); for (int i = 0; i < wsdls.length; ++i) { tests.addTest(new WSDL2JavaFailuresTestCase(badWSDL + File.separatorChar + wsdls[i])); } return tests; } // suite /** * Get a list of all WSDL files in this directory. */ private static String[] getWSDLs() { String[] wsdls = null; try { File failuresDir = new File(badWSDL); FilenameFilter fnf = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".wsdl"); } }; wsdls = failuresDir.list(fnf); } catch (Throwable t) { wsdls = null; } if (wsdls == null) { wsdls = new String[0]; } return wsdls; } // getWSDLs /** * Call WSDL2Java on this WSDL file, failing if WSDL2Java succeeds. */ public void testWSDLFailures() { boolean failed = false; Emitter emitter = new Emitter(); emitter.setTestCaseWanted(true); emitter.setHelperWanted(true); emitter.setImports(true); emitter.setAllWanted(true); emitter.setServerSide(true); emitter.setSkeletonWanted(true); try { emitter.run(wsdl); failed = true; } catch (Throwable e) { } if (failed) { fail("WSDL2Java " + wsdl + " should have failed."); } } // testWSDLFailures } // class WSDL2JavaFailuresTestCase