KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > handlerflow > HandlerFlowTestCase


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.webservice.handlerflow;
23
24 import java.util.Arrays JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.naming.InitialContext JavaDoc;
28
29 import junit.framework.Test;
30 import junit.framework.TestSuite;
31
32 import org.jboss.test.JBossTestCase;
33 import org.jboss.test.webservice.WebserviceTestBase;
34
35 /**
36  * The HelloEjb is the web service client conecting to HelloJSE.
37  * Both the client and the server have handlers configured, we test
38  * the flow of handler invocations.
39  *
40  * @author Thomas.Diesler@jboss.org
41  * @since 12-May-2004
42  */

43 public class HandlerFlowTestCase extends WebserviceTestBase
44 {
45    private static HelloRemote ejb;
46    
47    public HandlerFlowTestCase(String JavaDoc name)
48    {
49       super(name);
50    }
51
52    public static Test suite() throws Exception JavaDoc
53    {
54       // JBAS-3608, the execution order of tests in this test case is important
55
// so it must be defined explicitly when running under some JVMs
56
TestSuite suite = new TestSuite();
57       suite.addTest(new HandlerFlowTestCase("testHandlerFlowAllPass"));
58       suite.addTest(new HandlerFlowTestCase("testHandlerFlowClientReturn"));
59       suite.addTest(new HandlerFlowTestCase("testHandlerFlowServerReturn"));
60       
61       return JBossTestCase.getDeploySetup(suite, "ws4ee-handlerflow.jar, ws4ee-handlerflow.war");
62    }
63    
64    public void setUp() throws Exception JavaDoc
65    {
66       super.setUp();
67       
68       if (ejb == null)
69       {
70          InitialContext JavaDoc iniCtx = getClientContext();
71          HelloHome home = (HelloHome)iniCtx.lookup("ejb/HelloEjb");
72          ejb = home.create();
73       }
74    }
75
76    /**
77     * Call the ejb and verify the hander tracker protocol
78     */

79    public void testHandlerFlowAllPass() throws Exception JavaDoc
80    {
81       // test direct EJB access
82
List JavaDoc protocol = Arrays.asList(ejb.sayHello("Hello"));
83
84       String JavaDoc[] exp = {
85          "ClientHandler1 init",
86          "ClientHandler2 init",
87          "ClientHandler1 handleRequest",
88          "ClientHandler2 handleRequest",
89          "ServerHandler1 init",
90          "ServerHandler2 init",
91          "ServerHandler1 handleRequest",
92          "ServerHandler2 handleRequest",
93          "jse: 'Hello' to you too!",
94          "ServerHandler2 handleResponse",
95          "ServerHandler1 handleResponse",
96          "ClientHandler2 handleResponse",
97          "ClientHandler1 handleResponse",
98          "ejb: 'Hello' to you too!"
99       };
100       
101       assertHandlerProtocol(exp, protocol);
102    }
103
104    /**
105     * ClientHandler2 should return false and terminate the call
106     */

107    public void testHandlerFlowClientReturn() throws Exception JavaDoc
108    {
109       if (isWS4EEAvailable() == false)
110       {
111          List JavaDoc protocol = Arrays.asList(ejb.sayHello("ClientReturn"));
112
113          String JavaDoc[] exp = {
114                "ClientHandler1 handleRequest",
115                "ClientHandler2 handleRequest",
116                "ClientHandler2 handleResponse",
117                "ClientHandler1 handleResponse",
118                "ejb: Return in ClientHandler2" };
119
120          assertHandlerProtocol(exp, protocol);
121       }
122    }
123
124
125    /**
126     * ClientHandler2 should return false and terminate the call
127     */

128    public void testHandlerFlowServerReturn() throws Exception JavaDoc
129    {
130       if (isWS4EEAvailable() == false)
131       {
132          List JavaDoc protocol = Arrays.asList(ejb.sayHello("ServerReturn"));
133
134          String JavaDoc[] exp = {
135                "ClientHandler1 handleRequest",
136                "ClientHandler2 handleRequest",
137                "ServerHandler1 handleRequest",
138                "ServerHandler2 handleRequest",
139                "ServerHandler2 handleResponse",
140                "ServerHandler1 handleResponse",
141                "ClientHandler2 handleResponse",
142                "ClientHandler1 handleResponse",
143                "ejb: Return in ServerHandler2" };
144
145          assertHandlerProtocol(exp, protocol);
146       }
147    }
148
149    private void assertHandlerProtocol(String JavaDoc[] exp, List JavaDoc protocol)
150    {
151       assertEquals("Wrong number of entries: " + protocol, exp.length, protocol.size());
152
153       for (int i = 0; i < protocol.size(); i++)
154       {
155          String JavaDoc msg = (String JavaDoc)protocol.get(i);
156          boolean equals = msg.startsWith(exp[i]);
157          assertTrue("Wrong entry: " + msg + " in " + protocol, equals);
158       }
159    }
160 }
161
Popular Tags