KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdd > TestScopeOption


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 TestScopeOption extends TestCase
12 {
13     static final String JavaDoc HANDLER_NAME = "logger";
14     
15     // Two-part WSDD, with a space for scope option in the middle
16
static final String JavaDoc doc1 =
17             "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " +
18                   "xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n" +
19             " <handler type=\"java:org.apache.axis.handlers.LogHandler\" " +
20                       "name=\"" + HANDLER_NAME + "\" " +
21                       "scope=\"";
22     static final String JavaDoc doc2 = "\"/>\n" +
23             "</deployment>";
24
25     public TestScopeOption (String JavaDoc name) {
26         super(name);
27     }
28
29     public static Test suite() {
30         return new TestSuite(TestScopeOption.class);
31     }
32
33     protected void setup() {
34     }
35
36     /**
37      * Initialize an engine with a single handler with per-access scope.
38      * Then get the handler from the engine twice, and confirm that we get
39      * two different objects.
40      *
41      */

42     public void testPerAccessScope() throws Exception JavaDoc
43     {
44         String JavaDoc doc = doc1 + "per-access" + doc2;
45         XMLStringProvider provider = new XMLStringProvider(doc);
46         AxisServer server = new AxisServer(provider);
47         
48         Handler h1 = server.getHandler(HANDLER_NAME);
49         assertNotNull("Couldn't get first logger handler from engine!", h1);
50         
51         Handler h2 = server.getHandler(HANDLER_NAME);
52         assertNotNull("Couldn't get second logger handler from engine!", h2);
53         
54         assertTrue("Per-access Handlers were identical!", (h1 != h2));
55     }
56     
57     /**
58      * Initialize an engine with a single handler of singleton scope.
59      * Then get the handler from the engine twice, and confirm that we
60      * get the same object both times.
61      */

62     public void testSingletonScope() throws Exception JavaDoc
63     {
64         String JavaDoc doc = doc1 + "singleton" + doc2;
65         XMLStringProvider provider = new XMLStringProvider(doc);
66         AxisServer server = new AxisServer(provider);
67         
68         Handler h1 = server.getHandler(HANDLER_NAME);
69         assertNotNull("Couldn't get first logger handler from engine!", h1);
70         
71         Handler h2 = server.getHandler(HANDLER_NAME);
72         assertNotNull("Couldn't get second logger handler from engine!", h2);
73         
74         assertTrue("Singleton Handlers were different!", (h1 == h2));
75     }
76     
77     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
78         TestScopeOption tester = new TestScopeOption("foo");
79         tester.testPerAccessScope();
80     }
81 }
82
Popular Tags