KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > header > HeaderEndpointTestCase


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.header;
23
24 import junit.framework.Test;
25 import org.jboss.test.webservice.WebserviceTestBase;
26 import org.jboss.util.id.UID;
27
28 import javax.naming.InitialContext JavaDoc;
29 import javax.xml.rpc.Service JavaDoc;
30
31 /**
32  * A collection of header tests.
33  *
34  * @author Thomas.Diesler@jboss.org
35  * @since 26-Nov-2004
36  */

37 public class HeaderEndpointTestCase extends WebserviceTestBase
38 {
39    public HeaderEndpointTestCase(String JavaDoc name)
40    {
41       super(name);
42    }
43
44    /** Deploy the test ear */
45    public static Test suite() throws Exception JavaDoc
46    {
47       return getDeploySetup(HeaderEndpointTestCase.class, "ws4ee-header.war, ws4ee-header-client.jar");
48    }
49    
50    /** Send a message with IN header.
51     * The service endpoint interface sees the header.
52     */

53    public void testSimpleHeaderEndpoint() throws Exception JavaDoc
54    {
55       InitialContext JavaDoc iniCtx = getClientContext();
56       Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/SimpleHeaderService");
57       SimpleHeaderEndpoint port = (SimpleHeaderEndpoint)service.getPort(SimpleHeaderEndpoint.class);
58
59       boolean result = port.doStuff("Hello World!", "kermit");
60       assertTrue(result);
61    }
62
63    /** Send a message with complex IN header.
64     * The service endpoint interface sees the header.
65     */

66    public void testBeanHeaderEndpoint() throws Exception JavaDoc
67    {
68       InitialContext JavaDoc iniCtx = getClientContext();
69       Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/BeanHeaderService");
70       BeanHeaderEndpoint port = (BeanHeaderEndpoint)service.getPort(BeanHeaderEndpoint.class);
71
72       SessionHeader header = new SessionHeader();
73       header.setUsername("kermit");
74       header.setSessionID(UID.asString());
75
76       boolean result = port.doStuff("Hello World!", header);
77       assertTrue(result);
78    }
79
80    /** Send a message with INOUT headers. The headers are processed by handlers.
81     * The service endpoint interface does not see the header.
82     */

83    public void testImplicitHeaderEndpoint() throws Exception JavaDoc
84    {
85       InitialContext JavaDoc iniCtx = getClientContext();
86       Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/ImplicitHeaderService");
87       ImplicitHeaderEndpoint port = (ImplicitHeaderEndpoint)service.getPort(ImplicitHeaderEndpoint.class);
88
89       boolean result = port.doStuff("Hello World!");
90       assertTrue(result);
91
92       // Do a second call to the endpoint, this time with sessionID
93
result = port.doStuff("Hello World!");
94       assertTrue(result);
95    }
96
97    /** Send a message with INOUT headers.
98     * The service endpoint interface sees the header.
99     */

100    public void testExplicitHeaderEndpoint() throws Exception JavaDoc
101    {
102       InitialContext JavaDoc iniCtx = getClientContext();
103       Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/ExplicitHeaderService");
104       ExplicitHeaderEndpoint port = (ExplicitHeaderEndpoint)service.getPort(ExplicitHeaderEndpoint.class);
105
106       SessionHeader header = new SessionHeader();
107       header.setUsername("kermit");
108       SessionHeaderHolder holder = new SessionHeaderHolder();
109       holder.value = header;
110
111       boolean result = port.doStuff("Hello World!", holder);
112       assertTrue(result);
113       assertNotNull(holder.value);
114
115       header = holder.value;
116       assertEquals("kermit", header.getUsername());
117       assertNotNull(header.getSessionID());
118
119       // Do a second call to the endpoint, this time with sessionID
120
result = port.doStuff("Hello World!", holder);
121       assertTrue(result);
122       assertNotNull(holder.value);
123
124       header = holder.value;
125       assertEquals("kermit", header.getUsername());
126       assertNotNull(header.getSessionID());
127    }
128 }
129
Popular Tags