KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > ws4eesimple > SimpleClientTestCase


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.ws4eesimple;
23
24 import junit.framework.Test;
25 import org.jboss.test.webservice.WebserviceTestBase;
26
27 import javax.naming.Context JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29 import javax.xml.rpc.Service JavaDoc;
30 import java.io.BufferedReader JavaDoc;
31 import java.io.InputStreamReader JavaDoc;
32 import java.net.URL JavaDoc;
33
34 /**
35  * Tests of the ws4ee functionality for a simple Hello EJB.
36  *
37  * @author Thomas.Diesler@jboss.org
38  * @author Christoph.Jung@infor.de
39  * @since 06-May-2004
40  */

41 public class SimpleClientTestCase extends WebserviceTestBase
42 {
43
44    /**
45     * Construct the test case with a given name
46     */

47    public SimpleClientTestCase(String JavaDoc name)
48    {
49       super(name);
50    }
51
52    /**
53     * deploy the test archives
54     */

55    public static Test suite() throws Exception JavaDoc
56    {
57       return getDeploySetup(SimpleClientTestCase.class, "ws4ee-simple.jar, ws4ee-simple-client.ear");
58    }
59
60    /**
61     * Test client application access
62     */

63    public void testApplClient() throws Exception JavaDoc
64    {
65       Context JavaDoc envCtx = getClientContext();
66       Service JavaDoc service = (Service JavaDoc)envCtx.lookup("java:comp/env/service/HelloService");
67       HelloWs ws = (HelloWs)service.getPort(HelloWs.class);
68       String JavaDoc res = ws.sayHello("Hello");
69       assertEquals("'Hello' to you too!", res);
70    }
71
72    /**
73     * Test servlet client access
74     */

75    public void testWebClient() throws Exception JavaDoc
76    {
77       URL JavaDoc url = new URL JavaDoc("http://" + getServerHost() + ":8080/ws4ee-simple-client/HelloWsClientServlet?input=Hello");
78       BufferedReader JavaDoc br = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(url.openStream()));
79       String JavaDoc res = br.readLine();
80       br.close();
81
82       assertEquals("'Hello' to you too!", res);
83    }
84
85    /**
86     * Test EJB client access
87     */

88    public void testEJBClient() throws Exception JavaDoc
89    {
90       // test direct EJB access
91
InitialContext JavaDoc iniCtx = getClientContext();
92       HelloHome home = (HelloHome)iniCtx.lookup("java:comp/env/HelloClientEjb");
93       Hello ejb = home.create();
94
95       String JavaDoc output = ejb.sayHello("Hello");
96       assertEquals("'Hello' to you too!", output);
97
98       // test webservice access
99
Context JavaDoc envCtx = getClientContext();
100       Service JavaDoc svc = (Service JavaDoc)envCtx.lookup("java:comp/env/service/HelloService");
101
102       HelloWs sei = (HelloWs)svc.getPort(HelloWs.class);
103       output = sei.sayHello("Hello");
104       assertEquals("'Hello' to you too!", output);
105    }
106 }
107
Popular Tags