1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.test.client.integration;
18
19 import javax.xml.transform.Source;
20
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.test.context.ContextConfiguration;
23 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
24 import org.springframework.ws.test.client.MockWebServiceServer;
25 import org.springframework.xml.transform.StringSource;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30
31 import static org.junit.Assert.assertEquals;
32 import static org.springframework.ws.test.client.RequestMatchers.payload;
33 import static org.springframework.ws.test.client.ResponseCreators.withPayload;
34
35
36
37
38
39
40
41 @RunWith(SpringJUnit4ClassRunner.class)
42 @ContextConfiguration("integration-test.xml")
43 public class ClientIntegrationTest {
44
45 @Autowired
46 private CustomerClient client;
47
48 private MockWebServiceServer mockServer;
49
50 @Before
51 public void createServer() throws Exception {
52 mockServer = MockWebServiceServer.createServer(client);
53 }
54
55 @Test
56 public void basic() throws Exception {
57 Source expectedRequestPayload = new StringSource(
58 "<customerCountRequest xmlns='http://springframework.org/spring-ws'>" +
59 "<customerName>John Doe</customerName>" + "</customerCountRequest>");
60 Source responsePayload = new StringSource(
61 "<customerCountResponse xmlns='http://springframework.org/spring-ws'>" +
62 "<customerCount>10</customerCount>" + "</customerCountResponse>");
63
64 mockServer.expect(payload(expectedRequestPayload)).andRespond(withPayload(responsePayload));
65
66 int result = client.getCustomerCount();
67 assertEquals(10, result);
68
69 mockServer.verify();
70 }
71
72 }