KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > badWSDL > WSDL2JavaFailuresTestCase


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 JavaDoc;
9 import java.io.FilenameFilter JavaDoc;
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 JavaDoc badWSDL = "test" + File.separatorChar +
18             "badWSDL";
19     private String JavaDoc wsdl;
20
21     public WSDL2JavaFailuresTestCase(String JavaDoc 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 JavaDoc[] 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 JavaDoc[] getWSDLs() {
44         String JavaDoc[] wsdls = null;
45         try {
46             File JavaDoc failuresDir = new File JavaDoc(badWSDL);
47             FilenameFilter JavaDoc fnf = new FilenameFilter JavaDoc()
48             {
49                 public boolean accept(File JavaDoc dir, String JavaDoc name) {
50                     return name.endsWith(".wsdl");
51                 }
52             };
53             wsdls = failuresDir.list(fnf);
54         }
55         catch (Throwable JavaDoc t) {
56             wsdls = null;
57         }
58         if (wsdls == null) {
59             wsdls = new String JavaDoc[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 JavaDoc e) {
82         }
83         if (failed) {
84             fail("WSDL2Java " + wsdl + " should have failed.");
85         }
86     } // testWSDLFailures
87
} // class WSDL2JavaFailuresTestCase
88

89
Popular Tags