a536c47855aeaec1f8f9f28c0044e8d69f3d4a29
[SpringWebServicesForFun/.git] /
1 package de.spring.webservices.client;
2
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;
6
7 import javax.xml.transform.Source;
8
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;
18
19 import de.spring.webservices.auto.CustomBindingExampleResponse;
20 import de.spring.webservices.auto.ExampleResponse;
21
22
23 @RunWith(SpringJUnit4ClassRunner.class)
24 @ContextConfiguration("classpath*:spring-configuration/ws/client-spring-configuration.xml")
25 public class ExampleClientServiceIntegrationTest {
26
27         @Autowired
28         ExampleClientService exampleClientService;
29         
30     @Autowired
31     private WebServiceTemplate webServiceTemplate;
32
33     private MockWebServiceServer mockServer;
34
35     @Before
36     public void createServer() throws Exception {
37         mockServer = MockWebServiceServer.createServer(webServiceTemplate);
38     }
39
40     @Test
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));
52         
53         final ExampleResponse response = exampleClientService.sendAndReceiveSpring();
54
55         assertEquals(response.getData(), "SNAKE EYES AND SCARLETT SPRING. IT IS CANON.");
56         mockServer.verify();
57     }
58     
59     @Test
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));
71         
72         final CustomBindingExampleResponse response = exampleClientService.sendAndReceiveSpringCustom();
73
74         assertEquals(response.getData(), "CUSTOM BINDING SNAKE EYES AND SCARLETT SPRING. IT IS CANON.");
75         mockServer.verify();
76     }
77 }
78