jakarta-watchdog-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-watchdog-4.0/src/server/servlet-tests/WEB-INF/classes/tests/javax_servlet/ServletRequest GetContentLengthTestServlet.java
Date Sun, 17 Dec 2000 04:36:15 GMT
craigmcc    00/12/16 20:36:15

  Modified:    src/conf servlet-gtest.xml
               src/server/servlet-tests/WEB-INF/classes/tests/javax_servlet/ServletRequest
                        GetContentLengthTestServlet.java
  Log:
  Update this test to actually send content bytes, and then verify that both
  the correct number of bytes, and the correct characters themselves, were
  received.
  
  Revision  Changes    Path
  1.14      +4 -4      jakarta-watchdog-4.0/src/conf/servlet-gtest.xml
  
  Index: servlet-gtest.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-watchdog-4.0/src/conf/servlet-gtest.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- servlet-gtest.xml	2000/12/17 03:40:36	1.13
  +++ servlet-gtest.xml	2000/12/17 04:36:14	1.14
  @@ -415,11 +415,11 @@
              debug="0" host="${host}" port="${port}" 
              goldenFile="${wgdir}/javax_servlet/ServletRequest/ServletRequestGetCharacterEncoding_1Test.html"
/>
   
  -<!-- FIXME - Causes hang because content length is set but no content sent
         <gtest request="GET /servlet-tests/GetContentLengthTest HTTP/1.0"
  -           debug="0" host="${host}" port="${port}" requestHeaders="Content-Type:text/plain##Content-Length:20"

  -           goldenFile="${wgdir}/javax_servlet/ServletRequest/GetContentLengthTest.html"
/>
  --->
  +               debug="0" host="${host}" port="${port}"
  +      requestHeaders="Content-Type:text/plain"
  +             content="ULTRA SPARC"
  +          goldenFile="${wgdir}/javax_servlet/ServletRequest/GetContentLengthTest.html"
/>
   
         <gtest request="GET /servlet-tests/GetContentTypeTest HTTP/1.0"
              debug="0" host="${host}" port="${port}" requestHeaders="Content-Type:text/plain"

  
  
  
  1.2       +33 -28    jakarta-watchdog-4.0/src/server/servlet-tests/WEB-INF/classes/tests/javax_servlet/ServletRequest/GetContentLengthTestServlet.java
  
  Index: GetContentLengthTestServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-watchdog-4.0/src/server/servlet-tests/WEB-INF/classes/tests/javax_servlet/ServletRequest/GetContentLengthTestServlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GetContentLengthTestServlet.java	2000/10/16 22:48:13	1.1
  +++ GetContentLengthTestServlet.java	2000/12/17 04:36:14	1.2
  @@ -1,6 +1,6 @@
   /*
  - * $Header: /home/cvs/jakarta-watchdog-4.0/src/server/servlet-tests/WEB-INF/classes/tests/javax_servlet/ServletRequest/GetContentLengthTestServlet.java,v
1.1 2000/10/16 22:48:13 santosh Exp $
  - * $Date: 2000/10/16 22:48:13 $
  + * $Header: /home/cvs/jakarta-watchdog-4.0/src/server/servlet-tests/WEB-INF/classes/tests/javax_servlet/ServletRequest/GetContentLengthTestServlet.java,v
1.2 2000/12/17 04:36:14 craigmcc Exp $
  + * $Date: 2000/12/17 04:36:14 $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -80,36 +80,41 @@
   	/**
   	 *	We get the content length using getContentLength and
   	 * 	we read from the input stream. if the no of chars read
  -	 * 	matches the no returned by getContentLength
  +	 * 	matches the number returned by getContentLength,
  +         *      and the actual content matches as well,
   	 *	we pass the test
   	 */
   
   	PrintWriter out = response.getWriter();
  +        ServletInputStream sins = request.getInputStream();
  +        String expectedResult = "ULTRA SPARC";
  +        int expectedLen = expectedResult.length();
  +        byte buffer[] = null;
  +	int contentLen = request.getContentLength();
  +        int actualLen = 0;
  +
  +        if (contentLen > 0) {
  +            buffer = new byte[contentLen];
  +            actualLen = sins.readLine(buffer, 0, buffer.length);
  +        } else {
  +            buffer = new byte[0];
  +            actualLen = 0;
  +        }
  +        String actualResult = new String(buffer, 0, actualLen);
  +
  +        if ((expectedLen == contentLen) &&
  +            (expectedLen == actualLen) &&
  +            expectedResult.equals(actualResult)) {
  +            out.println("GetContentLengthTest test PASSED");
  +        } else {
  +            out.println("GetContentLengthTest test FAILED");
  +            out.println("contentLen = " + contentLen);
  +            out.println("expectedLen = " + expectedLen +
  +                        ", actualLen = " + actualLen);
  +            out.println("expectedResult = " + expectedResult +
  +                        ", actualResult = " + actualResult);
  +        }
   
  -	// get the content length
  -	int contentLength = request.getContentLength();
  -	out.println("contentLength = " + contentLength );
  -
  -	int len=0;
  -	// getting input stream
  -
  -	ServletInputStream sin = request.getInputStream();
  -	// read from the stream
  -
  -	while(sin.read()!=-1) {
  -		len++;
  -	}
  -
  -	// did we get what we wrote
  -	out.println("len = " + len);
  -	if((contentLength==len) || (contentLength==-1)) {
  -		out.println("GetContentLengthTest test PASSED");
  -	}
  -	else {
  -		out.println("GetContentLengthTest test FAILED <BR> ");
  -		out.println("ServletRequest.getContentLength() method FAILED <BR> ");
  -		out.println("Expected Value returned -> contentLength <BR> ");
  -		out.println("Actual Value returned -> " + len);
  -	}
      }
  +
   }
  
  
  

Mime
View raw message