wood burning stoves*
The moose likes Testing and the fly likes How to Junit test a servlet method which has multipart form request. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to Junit test a servlet method which has multipart form request." Watch "How to Junit test a servlet method which has multipart form request." New topic
Author

How to Junit test a servlet method which has multipart form request.

Ravish Srivastava
Greenhorn

Joined: Sep 05, 2011
Posts: 23

Hi,

I have a method "doUploadFile(request, response)". This method accept multipart form request from a JSP file and save the file uploaded into to a local directory say C:/uploaded.

My Requiremnt is to Junit test doUploadFile() method.

How can I achieve this?

Help..


Thanks & Regards,
RS
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Do you want to mock it out or call a framework that simulates the real behavior?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ravish Srivastava
Greenhorn

Joined: Sep 05, 2011
Posts: 23
I want to write a Java code which calls my "doUploadFile(request, response)" method. I want to construct a Multipart request so that I can pass to doUploadFile().
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

It sounds like you'd want a mock one then. You could write a class that extends it. Or use a mock one that already exists like Spring's MockMultipartHttpServletRequest.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Junit test a servlet method which has multipart form request.
 
Similar Threads
Uploading Image file from client to the server
request content length question
file uploading
form to upload files
uploading of file from one server to another using java or servlets