vmassol     2005/05/06 05:22:24

  Modified:    
samples/servlet/src/test-cactus/share/org/apache/cactus/sample/servlet/unit
                        TestHttpRequest.java
  Log:
  Added test/sample showing how to pass a Java Object in beginXXX to the 
server-side.
  
  Revision  Changes    Path
  1.4       +48 -5     
jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/servlet/unit/TestHttpRequest.java
  
  Index: TestHttpRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/servlet/unit/TestHttpRequest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestHttpRequest.java      29 Feb 2004 16:36:44 -0000      1.3
  +++ TestHttpRequest.java      6 May 2005 12:22:24 -0000       1.4
  @@ -21,7 +21,11 @@
   
   import java.io.BufferedReader;
   import java.io.ByteArrayInputStream;
  +import java.io.ByteArrayOutputStream;
   import java.io.File;
  +import java.io.InputStream;
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   
   import org.apache.cactus.ServletTestCase;
   import org.apache.cactus.WebRequest;
  @@ -78,12 +82,13 @@
       
//-------------------------------------------------------------------------
   
       /**
  -     * Verify that we can send arbitrary data in the request body.
  +     * Verify that we can send arbitrary data in the request body and read 
the
  +     * data back on the server side using a Reader.
        *
        * @param theRequest the request object that serves to initialize the
        *                   HTTP connection to the server redirector.
        */
  -    public void beginSendUserData(WebRequest theRequest)
  +    public void beginSendUserDataAndReadWithReader(WebRequest theRequest)
       {
           ByteArrayInputStream bais = new ByteArrayInputStream(
               "<data>some data to send in the body</data>".getBytes());
  @@ -93,11 +98,12 @@
       }
   
       /**
  -     * Verify that we can send arbitrary data in the request body.
  +     * Verify that we can send arbitrary data in the request body and read 
the
  +     * data back on the server side using a Reader.
        * 
        * @exception Exception on test failure
        */
  -    public void testSendUserData() throws Exception
  +    public void testSendUserDataAndReadWithReader() throws Exception
       {
           String buffer;
           StringBuffer body = new StringBuffer();
  @@ -117,6 +123,43 @@
       
//-------------------------------------------------------------------------
   
       /**
  +     * Verify that we can send arbitrary data in the request body and read 
the
  +     * data back on the server side using an ObjectInputStream.
  +     *
  +     * @param theRequest the request object that serves to initialize the
  +     *                   HTTP connection to the server redirector.
  +     * @exception Exception on test failure
  +     */
  +    public void beginSendUserDataAndReadWithObjectInputStream(
  +        WebRequest theRequest) throws Exception
  +    {
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream();        
  +        ObjectOutputStream oos = new ObjectOutputStream(baos);
  +        oos.writeObject("Test with a String object");
  +        oos.flush();
  +
  +        theRequest.setUserData(new ByteArrayInputStream(baos.toByteArray()));
  +        theRequest.setContentType("application/octet-stream");
  +    }
  +
  +    /**
  +     * Verify that we can send arbitrary data in the request body and read 
the
  +     * data back on the server side using an ObjectInputStream.
  +     * 
  +     * @exception Exception on test failure
  +     */
  +    public void testSendUserDataAndReadWithObjectInputStream() throws 
Exception
  +    {
  +        InputStream in = request.getInputStream();
  +        ObjectInputStream  ois = new ObjectInputStream(in);
  +        String data = (String) ois.readObject();
  +        assertNotNull(data);
  +        assertEquals("Test with a String object", data);
  +    }
  +
  +    
//-------------------------------------------------------------------------
  +
  +    /**
        * Verify that we can simulate the client remote IP address and the 
client
        * remote host name.
        */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to