diff --git a/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java b/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java index a7b545b8..7871a121 100644 --- a/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java +++ b/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java @@ -23,6 +23,7 @@ import org.springframework.ws.WebServiceMessage; import org.springframework.xml.transform.TransformerObjectSupport; import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.XMLUnit; import static org.springframework.ws.mock.client.Assert.assertTrue; import static org.springframework.ws.mock.client.Assert.fail; @@ -35,6 +36,11 @@ import static org.springframework.ws.mock.client.Assert.fail; */ abstract class DiffMatcher extends TransformerObjectSupport implements RequestMatcher { + static { + XMLUnit.setIgnoreWhitespace(true); + } + + public final void match(URI uri, WebServiceMessage request) throws IOException, AssertionError { try { Diff diff = createDiff(request); diff --git a/test/src/main/java/org/springframework/ws/mock/client/MockWebServiceMessageSender.java b/test/src/main/java/org/springframework/ws/mock/client/MockWebServiceMessageSender.java index 563814a9..b0fc8308 100644 --- a/test/src/main/java/org/springframework/ws/mock/client/MockWebServiceMessageSender.java +++ b/test/src/main/java/org/springframework/ws/mock/client/MockWebServiceMessageSender.java @@ -56,15 +56,18 @@ class MockWebServiceMessageSender implements WebServiceMessageSender { return currentConnection; } - /** Always returns {@code true}. */ + /** + * Always returns {@code true}. + */ public boolean supports(URI uri) { return true; } MockSenderConnection expectNewConnection() { + Assert.state(connectionIterator == null, "Can not expect another connection, the test is already underway"); MockSenderConnection connection = new MockSenderConnection(); expectedConnections.add(connection); return connection; } -} \ No newline at end of file +} diff --git a/test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java b/test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java index ae2b0bb2..fd500f13 100644 --- a/test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java +++ b/test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java @@ -25,6 +25,7 @@ import javax.xml.transform.Source; import org.springframework.core.io.Resource; import org.springframework.util.Assert; +import org.springframework.ws.WebServiceMessage; import org.springframework.ws.client.core.WebServiceTemplate; import org.springframework.xml.transform.ResourceSource; import org.springframework.xml.validation.XmlValidator; @@ -65,6 +66,18 @@ public abstract class WebServiceMock { // RequestMatchers + /** + * Expects any request. + * + * @return the request matcher + */ + public static RequestMatcher anything() { + return new RequestMatcher() { + public void match(URI uri, WebServiceMessage request) throws IOException, AssertionError { + } + }; + } + /** * Expects the given {@link Source} XML payload. * @@ -121,7 +134,7 @@ public abstract class WebServiceMock { /** * Expects the given XPath expression to (not) exist or be evaluated to a value. * - * @param xpathExpression the XPath expression + * @param xpathExpression the XPath expression * @param namespaceMapping the namespaces * @return the XPath expectations, to be further configured */ diff --git a/test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java b/test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java index 21575fe5..0f68649a 100644 --- a/test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java +++ b/test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java @@ -203,7 +203,7 @@ public class WebServiceMockTest { template.sendSourceAndReceiveToResult(new StringSource(""), new StringResult()); } - + @Test(expected = AssertionError.class) public void xpathExistsNonMatch() throws Exception { final Map ns = Collections.singletonMap("ns", "http://example.com"); @@ -214,5 +214,32 @@ public class WebServiceMockTest { new StringResult()); } + @Test + public void anythingMatch() throws Exception { + Source request = new StringSource(""); + Source response = new StringSource(""); + + expect(anything()).andRespond(withPayload(response)); + + StringResult result = new StringResult(); + template.sendSourceAndReceiveToResult(request, result); + assertXMLEqual(result.toString(), response.toString()); + } + + @Test(expected = IllegalStateException.class) + public void recordWhenReplay() throws Exception { + Source request = new StringSource(""); + Source response = new StringSource(""); + + expect(anything()).andRespond(withPayload(response)); + expect(anything()).andRespond(withPayload(response)); + + StringResult result = new StringResult(); + template.sendSourceAndReceiveToResult(request, result); + assertXMLEqual(result.toString(), response.toString()); + + expect(anything()).andRespond(withPayload(response)); + } + }