You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Hardy <ah...@cyberspaceroad.com> on 2008/03/31 19:04:38 UTC

testing file uploads

I need to test an action that is getting uploaded files and piping them straight 
into Strings. I don't want to save actual files on server, so I'll get the 
multipart request wrapper directly.

MultiPartRequestWrapper multiWrapper =
     (MultiPartRequestWrapper) ServletActionContext.getRequest()

I'm thinking of using HttpUnit and ServletUnit to set this stuff up. Has anyone 
set up Struts2 with ServletUnit?

By the way, has anyone used Mockito yet, the new mocking framework? 
http://code.google.com/p/mockito/


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: testing file uploads

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Just remembered struts2 isn't a servlet. I just wanted a quick and easy way of 
giving my action a real multipart request wrapper to run against. So tomorrow I 
guess I'll have to check out the MockMultipartRequestWrapper.

Thanks
Adam

Martin Gainty on 31/03/08 20:55, wrote:
> Have you looked at using Mock classes of MockHttpServletRequest(),
> MockHttpServletResponse(), MockServletContext()
> from
> org.apache.struts2.ServletActionContextTest.java
> 
> ?
> Martin
> ----- Original Message -----
> From: "Adam Hardy" <ah...@cyberspaceroad.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Monday, March 31, 2008 12:04 PM
> Subject: testing file uploads
> 
> 
>> I need to test an action that is getting uploaded files and piping them
> straight
>> into Strings. I don't want to save actual files on server, so I'll get the
>> multipart request wrapper directly.
>>
>> MultiPartRequestWrapper multiWrapper =
>>      (MultiPartRequestWrapper) ServletActionContext.getRequest()
>>
>> I'm thinking of using HttpUnit and ServletUnit to set this stuff up. Has
> anyone
>> set up Struts2 with ServletUnit?
>>
>> By the way, has anyone used Mockito yet, the new mocking framework?
>> http://code.google.com/p/mockito/


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: testing file uploads

Posted by Dave Newton <ne...@yahoo.com>.
--- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> I see the multipart http request as a weak point in the servlet spec. Or
> the http spec. But I want to test it for my own piece of mind, and when 
> I have the test finished, I guess I can work out if it's really necessary.

You want to test multipart HTTP requests? Well, okay; enjoy!

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: testing file uploads

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Dave Newton on 31/03/08 22:00, wrote:
> --- Adam Hardy <ah...@cyberspaceroad.com> wrote:
>> Dave Newton on 31/03/08 18:42, wrote:
>>> What, specifically, are you trying to test?
>> The action has to get strings out of the request, work out which file they
>> are from and call the appropriate managers, with the corresponding string 
>> as a request. There's logic in the action that basically has nothing to do 
>> with how the container handles it (I hope).
> 
> You're saying it's reading the file and deciding what to do based on file
> contents?
> 
> Well, either way, I'd still test that completely separately from any
> container/request stuff, but without your understanding of how it's working
> I'm mostly just babbling ;)

I see the multipart http request as a weak point in the servlet spec. Or the 
http spec. But I want to test it for my own piece of mind, and when I have the 
test finished, I guess I can work out if it's really necessary.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: testing file uploads

Posted by Dave Newton <ne...@yahoo.com>.
--- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> Dave Newton on 31/03/08 18:42, wrote:
> > What, specifically, are you trying to test?
> 
> The action has to get strings out of the request, work out which file they
> are from and call the appropriate managers, with the corresponding string 
> as a request. There's logic in the action that basically has nothing to do 
> with how the container handles it (I hope).

You're saying it's reading the file and deciding what to do based on file
contents?

Well, either way, I'd still test that completely separately from any
container/request stuff, but without your understanding of how it's working
I'm mostly just babbling ;)

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: testing file uploads

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Dave Newton on 31/03/08 18:42, wrote:
> --- Adam Hardy <ah...@cyberspaceroad.com> wrote:
>> I need to test an action that is getting uploaded files and piping them
>> straight into Strings. I don't want to save actual files on server, so I'll
> 
>> get the multipart request wrapper directly.
> 
> What, specifically, are you trying to test?
> 
> I ask because I've never had any particular reason to test file uploads
> inside the container, because the container itself should have already tested
> that and verified its operations. Everything else I've ever done with files
> has been testable outside the container.

The action has to get strings out of the request, work out which file they are 
from and call the appropriate managers, with the corresponding string as a 
request. There's logic in the action that basically has nothing to do with how 
the container handles it (I hope).



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: testing file uploads

Posted by Dave Newton <ne...@yahoo.com>.
--- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> I need to test an action that is getting uploaded files and piping them
> straight into Strings. I don't want to save actual files on server, so I'll

> get the multipart request wrapper directly.

What, specifically, are you trying to test?

I ask because I've never had any particular reason to test file uploads
inside the container, because the container itself should have already tested
that and verified its operations. Everything else I've ever done with files
has been testable outside the container.

I may have misunderstood what you're asking, though.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org