1 package de.spring.webservices.client;
3 import static org.springframework.ws.test.client.RequestMatchers.payload;
4 import static org.springframework.ws.test.client.ResponseCreators.withPayload;
5 import static org.junit.Assert.*;
7 import javax.xml.transform.Source;
9 import name.gumartinm.spring_ws.example.ExampleResponse;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.test.context.ContextConfiguration;
16 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17 import org.springframework.ws.client.core.WebServiceTemplate;
18 import org.springframework.ws.test.client.MockWebServiceServer;
19 import org.springframework.xml.transform.StringSource;
22 @RunWith(SpringJUnit4ClassRunner.class)
23 @ContextConfiguration("/client-spring-configuration.xml")
24 public class ExampleClientServiceIntegrationTest {
27 ExampleClientService exampleClientService;
30 private WebServiceTemplate webServiceTemplate;
32 private MockWebServiceServer mockServer;
35 public void createServer() throws Exception {
36 mockServer = MockWebServiceServer.createServer(webServiceTemplate);
40 public void customerClient() throws Exception {
41 final Source requestPayload = new StringSource(
42 "<ExampleRequest xmlns='http://gumartinm.name/spring-ws/example'>"
43 + "<data>SCARLETT SPRING. IT IS CANON.</data>"
44 + "</ExampleRequest>");
45 final Source responsePayload = new StringSource(
46 "<ns2:ExampleResponse xmlns:ns2='http://gumartinm.name/spring-ws/example'>"
47 + "<ns2:data>SNAKE EYES AND SCARLETT SPRING. IT IS CANON.</ns2:data>"
48 + "</ns2:ExampleResponse>");
49 mockServer.expect(payload(requestPayload)).andRespond(
50 withPayload(responsePayload));
52 final ExampleResponse exampleResponse = exampleClientService.sendAndReceiveSpring();
54 assertEquals(exampleResponse.getData(), "SNAKE EYES AND SCARLETT SPRING. IT IS CANON.");