[Httpunit-commit] SF.net SVN: httpunit:[1087] trunk/httpunit/src
Brought to you by:
russgold
|
From: <wol...@us...> - 2012-09-12 13:26:54
|
Revision: 1087
http://httpunit.svn.sourceforge.net/httpunit/?rev=1087&view=rev
Author: wolfgang_fahl
Date: 2012-09-12 13:26:44 +0000 (Wed, 12 Sep 2012)
Log Message:
-----------
add checks for InvocationContextFactory - clearly ServletAccessTest can not be run on it's own with this change
Modified Paths:
--------------
trunk/httpunit/src/main/java/com/meterware/servletunit/ServletTestCase.java
trunk/httpunit/src/main/java/com/meterware/servletunit/ServletUnitClient.java
trunk/httpunit/src/test/java/com/meterware/servletunit/HttpServletRequestTest.java
trunk/httpunit/src/test/java/com/meterware/servletunit/JUnitServletTest.java
trunk/httpunit/src/test/java/com/meterware/servletunit/ServletAccessTest.java
Modified: trunk/httpunit/src/main/java/com/meterware/servletunit/ServletTestCase.java
===================================================================
--- trunk/httpunit/src/main/java/com/meterware/servletunit/ServletTestCase.java 2012-09-12 12:21:19 UTC (rev 1086)
+++ trunk/httpunit/src/main/java/com/meterware/servletunit/ServletTestCase.java 2012-09-12 13:26:44 UTC (rev 1087)
@@ -30,20 +30,31 @@
abstract
public class ServletTestCase extends TestCase {
+ /**
+ * construct a ServletTestCase with the given name
+ * @param name
+ */
protected ServletTestCase( String name ) {
super( name );
}
-
/**
* Returns a client object which can access the servlet context in which this test is running.
*/
final protected ServletUnitClient newClient() {
+ if (_invocationContextFactory==null)
+ throw new RuntimeException("ServletTestCase.newClient called before setInvocationContextFactory was called");
return ServletUnitClient.newClient( _invocationContextFactory );
}
+ /**
+ * set the invocation context factory to be used
+ * @param invocationContextFactory
+ */
static void setInvocationContextFactory( InvocationContextFactory invocationContextFactory ) {
+ if (invocationContextFactory==null)
+ throw new RuntimeException("setInvocationContextFactory called with null invocationContextFactory parameter");
_invocationContextFactory = invocationContextFactory;
}
Modified: trunk/httpunit/src/main/java/com/meterware/servletunit/ServletUnitClient.java
===================================================================
--- trunk/httpunit/src/main/java/com/meterware/servletunit/ServletUnitClient.java 2012-09-12 12:21:19 UTC (rev 1086)
+++ trunk/httpunit/src/main/java/com/meterware/servletunit/ServletUnitClient.java 2012-09-12 13:26:44 UTC (rev 1087)
@@ -45,6 +45,10 @@
public class ServletUnitClient extends WebClient {
+ private ServletUnitClient() {
+ throw new RuntimeException("ServletUnitClient constructor needs InvocationContextFactory parameter");
+ }
+
/**
* Creates and returns a new servlet unit client instance.
**/
@@ -77,8 +81,18 @@
}
+ /**
+ * get a new Invocation Context based on a request and a frame
+ * @param request
+ * @param frame
+ * @return
+ * @throws IOException
+ * @throws MalformedURLException
+ */
InvocationContext newInvocation( WebRequest request, FrameSelector frame ) throws IOException, MalformedURLException {
ByteArrayOutputStream baos = getMessageBody( request );
+ if (_invocationContextFactory==null)
+ throw new RuntimeException("newInvocation called with null _invocationContextFactory");
return _invocationContextFactory.newInvocation( this, frame, request, getHeaderFields( request.getURL() ), baos.toByteArray() );
}
@@ -141,6 +155,8 @@
private ServletUnitClient( InvocationContextFactory factory ) {
+ if (factory==null)
+ throw new RuntimeException("constructor for ServletUnitClient called with null factory parameter");
_invocationContextFactory = factory;
}
}
Modified: trunk/httpunit/src/test/java/com/meterware/servletunit/HttpServletRequestTest.java
===================================================================
--- trunk/httpunit/src/test/java/com/meterware/servletunit/HttpServletRequestTest.java 2012-09-12 12:21:19 UTC (rev 1086)
+++ trunk/httpunit/src/test/java/com/meterware/servletunit/HttpServletRequestTest.java 2012-09-12 13:26:44 UTC (rev 1087)
@@ -20,6 +20,7 @@
*
*******************************************************************************************************************/
+import com.meterware.httpunit.FrameSelector;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.HttpUnitOptions;
import com.meterware.httpunit.HttpUnitUtils;
@@ -38,9 +39,11 @@
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Date;
+import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
@@ -788,7 +791,16 @@
assertEquals("param1 value", "red", request.getParameter("param1"));
assertEquals("param2 value", hebrewValue, request.getParameter("param2"));
}
+
+ private InvocationContextFactory _dummyfactory = new InvocationContextFactory() {
+ public InvocationContext newInvocation( ServletUnitClient client, FrameSelector targetFrame, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
+ return new InvocationContextImpl( client, null, targetFrame, request, clientHeaders, messageBody );
+ }
+ public HttpSession getSession( String sessionId, boolean create ) {
+ return _context.getValidSession( sessionId, null, create );
+ }
+ };
@Test
public void testSpecifiedCharEncoding2() throws Exception {
@@ -798,7 +810,7 @@
wr.setParameter("param1", "red");
wr.setParameter("param2", hebrewValue);
wr.setHeaderField("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-8");
- ServletUnitClient client = ServletUnitClient.newClient(null);
+ ServletUnitClient client = ServletUnitClient.newClient(_dummyfactory);
ByteArrayOutputStream messageBody = client.getMessageBody(wr);
ServletUnitHttpRequest request = new ServletUnitHttpRequest(NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), messageBody.toByteArray());
String parameter = request.getParameter("param2");
Modified: trunk/httpunit/src/test/java/com/meterware/servletunit/JUnitServletTest.java
===================================================================
--- trunk/httpunit/src/test/java/com/meterware/servletunit/JUnitServletTest.java 2012-09-12 12:21:19 UTC (rev 1086)
+++ trunk/httpunit/src/test/java/com/meterware/servletunit/JUnitServletTest.java 2012-09-12 13:26:44 UTC (rev 1087)
@@ -247,7 +247,7 @@
}
- static class MyFactory implements InvocationContextFactory {
+ protected static class MyFactory implements InvocationContextFactory {
private static ServletRunner _runner;
public InvocationContext newInvocation(ServletUnitClient client, FrameSelector targetFrame, WebRequest request, Dictionary clientHeaders, byte[] messageBody) throws IOException, MalformedURLException {
Modified: trunk/httpunit/src/test/java/com/meterware/servletunit/ServletAccessTest.java
===================================================================
--- trunk/httpunit/src/test/java/com/meterware/servletunit/ServletAccessTest.java 2012-09-12 12:21:19 UTC (rev 1086)
+++ trunk/httpunit/src/test/java/com/meterware/servletunit/ServletAccessTest.java 2012-09-12 13:26:44 UTC (rev 1087)
@@ -31,6 +31,10 @@
*/
public class ServletAccessTest extends ServletTestCase {
+ /**
+ * construct a ServletAccessTest
+ * @param name
+ */
public ServletAccessTest(String name) {
super(name);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|