1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Integration test for client-side WebService testing. In different package so we can't use the package-protected
37   * classes.
38   *
39   * @author Arjen Poutsma
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  }