Update: Spring WS 2.0 contains support for both server side and client side testing. If you are using Spring WS 2, use that. If you are Axis2, CXF or Metro user, take a look at Smock library.
Do you need to test you web-service client layer? Do you wan to run your end-to-end test without having to set-up a mock server? Do you want to simplify your server side tests? Spring WS Test is here to help you.
Spring WS Test project simplifies functional testing of Spring WS client applications. It allows you to write functional tests that can run in one JVM, that can use JUnit or TestNG, that are simple to set-up and configure. Yet this type of tests is quite powerful and you can test most of your configuration and component integration.
This project can be used mainly in the following scenarios:
If you are looking for server side testing, please go here. Following sections are about WS client tests.
<dependency> <groupId>net.javacrumbs</groupId> <artifactId>spring-ws-test</artifactId> <version>0.22</version> </dependency>
@RunWith(SpringJUnit4ClassRunner.class) //load your standard Spring configuration @ContextConfiguration(locations={"classpath:spring/applicationContext.xml"}) //Add the listener @TestExecutionListeners({WsMockControlTestExecutionListener.class, DependencyInjectionTestExecutionListener.class}) public class AirlineWsClient4Test { //inject the class under the test @Autowired private AirlineWsClient client; //inject mock control @Autowired private WsMockControl mockControl; @Test public void testCall() { //teach mock what to do mockControl.expectRequest("expected-request.xml") .returnResponse("response-to-be-returned.xml"); //call WS client code long ticketId = client.bookFlight(input,params,here); assertEquals(123456L, ticketId); //verify all the calls mockControl.verify(); } }
If you need more functional test style configuration, please read functional test reference.
Note: I really want to hear your feedback. The project is in very early stage so you have unique opportunity to drive its development. If you find a bug, please report it in project JIRA. If you encounter any issue, do not hesitate and contact me on lukas at krecan dot net. If you like it, please let me now on my blog