File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Testing multipart submit in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Testing multipart submit in jsp" Watch "Testing multipart submit in jsp" New topic
Author

Testing multipart submit in jsp

Robin Clark
Ranch Hand

Joined: Dec 17, 2003
Posts: 81
I am very new to jsp and java testing in general. I have written a jsp that will be used as part of a VoiceXML application. This jsp receives some parameters that are strings from a VoiceXML page along with a parameter that is an audio file. The jsp creates a directory structure based upon the values of the string parameter, then it constructs a filename with a date stamp, then it saves the audio using an oreilly multipart bean.
It seems to work well, but now I am wondering how I could have tested it at the unit level? I will need to do this again and I would like to learn how to test jsp code correctly.
Here is the jsp in question:

Thank you for any advice you have about unit testing jsp code!
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You could use HttpUnit or Cactus for sending the multipart HTTP POST request and then, somehow, verify that the file appeared in the correct place.
It's not really unit testing but functional testing, though. I would still consider extracting everything you can into helper classes which can be tested in isolation without a web container. Divide and conquer...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Lasse is correct - your JSP should be as dumb as possible. Put all the logic into POJOs (plain old java objects) and test them using vanilla JUnit.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Testing multipart submit in jsp