This commit is contained in:
Arjen Poutsma
2010-11-03 14:10:26 +00:00
parent 8e3525bede
commit 77d400ec9b
2 changed files with 43 additions and 3 deletions

View File

@@ -54,6 +54,47 @@ import static org.springframework.ws.test.support.AssertionErrors.fail;
* <p/>
* For example:
* <blockquote><pre>
* import org.junit.*;
* import org.springframework.beans.factory.annotation.Autowired;
* import org.springframework.context.ApplicationContext;
* import org.springframework.test.context.ContextConfiguration;
* import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* import org.springframework.xml.transform.StringSource;
* <strong>import org.springframework.ws.test.server.MockWebServiceClient</strong>;
* <strong>import static org.springframework.ws.test.server.RequestCreators.*</strong>;
* <strong>import static org.springframework.ws.test.server.ResponseMatchers.*</strong>;
*
* &#064;RunWith(SpringJUnit4ClassRunner.class)
* &#064;ContextConfiguration("applicationContext.xml")
* public class MyWebServiceIntegrationTest {
*
* // a standard MessageDispatcherServlet application context, containing endpoints, mappings, etc.
* &#064;Autowired
* private ApplicationContext applicationContext;
*
* private MockWebServiceClient mockClient;
*
* &#064;Before
* public void createClient() throws Exception {
* <strong>mockClient = MockWebServiceClient.createClient(applicationContext)</strong>;
* }
*
* // test the CustomerCountEndpoint, which is wired up in the application context above
* // and handles &lt;customerCount/&gt; messages
* &#064;Test
* public void customerCountEndpoint() throws Exception {
* Source requestPayload = new StringSource(
* "&lt;customerCountRequest xmlns='http://springframework.org/spring-ws'&gt;" +
* "&lt;customerName&gt;John Doe&lt;/customerName&gt;" +
* "&lt;/customerCountRequest&gt;");
* Source expectedResponsePayload = new StringSource(
* "&lt;customerCountResponse xmlns='http://springframework.org/spring-ws'&gt;" +
* "&lt;customerCount&gt;42&lt;/customerCount&gt;" +
* "&lt;/customerCountResponse&gt;");
*
* <strong>mockClient.sendMessage(withPayload(requestPayload)).andExpect(payload(expectedResponsePayload))</strong>;
* }
* }
* </pre></blockquote>
*
* @author Arjen Poutsma

View File

@@ -30,7 +30,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import static org.springframework.ws.test.server.RequestCreators.withPayload;
import static org.springframework.ws.test.server.ResponseMatchers.noFault;
import static org.springframework.ws.test.server.ResponseMatchers.payload;
/**
@@ -54,11 +53,11 @@ public class ServerIntegrationTest {
public void basic() throws Exception {
Source requestPayload = new StringSource("<customerCountRequest xmlns='http://springframework.org/spring-ws'>" +
"<customerName>John Doe</customerName>" + "</customerCountRequest>");
Source responsePayload = new StringSource(
Source expectedResponsePayload = new StringSource(
"<customerCountResponse xmlns='http://springframework.org/spring-ws'>" +
"<customerCount>42</customerCount>" + "</customerCountResponse>");
mockClient.sendMessage(withPayload(requestPayload)).andExpect(payload(responsePayload)).andExpect(noFault());
mockClient.sendMessage(withPayload(requestPayload)).andExpect(payload(expectedResponsePayload));
}