1 package de.spring.webservices.client;
3 import static org.junit.Assert.assertEquals;
4 import static org.springframework.ws.test.client.RequestMatchers.payload;
5 import static org.springframework.ws.test.client.ResponseCreators.withPayload;
7 import javax.xml.transform.Source;
9 import org.junit.Before;
10 import org.junit.Test;
11 import org.junit.runner.RunWith;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.test.context.ContextConfiguration;
14 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 import org.springframework.ws.client.core.WebServiceTemplate;
16 import org.springframework.ws.test.client.MockWebServiceServer;
17 import org.springframework.xml.transform.StringSource;
19 import de.spring.webservices.auto.CustomBindingExampleResponse;
20 import de.spring.webservices.auto.ExampleResponse;
23 @RunWith(SpringJUnit4ClassRunner.class)
24 @ContextConfiguration("classpath*:spring-configuration/ws/client-spring-configuration.xml")
25 public class ExampleClientServiceIntegrationTest {
28 ExampleClientService exampleClientService;
31 private WebServiceTemplate webServiceTemplate;
33 private MockWebServiceServer mockServer;
36 public void createServer() throws Exception {
37 mockServer = MockWebServiceServer.createServer(webServiceTemplate);
41 public void customerClient() throws Exception {
42 final Source requestPayload = new StringSource(
43 "<ExampleRequest xmlns='http://gumartinm.name/spring-ws/example'>"
44 + "<data>SCARLETT SPRING. IT IS CANON.</data>"
45 + "</ExampleRequest>");
46 final Source responsePayload = new StringSource(
47 "<ns2:ExampleResponse xmlns:ns2='http://gumartinm.name/spring-ws/example'>"
48 + "<ns2:data>SNAKE EYES AND SCARLETT SPRING. IT IS CANON.</ns2:data>"
49 + "</ns2:ExampleResponse>");
50 mockServer.expect(payload(requestPayload)).andRespond(
51 withPayload(responsePayload));
53 final ExampleResponse response = exampleClientService.sendAndReceiveSpring();
55 assertEquals(response.getData(), "SNAKE EYES AND SCARLETT SPRING. IT IS CANON.");
60 public void customerCustomClient() throws Exception {
61 final Source customRequestPayload = new StringSource(
62 "<CustomBindingExampleRequest xmlns='http://gumartinm.name/spring-ws/example'>" +
63 "<data>CUSTOM BINDING SPRING. SCARLETT. IT IS CANON.</data>" +
64 "</CustomBindingExampleRequest>");
65 final Source customResponsePayload = new StringSource(
66 "<ns2:CustomBindingExampleResponse xmlns:ns2='http://gumartinm.name/spring-ws/example'>" +
67 "<ns2:data>CUSTOM BINDING SNAKE EYES AND SCARLETT SPRING. IT IS CANON.</ns2:data>" +
68 "</ns2:CustomBindingExampleResponse>");
69 mockServer.expect(payload(customRequestPayload)).andRespond(
70 withPayload(customResponsePayload));
72 final CustomBindingExampleResponse response = exampleClientService.sendAndReceiveSpringCustom();
74 assertEquals(response.getData(), "CUSTOM BINDING SNAKE EYES AND SCARLETT SPRING. IT IS CANON.");