Skip to content

Commit 7297276

Browse files
committed
SWS-631 - documentation
1 parent 66b0e49 commit 7297276

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

test/src/main/java/org/springframework/ws/mock/client/PayloadResponseCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PayloadResponseCallback extends AbstractResponseCreator<WebServiceMessage>
3838
}
3939

4040
@Override
41-
public void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
41+
protected void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
4242
try {
4343
transform(payload, response.getPayloadResult());
4444
}

test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,87 @@
3232
import org.springframework.xml.validation.XmlValidatorFactory;
3333

3434
/**
35+
* <strong>Main entry point for client-side Web service testing</strong>. Typically used to mock a {@link
36+
* WebServiceTemplate}, set up expectations on request messages, and create response messages.
37+
* <p/>
38+
* The typical usage of this mock is similar to any other mocking library (such as EasyMock), that is:
39+
* <ol>
40+
* <li>Statically import {@link org.springframework.ws.mock.client.WebServiceMock
41+
* org.springframework.ws.mock.client.WebServiceMock.*}.
42+
* <li>Use the {@link #mockWebServiceTemplate(WebServiceTemplate)} method to mock a web service template. Typically,
43+
* this template is configured as a Spring bean, either explicitly or as a property of a class that extends
44+
* {@link org.springframework.ws.client.core.support.WebServiceGatewaySupport WebServiceGatewaySupport}.</li>
45+
* <li>Set up expectations on the outgoing request message by calling {@link #expect(RequestMatcher)} and
46+
* {@link #payload(Source)}, {@link #connectionTo(String)}, {@link #xpath(String)}, or any of the other
47+
* {@linkplain RequestMatcher request matcher} methods.
48+
* Multiple expectations can be set up by calling
49+
* {@link ResponseActions#andExpect(RequestMatcher) andExpect(RequestMatcher)}.</li>
50+
* <li>Indicate the desired response actions by calling
51+
* {@link ResponseActions#andRespond(ResponseCreator) andRespond(ResponseCreator)}.
52+
* See {@link #withPayload(Source)}, {@link #withError(String)},
53+
* {@link #withClientOrSenderFault(String, Locale)}, or any of the other {@linkplain ResponseCreator response creator}
54+
* methods.</li>
55+
* <li>Use the {@code WebServiceTemplate} as normal, either directly of through client code.
56+
* <li>Call {@link #verifyConnections()}.
57+
* </ol>
58+
* Note that because of the 'fluent' API offered by this class, you can typically use the Code Completion features (i.e.
59+
* ctrl-space) in your IDE to set up the mocks.
60+
* <p/>
61+
* For example:
62+
* <blockquote><pre>
63+
* import org.junit.Before;
64+
* import org.junit.Test;
65+
* import org.junit.runner.RunWith;
66+
* import org.springframework.beans.factory.annotation.Autowired;
67+
* import org.springframework.test.context.ContextConfiguration;
68+
* import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
69+
* import org.springframework.xml.transform.StringSource;
70+
* <strong>import static org.springframework.ws.mock.client.WebServiceMock.*</strong>;
71+
*
72+
*
73+
* &#064;RunWith(SpringJUnit4ClassRunner.class)
74+
* &#064;ContextConfiguration("applicationContext.xml")
75+
* public class IntegrationTest {
76+
*
77+
* // AirlineClient extends WebServiceGatewaySupport, and is configured in applicationContext.xml
78+
* &#064;Autowired
79+
* private MyWebServiceClient client;
80+
*
81+
* &#064;Before
82+
* public void setUpMocks() throws Exception {
83+
* <strong>mockWebServiceTemplate(client.getWebServiceTemplate())</strong>;
84+
* }
85+
*
86+
* &#064;Test
87+
* public void getCustomerCount() throws Exception {
88+
* Source requestPayload =
89+
* new StringSource("&lt;customerCountRequest xmlns='http://springframework.org/spring-ws/test' /&gt;";
90+
* Source responsePayload = new StringSource("&lt;customerCountResponse xmlns='http://springframework.org/spring-wstest'&gt;" +
91+
* "&lt;customerCount&gt;10&lt;/customerCount&gt;" +
92+
* "&lt;/customerCountResponse&gt;");
93+
*
94+
* <strong>expect(payload(requestPayload)).andRespond(withPayload(responsePayload));</strong>
95+
*
96+
* // client.getCustomerCount() uses the WebServiceTemplate
97+
* int customerCount = client.getCustomerCount();
98+
* assertEquals(10, response.getCustomerCount());
99+
*
100+
* <strong>verifyConnections();</strong>
101+
* }
102+
* }
103+
* </pre></blockquote>
104+
*
35105
* @author Arjen Poutsma
36106
* @author Lukas Krecan
37107
* @since 2.0
38108
*/
39109
public abstract class WebServiceMock {
40110

111+
/**
112+
* Mocks the given {@link WebServiceTemplate}. Typically done in a setup method of the test class.
113+
*
114+
* @param webServiceTemplate the template to mock.
115+
*/
41116
public static void mockWebServiceTemplate(WebServiceTemplate webServiceTemplate) {
42117
Assert.notNull(webServiceTemplate, "'webServiceTemplate' must not be null");
43118

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
/**
18+
* Provides a testing framework for client-side Web service testing. This package contains the
19+
* {@link org.springframework.ws.mock.client.WebServiceMock}, and various related test interfaces.
20+
*/
21+
package org.springframework.ws.mock.client;

0 commit comments

Comments
 (0)