KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdd > TestOptions


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.configuration.XMLStringProvider;
8 import org.apache.axis.deployment.wsdd.WSDDConstants;
9 import org.apache.axis.server.AxisServer;
10
11 public class TestOptions extends TestCase
12 {
13     static final String JavaDoc HANDLER_NAME = "logger";
14     static final String JavaDoc PARAM_NAME = "testParam";
15     static final String JavaDoc PARAM_VAL = "testValue";
16
17     // Two-part WSDD, with a space for scope option in the middle
18
static final String JavaDoc doc =
19             "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " +
20                   "xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n" +
21             " <handler type=\"java:org.apache.axis.handlers.LogHandler\" " +
22                       "name=\"" + HANDLER_NAME + "\">\n" +
23             " <parameter name=\"" + PARAM_NAME +
24                           "\" value=\"" + PARAM_VAL + "\"/>\n" +
25             " </handler>\n" +
26             " <handler type=\"logger\" name=\"other\"/>\n" +
27             "</deployment>";
28
29     public TestOptions (String JavaDoc name) {
30         super(name);
31     }
32
33     public static Test suite() {
34         return new TestSuite(TestOptions.class);
35     }
36
37     protected void setup() {
38     }
39
40     /**
41      * Initialize an engine with a single handler with a parameter set, and
42      * another reference to that same handler with a different name.
43      *
44      * Make sure the param is set for both the original and the reference
45      * handler.
46      *
47      */

48     public void testOptions() throws Exception JavaDoc
49     {
50         XMLStringProvider provider = new XMLStringProvider(doc);
51         AxisServer server = new AxisServer(provider);
52         
53         Handler h1 = server.getHandler(HANDLER_NAME);
54         assertNotNull("Couldn't get logger handler from engine!", h1);
55         
56         Object JavaDoc optVal = h1.getOption(PARAM_NAME);
57         assertNotNull("Option value was null!", optVal);
58         assertEquals("Option was not expected value", optVal, PARAM_VAL);
59
60         optVal = server.getOption("someOptionWhichIsntSet");
61         assertNull("Got value for bad option!", optVal);
62
63         Handler h2 = server.getHandler("other");
64         assertNotNull("Couldn't get second handler", h2);
65
66         optVal = h1.getOption(PARAM_NAME);
67         assertNotNull("Option value was null for 2nd handler!", optVal);
68         assertEquals("Option was not expected value for 2nd handler",
69                      optVal, PARAM_VAL);
70
71         optVal = server.getOption("someOptionWhichIsntSet");
72         assertNull("Got value for bad option on 2nd handler!", optVal);
73     }
74     
75     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
76         TestOptions tester = new TestOptions("foo");
77         tester.testOptions();
78     }
79 }
80
Popular Tags