KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > webservices > unit > JSR181TestCase


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.ejb3.test.webservices.unit;
23
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.Hashtable JavaDoc;
27
28 import javax.naming.Context JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31 import javax.rmi.PortableRemoteObject JavaDoc;
32 import javax.xml.rpc.Service JavaDoc;
33
34 import junit.framework.Test;
35
36 import org.jboss.test.JBossTestCase;
37 import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
38 import org.jboss.ws.metadata.wsdl.WSDLDefinitionsFactory;
39
40 import org.jboss.ejb3.test.webservices.jsr181.EndpointInterface;
41 import org.jboss.ejb3.test.webservices.jsr181.EJB3RemoteInterface;
42 import org.jboss.ejb3.test.webservices.jsr181.StatelessRemote;
43
44 /**
45  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
46  * @version $Revision: 43930 $
47  */

48 public class JSR181TestCase extends JBossTestCase
49 {
50    public JSR181TestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54
55    public void testRemoteAccess() throws Exception JavaDoc
56    {
57       InitialContext JavaDoc iniCtx = getInitialContext();
58       EJB3RemoteInterface ejb3Remote = (EJB3RemoteInterface)iniCtx.lookup("/ejb3/EJB3EndpointInterface");
59
60       String JavaDoc helloWorld = "Hello world!";
61       Object JavaDoc retObj = ejb3Remote.echo(helloWorld);
62       assertEquals(helloWorld, retObj);
63    }
64
65    public void testWebService() throws Exception JavaDoc
66    {
67       assertWSDLAccess();
68       
69       InitialContext JavaDoc iniCtx = getInitialContext();
70       Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/TestService");
71       EndpointInterface port = (EndpointInterface)service.getPort(EndpointInterface.class);
72
73       String JavaDoc helloWorld = "Hello world!";
74       Object JavaDoc retObj = port.echo(helloWorld);
75       assertEquals(helloWorld, retObj);
76    }
77    
78    public void testWebServiceRef() throws Exception JavaDoc
79    {
80       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
81       StatelessRemote stateless = (StatelessRemote)jndiContext.lookup("StatelessBean/remote");
82       assertNotNull(stateless);
83       
84       assertEquals("Hello", stateless.echo1("Hello"));
85       
86       assertEquals("Hello", stateless.echo2("Hello"));
87       
88       assertEquals("Hello", stateless.echo3("Hello"));
89       
90       assertEquals("Hello", stateless.echo4("Hello"));
91       
92       assertEquals("Hello", stateless.echo5("Hello"));
93       
94       assertEquals("Hello", stateless.echo6("Hello"));
95       
96       assertEquals("Hello", stateless.echo7("Hello"));
97       
98       assertEquals("Hello", stateless.echo8("Hello"));
99       
100       assertEquals("Hello", stateless.echo9("Hello"));
101    }
102
103    private void assertWSDLAccess() throws MalformedURLException JavaDoc
104    {
105       URL JavaDoc wsdlURL = new URL JavaDoc("http://" + getServerHost() + ":8080/jsr181?wsdl");
106       WSDLDefinitionsFactory factory = WSDLDefinitionsFactory.newInstance();
107       WSDLDefinitions wsdlDefinitions = factory.parse(wsdlURL);
108       assertNotNull(wsdlDefinitions);
109    }
110    
111    public static Test suite() throws Exception JavaDoc
112    {
113       return getDeploySetup(JSR181TestCase.class, "jsr181-client.jar, jsr181.jar");
114    }
115    
116    protected InitialContext JavaDoc getInitialContext(String JavaDoc clientName) throws NamingException JavaDoc
117    {
118       InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
119       Hashtable JavaDoc env = iniCtx.getEnvironment();
120       env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
121       env.put("j2ee.clientName", clientName);
122       return new InitialContext JavaDoc(env);
123    }
124
125    /** Get the client's env context
126     */

127    protected InitialContext JavaDoc getInitialContext() throws NamingException JavaDoc
128    {
129       return getInitialContext("jbossws-client");
130    }
131    
132    public String JavaDoc getServerHost()
133    {
134       String JavaDoc hostName = System.getProperty("jbosstest.server.host", "localhost");
135       return hostName;
136    }
137 }
138
Popular Tags