[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit HttpServletRequestTest.java,1.9,1.10
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-01-03 16:12:38
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv18497/test/com/meterware/servletunit
Modified Files:
HttpServletRequestTest.java StatelessTest.java
Log Message:
miscellaneous servletunit enhancments
Index: HttpServletRequestTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HttpServletRequestTest.java 25 Oct 2002 00:19:25 -0000 1.9
+++ HttpServletRequestTest.java 3 Jan 2003 16:12:35 -0000 1.10
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2003 by Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -38,6 +38,8 @@
/**
* Tests the ServletUnitHttpRequest class.
+ *
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class HttpServletRequestTest extends ServletUnitTest {
@@ -53,6 +55,25 @@
public HttpServletRequestTest( String name ) {
super( name );
+ }
+
+
+ public void testHeaderAccess() throws Exception {
+ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
+ wr.setHeaderField( "sample", "value" );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ assertEquals( "sample header value", "value", request.getHeader( "sample") );
+
+ assertContains( "Header names", "sample", request.getHeaderNames() );
+ }
+
+
+ private void assertContains( String comment, String string, Enumeration headerNames ) {
+ while (headerNames != null && headerNames.hasMoreElements()) {
+ String name = (String) headerNames.nextElement();
+ if (name.equalsIgnoreCase( string )) return;
+ }
+ fail( comment + " does not contain " + string );
}
Index: StatelessTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatelessTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- StatelessTest.java 22 Aug 2002 20:18:32 -0000 1.9
+++ StatelessTest.java 3 Jan 2003 16:12:35 -0000 1.10
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2000-2002, Russell Gold
+ * Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -42,6 +42,8 @@
/**
* Tests support for stateless HttpServlets.
+ *
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class StatelessTest extends TestCase {
@@ -76,12 +78,17 @@
public void testServletCaching() throws Exception {
final String resourceName = "something/interesting";
+ assertEquals( "Initial instances of servlet class", 0, AccessCountServlet.getNumInstances() );
ServletRunner sr = new ServletRunner();
sr.registerServlet( resourceName, AccessCountServlet.class.getName() );
WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName );
assertEquals( "First reply", "1", sr.getResponse( request ).getText().trim() );
+ assertEquals( "Instances of servlet class after first call", 1, AccessCountServlet.getNumInstances() );
assertEquals( "Second reply", "2", sr.getResponse( request ).getText().trim() );
+ assertEquals( "Instances of servlet class after first call", 1, AccessCountServlet.getNumInstances() );
+ sr.shutDown();
+ assertEquals( "Instances of servlet class after shutdown", 0, AccessCountServlet.getNumInstances() );
}
@@ -218,6 +225,25 @@
static class AccessCountServlet extends HttpServlet {
private int _numAccesses;
+
+ private static int _numInstances = 0;
+
+
+ public void init() throws ServletException {
+ super.init();
+ _numInstances++;
+ }
+
+
+ public void destroy() {
+ super.destroy();
+ _numInstances--;
+ }
+
+
+ public static int getNumInstances() {
+ return _numInstances;
+ }
protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
|