I'm trying to figure out the best way to write unit tests for Spring's WebService Template classes. What I'm trying to do is check to make sure that I wired these classes up correctly for each request/response type that my client is producing. I also want to make sure that if an exception is returned the exception is handled correctly.
I guess what I'm trying to do is figure out a way to make the actual send/receive calls.
Any suggestions?
The assert section ensures that the code behaves as expected. Assertions replace us humans in checking that the software does what it should. They express requirements that the unit under test is expected to meet. Now, often one can write slightly different assertions to capture a given requirement.
I'm going to be tacky and answer my own question.
After a little further research I found that Spring WS 2.0 has a new client testing framework that does exactly what I was hoping to do (from http://blog.springsource.com/2011/01/11/spring-web-services-2-0-released/):
The core class for doing client-side integration testing is the MockWebServiceServer. The underlying idea is that the web service template connects to this mock server, sends it request message, which the mock server then verifies against the registered expectations. If the expectations are met, the mock server then prepares a response message, which is send back to the template.
The typical scenario of testing client-side code consists of:
- Creating a MockWebServiceServer.
- Setting up expectation(s) about the request message.
- Creating an appropriate response message
- Using the WebServiceTemplate as normal, either directly of through client code.
- Call MockWebServiceServer.verify() to make sure that all expectations have been met.
Now unfortunately my project still uses spring-ws 1.5.9. I'm going to try and upgrade just the client to 2.0 and see if anything breaks. If that goes well I might try switching over the server side soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With