I am trying write a junit style test to invoke a Struts 2 action class, using Spring 2.5. I have been given a message body of an HTTP Post request that will be sent to our web site from an external source. This message body is plain text exactly of the Post request itself. I want to write a test against this.
I have been looking at the different Java web testing frameworks like JWebUnit, HtmlUnit and HttpUnit but none seem to do what I want.
I do not want either:
What I want is:
where myMessageBody is a plain-text concatenation of all the fields, which my test (Tomcat / Struts / Spring) has to unpack and deal with. Why do I want it this way? Because that is the API specification I am given and what I must program against.
Change the requirement--you're now testing the web server, Struts 2, *and* your code. The purpose of unit testing is to test small, standalone units, that (hopefully) don't depend on too many other things. Besides--you'd have to run that unit test inside a container: Struts 2 uses the container's request processing to access request parameters.
This is almost certainly not what you want to do.
Joined: May 26, 2004
Yes I understand that. But I am specifically given a text file which is exactly what the Post request will look like. I need to test directly against this text file that contains all the fields. I have other unit tests that test isolated parts. But I really need this automated acceptance test that says "send this Post message text to me (to simulate a page transmission over the net) and I will respond correctly". How can I do this?
You'll still need to either run the test against a running container (an integration test), or simulate everything up to the point of the action request. IMO this isn't a good way to do this, since you're basically testing the app server. That's a slippery slope. If you're that uncomfortable with your app server, I'd consider maybe using a different one.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Simulation of HTTP Post request with message body