[
http://jira.jboss.com/jira/browse/JBSEAM-2982?page=comments#action_12412606 ]
Tom N commented on JBSEAM-2982:
-------------------------------
Hi Shane,
You're right, after looking through things again, the errors were occurring when the
first getParameter method was called -- it looks like it internally calls getHeader,
getContentType, and begins parsing the request body for the mime boundary. This is what
was causing me problems -- because I was putting the mock getParameter() calls on my inner
HttpServletRequest, but the MultipartRequest was still trying to parse a MIME request
body. I was able to get around it by putting the mock behavior back on the
MultipartRequest like so:
{{{
Properties requestProperties = ...
byte[] uploadFile = ...
HttpServletRequest req = createMock( HttpServletRequest.class );
MultipartRequest mpRequest = new MultipartRequest( req, false, Integer.MAX_VALUE ) {
@Override public String getParameter(String name) {
return requestProperties.getProperty(name);
}
@Override public byte[] getFileBytes(String name) {
if ( name == "LOGFILE" ) return uploadFile;
throw new IllegalArgumentException( "Unepected file request: " + name );
}
};
}}}
...Apologies if the code is all inline -- JIRA is not giving me a preview button for my
comment.
So is this the best way to mock a MultipartRequest? It would still be nice if the inner
mock HttpServletRequest was not necessary.
Give MultipartRequest constructor to support unit testing
---------------------------------------------------------
Key: JBSEAM-2982
URL:
http://jira.jboss.com/jira/browse/JBSEAM-2982
Project: Seam
Issue Type: Feature Request
Components: Core
Affects Versions: 2.1.0.A1, 2.0.1.GA
Environment: N/A
Reporter: Tom N
Assigned To: Shane Bryzak
Fix For: 2.1.0.BETA1
MultipartRequest cannot easily be mocked for unit testing. This could be solved by (1)
making that type into an interface, or (2) changing the constructor so that the wrapped
HttpServletRequest body is not parsed when the constructor is invoked. See the forum link
for more details.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira