[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/transport/web ...

Ron Sigal ron_sigal at yahoo.com
Wed Oct 31 23:41:22 EDT 2007


  User: rsigal  
  Date: 07/10/31 23:41:22

  Modified:    src/tests/org/jboss/test/remoting/transport/web  Tag:
                        remoting_2_x WebInvokerTestClient.java
  Log:
  JBREM-675:  Runs POST tests in "raw" and "non-raw" mode.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.13.4.3  +74 -32    JBossRemoting/src/tests/org/jboss/test/remoting/transport/web/WebInvokerTestClient.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WebInvokerTestClient.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/web/WebInvokerTestClient.java,v
  retrieving revision 1.13.4.2
  retrieving revision 1.13.4.3
  diff -u -b -r1.13.4.2 -r1.13.4.3
  --- WebInvokerTestClient.java	11 Oct 2007 05:11:31 -0000	1.13.4.2
  +++ WebInvokerTestClient.java	1 Nov 2007 03:41:22 -0000	1.13.4.3
  @@ -23,12 +23,14 @@
   package org.jboss.test.remoting.transport.web;
   
   import junit.framework.TestCase;
  +
  +import org.apache.log4j.Logger;
   import org.jboss.remoting.Client;
   import org.jboss.remoting.InvokerLocator;
   import org.jboss.remoting.transport.http.HTTPMetadataConstants;
  +import org.jboss.remoting.transport.http.WebServerError;
   import org.jboss.remoting.transport.web.WebUtil;
   
  -import java.io.IOException;
   import java.util.HashMap;
   import java.util.Map;
   import java.util.Properties;
  @@ -38,10 +40,22 @@
    */
   public abstract class WebInvokerTestClient extends TestCase
   {
  +   protected static Logger log = Logger.getLogger(WebInvokerTestClient.class);
  +   
      public abstract String getLocatorURI();
   
      public void testPostInvocation() throws Exception
      {
  +      testPostInvocationSub(true);
  +      testPostInvocationSub(false);
  +   }
  +   
  +   /**
  +    * If raw == true, set content-type appropriately.
  +    * If raw == false, all content will be binary and well be treated as binary.
  +    */
  +   public void testPostInvocationSub(boolean raw) throws Exception
  +   {
         Client remotingClient = null;
   
         try
  @@ -52,18 +66,31 @@
            remotingClient = new Client(locator);
            remotingClient.connect();
   
  +         Map metadata = new HashMap();
  +         
  +         if (raw)
  +         {
  +
            // The following use of two versions of Client.RAW is to account for the
            // fact that the value of Client.RAW changed from Remoting 1.4.x to
            // Remoting 2.0.0.  This test is used as part of the version compatibility
            // test suite.  Yuck.
  -         Map metadata = new HashMap();
  -//         metadata.put(Client.RAW, Boolean.TRUE);
            metadata.put("rawPayload", Boolean.TRUE);
            metadata.put("RAW_PAYLOAD", Boolean.TRUE);
  +         }
  +         
            metadata.put("TYPE", "POST");
   
            Properties headerProps = new Properties();
  +         
  +         if (raw)
  +         {
            headerProps.put("Content-Type", "application/soap+xml");
  +         }
  +         else
  +         {
  +            headerProps.put("Content-Type", WebUtil.BINARY);
  +         }
   
            addHeaders(headerProps);
   
  @@ -80,7 +107,10 @@
            System.out.println("Second response should be " + WebInvocationHandler.HTML_PAGE_RESPONSE + " and was: " + response);
            assertEquals(WebInvocationHandler.HTML_PAGE_RESPONSE, response);
   
  +         if (raw)
  +         {
            headerProps.put("Content-Type", WebUtil.BINARY);
  +         }
            response = remotingClient.invoke(new ComplexObject(2, "foo", true), metadata);
            System.out.println("Third response should be " + WebInvocationHandler.OBJECT_RESPONSE_VALUE + " and was: " + response);
            assertEquals(WebInvocationHandler.OBJECT_RESPONSE_VALUE, response);
  @@ -89,18 +119,22 @@
            System.out.println("Fourth response should be " + WebInvocationHandler.LARGE_OBJECT_RESPONSE_VALUE + " and was: " + response);
            assertEquals(WebInvocationHandler.LARGE_OBJECT_RESPONSE_VALUE, response);
   
  +         if (raw)
  +         {
            headerProps.put("Content-Type", "application/soap+xml");
  +         }
            response = remotingClient.invoke(WebInvocationHandler.STRING_RETURN_PARAM, metadata);
            System.out.println("Fifth response should be " + WebInvocationHandler.RESPONSE_VALUE + " and was: " + response);
            assertEquals(WebInvocationHandler.RESPONSE_VALUE, response);
   
            checkUserAgent(remotingClient, metadata);
   
  -         makeExceptionInvocation(remotingClient, metadata);
  -
            remotingClient.invokeOneway("Do something", metadata, true);
   
            remotingClient.invokeOneway("Do something", metadata, false);
  +         
  +         makeExceptionInvocation(remotingClient, metadata);
  +         
         }
         catch (Throwable throwable)
         {
  @@ -113,8 +147,6 @@
               remotingClient.disconnect();
            }
         }
  -
  -
      }
   
      protected void checkUserAgent(Client remotingClient, Map metadata)
  @@ -136,26 +168,28 @@
   
         try
         {
  -         System.out.println("making exception invocation");
  +         log.info("making exception invocation");
            response = remotingClient.invoke(WebInvocationHandler.THROW_EXCEPTION_PARAM, metadata);
            assertTrue("Should have thrown WebServerError and not made it to here.", false);
         }
         catch (Exception error)
         {
  -         System.out.println("exception: " + error + " " + error.getMessage());
  +         log.info("exception: " + error + " " + error.getMessage());
            // having to check class name instead of just catching type WebServerError so
            // can use for backwards compatibility tests since WebServerError is new since 2.0.0.CR1.
   
  -         if (getLocatorURI().indexOf("return-exception=true") == -1)
  +         if (getLocatorURI().indexOf("dont-return-exception=true") >= 0)
            {
  -            if (error.getClass().getName().endsWith("WebServerError"))
  -            {
  -               assertTrue(true);
  -            }
  -            else
  -            {
  -               assertTrue("Did not get WebServerError thrown as expected", false);
  -            }
  +            assertTrue("Did not get WebServerError", error instanceof WebServerError);
  +            assertNotNull(error.getMessage());
  +            assertTrue(error.getMessage().indexOf("Error occurred processing invocation request. ") >= 0);
  +         }
  +         else if (Boolean.TRUE.equals(metadata.get("rawPayload")) ||
  +                  Boolean.TRUE.equals(metadata.get("RAW_PAYLOAD")))
  +         {
  +            assertTrue("Did not get WebServerError", error instanceof WebServerError);
  +            assertNotNull(error.getMessage());
  +            assertTrue(error.getMessage().startsWith("Error received when calling on web server."));
            }
            else
            {
  @@ -167,18 +201,25 @@
         response = remotingClient.invoke(WebInvocationHandler.THROW_EXCEPTION_PARAM, metadata);
         if (response instanceof Exception)
         {
  -         System.out.println("Return from invocation is of type Exception as expected.");
  +         log.info("Return from invocation is of type Exception as expected.");
            assertTrue("Received exception return as expected.", true);
         }
         else
         {
  -         System.out.println("Did not get Exception type returned as expected.");
  +         log.info("Did not get Exception type returned as expected.");
            assertTrue("Should have received Exception as return.", false);
         }
  +      metadata.remove(HTTPMetadataConstants.NO_THROW_ON_ERROR);
      }
   
      public void testGetInvocation() throws Exception
      {
  +      testGetInvocationSub(true);
  +      testGetInvocationSub(false);
  +   }
  +   
  +   protected void testGetInvocationSub(boolean raw) throws Exception
  +   {
         Client remotingClient = null;
   
         try
  @@ -190,7 +231,10 @@
            remotingClient.connect();
   
            Map metadata = new HashMap();
  +         if (raw)
  +         {
            metadata.put(Client.RAW, Boolean.TRUE);
  +         }
            metadata.put("TYPE", "GET");
   
            Object response = null;
  @@ -215,8 +259,6 @@
               remotingClient.disconnect();
            }
         }
  -
  -
      }
   
      protected void addHeaders(Properties headerProps)
  
  
  



More information about the jboss-cvs-commits mailing list