KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdd > TestAllowedMethods


1 /*
2  * Created by IntelliJ IDEA.
3  * User: gdaniels
4  * Date: Apr 2, 2002
5  * Time: 10:14:06 AM
6  * To change template for new class use
7  * Code Style | Class Templates options (Tools | IDE Options).
8  */

9 package test.wsdd;
10
11 import junit.framework.TestCase;
12 import org.apache.axis.client.Call;
13 import org.apache.axis.client.Service;
14 import org.apache.axis.configuration.XMLStringProvider;
15 import org.apache.axis.deployment.wsdd.WSDDConstants;
16 import org.apache.axis.server.AxisServer;
17 import org.apache.axis.transport.local.LocalTransport;
18
19 public class TestAllowedMethods extends TestCase {
20     static final String JavaDoc SERVICE_NAME = "AllowedMethodService";
21     private static final String JavaDoc MESSAGE = "Allowed method";
22
23     AxisServer server;
24     LocalTransport transport;
25
26     // Two-part WSDD, with a space for scope option in the middle
27
static final String JavaDoc doc1 =
28             "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " +
29                   "xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n" +
30             " <service name=\"" + SERVICE_NAME + "\" " +
31                       "provider=\"java:RPC\">\n" +
32             " <parameter name=\"allowedMethods\" value=\"allowed\"/>" +
33             " <parameter name=\"className\" value=\"test.wsdd.TestAllowedMethods\"/>" +
34             " </service>\n" +
35             "</deployment>";
36
37     public TestAllowedMethods() {
38         super("test");
39     }
40
41     public TestAllowedMethods(String JavaDoc s) {
42         super(s);
43     }
44
45     protected void setUp() throws Exception JavaDoc {
46         XMLStringProvider config = new XMLStringProvider(doc1);
47         server = new AxisServer(config);
48         transport = new LocalTransport(server);
49         transport.setRemoteService(SERVICE_NAME);
50     }
51
52     public void testAllowedMethods() throws Exception JavaDoc {
53         Call call = new Call(new Service());
54         call.setTransport(transport);
55
56         String JavaDoc ret = (String JavaDoc)call.invoke("allowed", null);
57         assertEquals("Return didn't match", MESSAGE, ret);
58
59         try {
60             ret = (String JavaDoc)call.invoke("disallowed", null);
61         } catch (Exception JavaDoc e) {
62             // Success, we shouldn't have been allowed to call that.
63
return;
64         }
65
66         fail("Successfully called disallowed method!");
67     }
68
69     public String JavaDoc disallowed() throws Exception JavaDoc {
70         return "You shouldn't have called me!";
71     }
72
73     public String JavaDoc allowed() {
74         return MESSAGE;
75     }
76 }
77
Popular Tags