I recently dealt with this. You can manually retrieve the action and set
the FileBean value on the action class within your unit test. If you are
planning to use and test annotation based validation then you will be out
of luck. You can't do it. I had a required file in my app. I wound up using
manual validation inside the handler method rather than annotations.
So you wind up doing something like this:
----
MockServletContext ctx = getServletContext(); // context instance
MockRoundtrip trip = new MockRoundtrip(ctx, FormAction.class);
FormAction action = trip.getActionBean();
action.setFile(...);// set file bean manually
trip.execute("saveImage");
----
Unfortunately it subverts testing through the standard stripes workflow for
this specific case and it subverts annotation based validation for the
FileBean. But, it's not really that big of a deal. In the end all you lose
is the annotations. This is currently the best workaround until the
stripes team introduces something to allow for FileBean mocking.
Just as an FYI, I made an attempt to dig deep and mess with the request
content type so that I could make the request a Mulipart-form. But, the
MockHttpServletRequest always returns null for the content type.
http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/mock/MockHttpServletRequest.html#getContentType()
I believe there is a bug fix/enhancement request for this.
Brandon
On Tue, Sep 3, 2013 at 6:07 AM, - <grandebu...@gmail.com> wrote:
> Hi,
>
> Can someone help me how to use Unit Test with stripes FileBean submit ?
>
> I have:
>
> //FormAction.class
>
> public FileBean file; public FileBean getFile() { return file; } public
> void setFile(FileBean file) { this.file = file; }
>
>
> //Test.class
>
> MockServletContext ctx = getServletContext(); // context instance
> MockRoundtrip trip = new MockRoundtrip(ctx, FormAction.class);
>
> trip.addParameter("file", "D:/workspace/webproject/img.jpg"); // image
> exist
>
> trip.execute("saveImage");
>
>
> On saveImage event (FormAction.class) I have file null.
>
> Thanks in advance
>
>
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users