KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdd > TestBadWSDD


1 package test.wsdd;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import org.apache.axis.Handler;
7 import org.apache.axis.client.AdminClient;
8 import org.apache.axis.configuration.XMLStringProvider;
9 import org.apache.axis.deployment.wsdd.WSDDConstants;
10 import org.apache.axis.server.AxisServer;
11 import org.apache.axis.transport.local.LocalTransport;
12
13 import java.io.ByteArrayInputStream JavaDoc;
14
15 /**
16  * Try various bad deployments, and make sure that we get back reasonable
17  * errors and don't screw up the engine's configuration.
18  *
19  * @author Glen Daniels (gdaniels@apache.org)
20  */

21 public class TestBadWSDD extends TestCase
22 {
23     static final String JavaDoc HANDLER_NAME = "logger";
24     static final String JavaDoc PARAM_NAME = "testParam";
25     static final String JavaDoc PARAM_VAL = "testValue";
26
27     static final String JavaDoc goodWSDD =
28             "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " +
29                   "xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n" +
30             " <handler type=\"java:org.apache.axis.handlers.LogHandler\" " +
31                       "name=\"" + HANDLER_NAME + "\">\n" +
32             " <parameter name=\"" + PARAM_NAME +
33                           "\" value=\"" + PARAM_VAL + "\"/>\n" +
34             " </handler>\n" +
35             " <handler type=\"logger\" name=\"other\"/>\n" +
36             " <service name=\"AdminService\" provider=\"java:MSG\">\n" +
37             " <parameter name=\"allowedMethods\" value=\"AdminService\"/>" +
38             " <parameter name=\"enableRemoteAdmin\" value=\"false\"/>" +
39             " <parameter name=\"className\"" +
40                     " value=\"org.apache.axis.utils.Admin\"/>" +
41             " </service>" +
42             "</deployment>";
43
44     static final String JavaDoc header =
45             "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " +
46                   "xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n";
47     static final String JavaDoc footer =
48             "</deployment>";
49
50     static final String JavaDoc badHandler =
51             " <handler name=\"nameButNoType\"/>\n";
52
53     public TestBadWSDD (String JavaDoc name) {
54         super(name);
55     }
56
57     public static Test suite() {
58         return new TestSuite(TestBadWSDD.class);
59     }
60
61     protected void setup() {
62     }
63
64     /**
65      * Initialize an engine with a single handler with a parameter set, and
66      * another reference to that same handler with a different name.
67      *
68      * Make sure the param is set for both the original and the reference
69      * handler.
70      *
71      */

72     public void testOptions() throws Exception JavaDoc
73     {
74         XMLStringProvider provider = new XMLStringProvider(goodWSDD);
75         AxisServer server = new AxisServer(provider);
76         
77         Handler h1 = server.getHandler(HANDLER_NAME);
78         assertNotNull("Couldn't get logger handler from engine!", h1);
79
80         AdminClient client = new AdminClient(true);
81         String JavaDoc doc = header + badHandler + footer;
82         ByteArrayInputStream JavaDoc stream = new ByteArrayInputStream JavaDoc(doc.getBytes());
83         
84         LocalTransport transport = new LocalTransport(server);
85         transport.setUrl("local:///AdminService");
86         client.getCall().setTransport(transport);
87         try {
88             client.process(stream);
89         } catch (Exception JavaDoc e) {
90              return;
91         }
92         
93         fail("Successfully processed bad WSDD!");
94     }
95     
96     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
97         TestBadWSDD tester = new TestBadWSDD("foo");
98         tester.testOptions();
99     }
100 }
101
Popular Tags