| 1 |
package test.badWSDL; |
| 2 |
|
| 3 |
import junit.framework.Test; |
| 4 |
import junit.framework.TestCase; |
| 5 |
import junit.framework.TestSuite; |
| 6 |
import org.apache.axis.wsdl.toJava.Emitter; |
| 7 |
|
| 8 |
import java.io.File; |
| 9 |
import java.io.FilenameFilter; |
| 10 |
|
| 11 |
/** |
| 12 |
* This test grabs each WSDL file in the directory and runs WSDL2Java against them. |
| 13 |
* They should all fail. If one does not, this test fails. |
| 14 |
*/ |
| 15 |
|
| 16 |
public class WSDL2JavaFailuresTestCase extends TestCase { |
| 17 |
private static final String badWSDL = "test" + File.separatorChar + |
| 18 |
"badWSDL"; |
| 19 |
private String wsdl; |
| 20 |
|
| 21 |
public WSDL2JavaFailuresTestCase(String wsdl) { |
| 22 |
super("testWSDLFailures"); |
| 23 |
this.wsdl = wsdl; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Create a test suite with a single test for each WSDL file in this |
| 28 |
* directory. |
| 29 |
*/ |
| 30 |
public static Test suite() { |
| 31 |
TestSuite tests = new TestSuite(); |
| 32 |
String[] wsdls = getWSDLs(); |
| 33 |
for (int i = 0; i < wsdls.length; ++i) { |
| 34 |
tests.addTest(new WSDL2JavaFailuresTestCase(badWSDL + |
| 35 |
File.separatorChar + wsdls[i])); |
| 36 |
} |
| 37 |
return tests; |
| 38 |
} // suite |
| 39 |
|
| 40 |
/** |
| 41 |
* Get a list of all WSDL files in this directory. |
| 42 |
*/ |
| 43 |
private static String[] getWSDLs() { |
| 44 |
String[] wsdls = null; |
| 45 |
try { |
| 46 |
File failuresDir = new File(badWSDL); |
| 47 |
FilenameFilter fnf = new FilenameFilter() |
| 48 |
{ |
| 49 |
public boolean accept(File dir, String name) { |
| 50 |
return name.endsWith(".wsdl"); |
| 51 |
} |
| 52 |
}; |
| 53 |
wsdls = failuresDir.list(fnf); |
| 54 |
} |
| 55 |
catch (Throwable t) { |
| 56 |
wsdls = null; |
| 57 |
} |
| 58 |
if (wsdls == null) { |
| 59 |
wsdls = new String[0]; |
| 60 |
} |
| 61 |
return wsdls; |
| 62 |
} // getWSDLs |
| 63 |
|
| 64 |
/** |
| 65 |
* Call WSDL2Java on this WSDL file, failing if WSDL2Java succeeds. |
| 66 |
*/ |
| 67 |
public void testWSDLFailures() { |
| 68 |
boolean failed = false; |
| 69 |
Emitter emitter = new Emitter(); |
| 70 |
|
| 71 |
emitter.setTestCaseWanted(true); |
| 72 |
emitter.setHelperWanted(true); |
| 73 |
emitter.setImports(true); |
| 74 |
emitter.setAllWanted(true); |
| 75 |
emitter.setServerSide(true); |
| 76 |
emitter.setSkeletonWanted(true); |
| 77 |
try { |
| 78 |
emitter.run(wsdl); |
| 79 |
failed = true; |
| 80 |
} |
| 81 |
catch (Throwable e) { |
| 82 |
} |
| 83 |
if (failed) { |
| 84 |
fail("WSDL2Java " + wsdl + " should have failed."); |
| 85 |
} |
| 86 |
} // testWSDLFailures |
| 87 |
} // class WSDL2JavaFailuresTestCase |
| 88 |
|