[jbossws-commits] JBossWS SVN: r8138 - stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Tue Aug 26 09:44:14 EDT 2008


Author: alessio.soldano at jboss.com
Date: 2008-08-26 09:44:14 -0400 (Tue, 26 Aug 2008)
New Revision: 8138

Modified:
   stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/SecureEndpointClient.java
   stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/ServiceRefOverridesTestCase.java
   stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/StubPropertyTestCase.java
   stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/TestEndpointClientTwo.java
Log:
[JBAS-5457] Fixing webserviceref tests


Modified: stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/SecureEndpointClient.java
===================================================================
--- stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/SecureEndpointClient.java	2008-08-26 12:06:12 UTC (rev 8137)
+++ stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/SecureEndpointClient.java	2008-08-26 13:44:14 UTC (rev 8138)
@@ -42,7 +42,7 @@
    @WebServiceRef(name = "SecurePort1")
    static SecureEndpoint securePort1;
 
-   static String retStr;
+   public static String retStr;
 
    public static void main(String[] args)
    {

Modified: stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/ServiceRefOverridesTestCase.java
===================================================================
--- stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/ServiceRefOverridesTestCase.java	2008-08-26 12:06:12 UTC (rev 8137)
+++ stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/ServiceRefOverridesTestCase.java	2008-08-26 13:44:14 UTC (rev 8138)
@@ -21,6 +21,10 @@
  */
 package org.jboss.test.ws.jaxws.webserviceref;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
 import junit.framework.Test;
 
 import org.jboss.ejb3.client.ClientLauncher;
@@ -42,14 +46,6 @@
       return new JBossWSTestSetup(ServiceRefOverridesTestCase.class, "jaxws-webserviceref.war, jaxws-webserviceref-override-client.jar");
    }
 
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-
-      if (TestEndpointClientTwo.iniCtx == null)
-         TestEndpointClientTwo.iniCtx = getInitialContext();
-   }
-
    public void testService1() throws Throwable
    {
       String resStr = invokeTest(getName());
@@ -92,9 +88,25 @@
       assertEquals(getName() + getName(), resStr);
    }
 
+   @SuppressWarnings("unchecked")
    private String invokeTest(String reqStr) throws Throwable
    {
       new ClientLauncher().launch(TestEndpointClientTwo.class.getName(), "jbossws-client", new String[] { reqStr });
-      return TestEndpointClientTwo.testResult.get(reqStr);
+      Class<?> empty[] = {};
+      try
+      {
+         //Use reflection to compile on AS 5.0.0.CR1 too
+         Method getMainClassMethod = ClientLauncher.class.getMethod("getTheMainClass", empty);
+         //At least JBoss AS 5.0.0.CR2
+         //Use reflection to prevent double loading of the client class
+         Class<?> clientClass = (Class<?>)getMainClassMethod.invoke(null, empty);
+         Field field = clientClass.getField("testResult");
+         return ((Map<String, String>)field.get(clientClass)).get(reqStr);
+      }
+      catch (NoSuchMethodException e)
+      {
+         //JBoss AS 5.0.0.CR1
+         return TestEndpointClientTwo.testResult.get(reqStr);
+      }
    }
 }

Modified: stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/StubPropertyTestCase.java
===================================================================
--- stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/StubPropertyTestCase.java	2008-08-26 12:06:12 UTC (rev 8137)
+++ stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/StubPropertyTestCase.java	2008-08-26 13:44:14 UTC (rev 8138)
@@ -21,6 +21,8 @@
  */
 package org.jboss.test.ws.jaxws.webserviceref;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.net.URL;
 import java.io.InputStream;
 
@@ -77,41 +79,62 @@
    {
       String reqMsg = "SecureService1";
       new ClientLauncher().launch(SecureEndpointClient.class.getName(), "jbossws-client", new String[] { reqMsg, "kermit", "thefrog" });
-      assertEquals(reqMsg, SecureEndpointClient.retStr);
+      assertResult(reqMsg);
    }
 
    public void testExplicitSecureService2() throws Throwable
    {
       String reqMsg = "SecureService2";
       new ClientLauncher().launch(SecureEndpointClient.class.getName(), "jbossws-client", new String[] { reqMsg, "kermit", "thefrog" });
-      assertEquals(reqMsg, SecureEndpointClient.retStr);
+      assertResult(reqMsg);
    }
 
    public void testExplicitSecurePort1() throws Throwable
    {
       String reqMsg = "SecurePort1";
       new ClientLauncher().launch(SecureEndpointClient.class.getName(), "jbossws-client", new String[] { reqMsg, "kermit", "thefrog" });
-      assertEquals(reqMsg, SecureEndpointClient.retStr);
+      assertResult(reqMsg);
    }
 
    public void testImplicitSecureService1() throws Throwable
    {
       String reqMsg = "SecureService1";
       new ClientLauncher().launch(SecureEndpointClient.class.getName(), "jbossws-client", new String[] { reqMsg });
-      assertEquals(reqMsg, SecureEndpointClient.retStr);
+      assertResult(reqMsg);
    }
 
    public void testImplicitSecureService2() throws Throwable
    {
       String reqMsg = "SecureService2";
       new ClientLauncher().launch(SecureEndpointClient.class.getName(), "jbossws-client", new String[] { reqMsg });
-      assertEquals(reqMsg, SecureEndpointClient.retStr);
+      assertResult(reqMsg);
    }
 
    public void testImplicitSecurePort1() throws Throwable
    {
       String reqMsg = "SecurePort1";
       new ClientLauncher().launch(SecureEndpointClient.class.getName(), "jbossws-client", new String[] { reqMsg });
-      assertEquals(reqMsg, SecureEndpointClient.retStr);
+      assertResult(reqMsg);
    }
