d4ebf5a0f0c72753c6aec024cc605cecb826f1cf
[SpringWebServicesForFun/.git] /
1 package de.spring.webservices.client;
2
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.*;
6
7 import javax.xml.transform.Source;
8
9 import name.gumartinm.spring_ws.example.ExampleResponse;
10
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;
20
21
22 @RunWith(SpringJUnit4ClassRunner.class)
23 @ContextConfiguration("/client-spring-configuration.xml")
24 public class ExampleClientServiceIntegrationTest {
25
26         @Autowired
27         ExampleClientService exampleClientService;
28         
29     @Autowired
30     private WebServiceTemplate webServiceTemplate;
31
32     private MockWebServiceServer mockServer;
33
34     @Before
35     public void createServer() throws Exception {
36         mockServer = MockWebServiceServer.createServer(webServiceTemplate);
37     }
38
39     @Test
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));
51         
52         final ExampleResponse exampleResponse = exampleClientService.sendAndReceiveSpring();
53
54         assertEquals(exampleResponse.getData(), "SNAKE EYES AND SCARLETT SPRING. IT IS CANON.");
55         
56         mockServer.verify();
57     }
58 }
59