1 22 package org.jboss.ejb3.test.webservices.unit; 23 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.util.Hashtable ; 27 28 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 import javax.rmi.PortableRemoteObject ; 32 import javax.xml.rpc.Service ; 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 48 public class JSR181TestCase extends JBossTestCase 49 { 50 public JSR181TestCase(String name) 51 { 52 super(name); 53 } 54 55 public void testRemoteAccess() throws Exception 56 { 57 InitialContext iniCtx = getInitialContext(); 58 EJB3RemoteInterface ejb3Remote = (EJB3RemoteInterface)iniCtx.lookup("/ejb3/EJB3EndpointInterface"); 59 60 String helloWorld = "Hello world!"; 61 Object retObj = ejb3Remote.echo(helloWorld); 62 assertEquals(helloWorld, retObj); 63 } 64 65 public void testWebService() throws Exception 66 { 67 assertWSDLAccess(); 68 69 InitialContext iniCtx = getInitialContext(); 70 Service service = (Service )iniCtx.lookup("java:comp/env/service/TestService"); 71 EndpointInterface port = (EndpointInterface)service.getPort(EndpointInterface.class); 72 73 String helloWorld = "Hello world!"; 74 Object retObj = port.echo(helloWorld); 75 assertEquals(helloWorld, retObj); 76 } 77 78 public void testWebServiceRef() throws Exception 79 { 80 InitialContext jndiContext = new InitialContext (); 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 104 { 105 URL wsdlURL = new URL ("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 112 { 113 return getDeploySetup(JSR181TestCase.class, "jsr181-client.jar, jsr181.jar"); 114 } 115 116 protected InitialContext getInitialContext(String clientName) throws NamingException 117 { 118 InitialContext iniCtx = new InitialContext (); 119 Hashtable env = iniCtx.getEnvironment(); 120 env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client"); 121 env.put("j2ee.clientName", clientName); 122 return new InitialContext (env); 123 } 124 125 127 protected InitialContext getInitialContext() throws NamingException 128 { 129 return getInitialContext("jbossws-client"); 130 } 131 132 public String getServerHost() 133 { 134 String hostName = System.getProperty("jbosstest.server.host", "localhost"); 135 return hostName; 136 } 137 } 138 | Popular Tags |