+   
+   private static void assertResult(String expected) throws Exception
+   {
+      Class<?> empty[] = {};
+      try
+      {
+         //Use reflection to compile on AS 5.0.0.CR1 too
+         Method getMainClassMethod = ClientLauncher.class.getMethod("getTheMainClass", empty);
+         //At least JBoss AS 5.0.0.CR2
+         //Use reflection to prevent double loading of the client class
+         Class<?> clientClass = (Class<?>)getMainClassMethod.invoke(null, empty);
+         Field field = clientClass.getField("retStr");
+         String result = (String)field.get(clientClass);
+         assertEquals(expected, result);
+      }
+      catch (NoSuchMethodException e)
+      {
+         //JBoss AS 5.0.0.CR1
+         assertEquals(expected, SecureEndpointClient.retStr);
+      }
+   }
 }

Modified: stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/TestEndpointClientTwo.java
===================================================================
--- stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/TestEndpointClientTwo.java	2008-08-26 12:06:12 UTC (rev 8137)
+++ stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/webserviceref/TestEndpointClientTwo.java	2008-08-26 13:44:14 UTC (rev 8138)
@@ -25,7 +25,9 @@
 import org.jboss.test.ws.jaxws.webserviceref.TestEndpoint;
 import org.jboss.test.ws.jaxws.webserviceref.TestEndpointService;
 
+import javax.naming.Context;
 import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Service;
 import javax.xml.ws.WebServiceRef;
@@ -33,6 +35,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Map;
 
 @WebServiceRef(name = "Service1")
@@ -60,7 +63,19 @@
    static TestEndpoint port3;
 
    static InitialContext iniCtx;
-   static Map<String, String> testResult = new HashMap<String, String>();
+   public static Map<String, String> testResult = new HashMap<String, String>();
+   
+   private static void setInitialCtx() throws NamingException
+   {
+      if (iniCtx == null)
+      {
+         InitialContext ctx = new InitialContext();
+         Hashtable env = ctx.getEnvironment();
+         env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
+         env.put("j2ee.clientName", "jbossws-client");
+         iniCtx = new InitialContext(env);
+      }
+   }
 
    public static void main(String[] args) throws Exception
    {
@@ -89,6 +104,7 @@
     */
    public String testService1(String reqStr) throws Exception
    {
+      setInitialCtx();
       TestEndpointService service = (TestEndpointService)org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.iniCtx.lookup("java:comp/env/Service1");
       TestEndpoint port = service.getTestEndpointPort();
       return port.echo(reqStr);
@@ -99,6 +115,7 @@
     */
    public String testService2(String reqStr) throws Exception
    {
+      setInitialCtx();
       Service service = (Service)org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.iniCtx.lookup("java:comp/env/Service2");
 
       TestEndpoint port = service.getPort(TestEndpoint.class);
@@ -115,6 +132,7 @@
       TestEndpoint port = ((TestEndpointService)org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.service3).getTestEndpointPort();
       String resStr1 = port.echo(reqStr);
 
+      setInitialCtx();
       TestEndpointService service = (TestEndpointService)org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.iniCtx.lookup("java:comp/env/Service3");
       port = service.getTestEndpointPort();
 
@@ -132,6 +150,7 @@
       String resStr1 = port.echo(reqStr);
       //verifyConfig((ConfigProvider)port);
 
+      setInitialCtx();
       TestEndpointService service = (TestEndpointService)org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.iniCtx.lookup("java:comp/env/Service4");
       port = service.getTestEndpointPort();
       //verifyConfig((ConfigProvider)port);
@@ -146,6 +165,7 @@
     */
    public String testPort1(String reqStr) throws Exception
    {
+      setInitialCtx();
       TestEndpoint port = (TestEndpoint)org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.iniCtx.lookup("java:comp/env/Port1");
       //verifyConfig((ConfigProvider)port);
 
@@ -160,6 +180,7 @@
       //verifyConfig((ConfigProvider)port2);
       String resStr1 = org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.port2.echo(reqStr);
 
+      setInitialCtx();
       TestEndpoint port = (TestEndpoint)org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.iniCtx.lookup("java:comp/env/Port2");
       //verifyConfig((ConfigProvider)port);
 
@@ -178,6 +199,7 @@
       BindingProvider bp = (BindingProvider)org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.port3;
       verifyProperties(bp.getRequestContext());
 
+      setInitialCtx();
       TestEndpoint port = (TestEndpoint)org.jboss.test.ws.jaxws.webserviceref.TestEndpointClientTwo.iniCtx.lookup("java:comp/env/Port3");
       String resStr2 = port.echo(reqStr);
 




More information about the jbossws-commits mailing list