From 0abc553b4e400f9b2e6d4f23dafd350d51eeeb22 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 21 Mar 2011 11:28:14 +0000 Subject: [PATCH] SWS-694 - Print SOAP message if validation fails --- .../ws/test/client/UriMatcher.java | 6 +- .../ws/test/support/AssertionErrors.java | 49 ++++++++- .../ws/test/support/SourceAssertionError.java | 99 +++++++++++++++++++ .../ws/test/support/matcher/DiffMatcher.java | 6 +- .../matcher/SchemaValidatingMatcher.java | 6 +- .../support/matcher/SoapHeaderMatcher.java | 10 +- .../matcher/XPathExpectationsHelper.java | 14 +-- .../ws/test/client/UriMatcherTest.java | 18 +++- .../matcher/PayloadDiffMatcherTest.java | 10 +- .../matcher/SchemaValidatingMatcherTest.java | 12 +-- .../matcher/XPathExpectationsHelperTest.java | 22 ++--- 11 files changed, 202 insertions(+), 50 deletions(-) create mode 100644 test/src/main/java/org/springframework/ws/test/support/SourceAssertionError.java diff --git a/test/src/main/java/org/springframework/ws/test/client/UriMatcher.java b/test/src/main/java/org/springframework/ws/test/client/UriMatcher.java index c3574717..dcbedebf 100644 --- a/test/src/main/java/org/springframework/ws/test/client/UriMatcher.java +++ b/test/src/main/java/org/springframework/ws/test/client/UriMatcher.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -37,6 +37,6 @@ class UriMatcher implements RequestMatcher { } public void match(URI actual, WebServiceMessage request) { - assertEquals("Unexpected connection", expected, actual); + assertEquals("Unexpected connection", expected, actual, "Payload", request.getPayloadSource()); } } diff --git a/test/src/main/java/org/springframework/ws/test/support/AssertionErrors.java b/test/src/main/java/org/springframework/ws/test/support/AssertionErrors.java index 4035304d..e44d74ea 100644 --- a/test/src/main/java/org/springframework/ws/test/support/AssertionErrors.java +++ b/test/src/main/java/org/springframework/ws/test/support/AssertionErrors.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,8 @@ package org.springframework.ws.test.support; +import javax.xml.transform.Source; + /** * JUnit independent assertion class. * @@ -37,6 +39,21 @@ public abstract class AssertionErrors { throw new AssertionError(message); } + /** + * Fails a test with the given message and source. + * + * @param message the message + * @param source the source + */ + public static void fail(String message, String sourceLabel, Source source) { + if (source != null) { + throw new SourceAssertionError(message, sourceLabel, source); + } + else { + fail(message); + } + } + /** * Asserts that a condition is {@code true}. If not, throws an {@link AssertionError} with the given message. * @@ -44,8 +61,19 @@ public abstract class AssertionErrors { * @param condition the condition to test for */ public static void assertTrue(String message, boolean condition) { + assertTrue(message, condition, null, null); + } + + /** + * Asserts that a condition is {@code true}. If not, throws an {@link AssertionError} with the given message and + * source. + * + * @param message the message + * @param condition the condition to test for + */ + public static void assertTrue(String message, boolean condition, String sourceLabel, Source source) { if (!condition) { - fail(message); + fail(message, sourceLabel, source); } } @@ -57,12 +85,25 @@ public abstract class AssertionErrors { * @param actual the actual value */ public static void assertEquals(String message, Object expected, Object actual) { + assertEquals(message, expected, actual, null, null); + } + + /** + * Asserts that two objects are equal. If not, an {@link AssertionError} is thrown with the given message. + * + * @param message the message + * @param expected the expected value + * @param actual the actual value + * @param source the source + */ + public static void assertEquals(String message, Object expected, Object actual, String sourceLabel, Source source) { if (expected == null && actual == null) { return; } if (expected != null && expected.equals(actual)) { return; } - fail(message + " expected:<" + expected + "> but was:<" + actual + ">"); + fail(message + " expected:<" + expected + "> but was:<" + actual + ">", sourceLabel, source); } + } diff --git a/test/src/main/java/org/springframework/ws/test/support/SourceAssertionError.java b/test/src/main/java/org/springframework/ws/test/support/SourceAssertionError.java new file mode 100644 index 00000000..01d5e21a --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/support/SourceAssertionError.java @@ -0,0 +1,99 @@ +/* + * Copyright 2005-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ws.test.support; + +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; + +import org.springframework.xml.transform.StringResult; +import org.springframework.xml.transform.TransformerHelper; + +/** + * Subclass of {@link AssertionError} that also contains a {@link Source} for more context. + * + * @author Lukas Krecan + * @author Arjen Poutsma + * @since 2.0.1 + */ +public class SourceAssertionError extends AssertionError { + + private final String sourceLabel; + + private final Source source; + + private final TransformerHelper transformerHelper = new TransformerHelper(); + + /** + * Creates a new instance of the {@code SourceAssertionError} class with the given parameters. + */ + public SourceAssertionError(String detailMessage, String sourceLabel, Source source) { + super(detailMessage); + this.sourceLabel = sourceLabel; + this.source = source; + } + + /** + * Returns the source context of this error. + * @return the source + */ + public Source getSource() { + return source; + } + + @Override + public String getMessage() { + StringBuilder builder = new StringBuilder(); + builder.append(super.getMessage()); + String sourceString = getSourceString(); + if (sourceString != null) { + String newLine = System.getProperty("line.separator"); + builder.append(newLine); + String label = sourceLabel != null ? sourceLabel : "Source"; + builder.append(label); + builder.append(": "); + builder.append(sourceString); + } + return builder.toString(); + } + + private String getSourceString() { + if (source != null) { + try { + StringResult result = new StringResult(); + Transformer transformer = createNonIndentingTransformer(); + transformer.transform(source, result); + return result.toString(); + } + catch (TransformerException ex) { + // Ignore + } + } + return null; + } + + private Transformer createNonIndentingTransformer() throws TransformerConfigurationException { + Transformer transformer = transformerHelper.createTransformer(); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + transformer.setOutputProperty(OutputKeys.INDENT, "no"); + return transformer; + } + + +} diff --git a/test/src/main/java/org/springframework/ws/test/support/matcher/DiffMatcher.java b/test/src/main/java/org/springframework/ws/test/support/matcher/DiffMatcher.java index fd3e3016..c2ff3506 100644 --- a/test/src/main/java/org/springframework/ws/test/support/matcher/DiffMatcher.java +++ b/test/src/main/java/org/springframework/ws/test/support/matcher/DiffMatcher.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -39,7 +39,7 @@ public abstract class DiffMatcher implements WebServiceMessageMatcher { public final void match(WebServiceMessage message) throws IOException, AssertionError { Diff diff = createDiff(message); - assertTrue("Messages are different, " + diff.toString(), diff.similar()); + assertTrue("Messages are different, " + diff.toString(), diff.similar(), "Payload", message.getPayloadSource()); } /** diff --git a/test/src/main/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcher.java b/test/src/main/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcher.java index 19e7fd4a..153c3401 100644 --- a/test/src/main/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcher.java +++ b/test/src/main/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcher.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -60,7 +60,7 @@ public class SchemaValidatingMatcher implements WebServiceMessageMatcher { public void match(WebServiceMessage message) throws IOException, AssertionError { SAXParseException[] exceptions = xmlValidator.validate(message.getPayloadSource()); if (!ObjectUtils.isEmpty(exceptions)) { - fail("XML is not valid: " + Arrays.toString(exceptions)); + fail("XML is not valid: " + Arrays.toString(exceptions), "Payload", message.getPayloadSource()); } } } diff --git a/test/src/main/java/org/springframework/ws/test/support/matcher/SoapHeaderMatcher.java b/test/src/main/java/org/springframework/ws/test/support/matcher/SoapHeaderMatcher.java index 7cf20a07..82bc2625 100644 --- a/test/src/main/java/org/springframework/ws/test/support/matcher/SoapHeaderMatcher.java +++ b/test/src/main/java/org/springframework/ws/test/support/matcher/SoapHeaderMatcher.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -51,7 +51,8 @@ public class SoapHeaderMatcher extends AbstractSoapMessageMatcher { @Override protected void match(SoapMessage soapMessage) throws IOException, AssertionError { SoapHeader soapHeader = soapMessage.getSoapHeader(); - assertTrue("SOAP message [" + soapMessage + "] does not contain SOAP header", soapHeader != null); + assertTrue("SOAP message [" + soapMessage + "] does not contain SOAP header", soapHeader != null, "Envelope", + soapMessage.getEnvelope().getSource()); Iterator soapHeaderElementIterator = soapHeader.examineAllHeaderElements(); boolean found = false; @@ -62,6 +63,7 @@ public class SoapHeaderMatcher extends AbstractSoapMessageMatcher { break; } } - assertTrue("SOAP header [" + soapHeaderName + "] not found", found); + assertTrue("SOAP header [" + soapHeaderName + "] not found", found, "Envelope", + soapMessage.getEnvelope().getSource()); } } diff --git a/test/src/main/java/org/springframework/ws/test/support/matcher/XPathExpectationsHelper.java b/test/src/main/java/org/springframework/ws/test/support/matcher/XPathExpectationsHelper.java index fb952443..a6780920 100644 --- a/test/src/main/java/org/springframework/ws/test/support/matcher/XPathExpectationsHelper.java +++ b/test/src/main/java/org/springframework/ws/test/support/matcher/XPathExpectationsHelper.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -73,7 +73,7 @@ public class XPathExpectationsHelper { Node payload = transformToNode(message); Node result = expression.evaluateAsNode(payload); if (result == null) { - fail("No match for \"" + expressionString + "\" found"); + fail("No match for \"" + expressionString + "\" found", "Payload", message.getPayloadSource()); } } }; @@ -85,7 +85,7 @@ public class XPathExpectationsHelper { Node payload = transformToNode(message); Node result = expression.evaluateAsNode(payload); if (result != null) { - fail("Match for \"" + expressionString + "\" found"); + fail("Match for \"" + expressionString + "\" found", "Payload", message.getPayloadSource()); } } }; @@ -97,7 +97,7 @@ public class XPathExpectationsHelper { Node payload = transformToNode(message); boolean result = expression.evaluateAsBoolean(payload); assertEquals("Evaluation of XPath expression \"" + expressionString + "\" failed.", expectedValue, - result); + result, "Payload", message.getPayloadSource()); } }; @@ -113,7 +113,7 @@ public class XPathExpectationsHelper { Node payload = transformToNode(message); double result = expression.evaluateAsNumber(payload); assertEquals("Evaluation of XPath expression \"" + expressionString + "\" failed.", expectedValue, - result); + result, "Payload", message.getPayloadSource()); } }; @@ -126,7 +126,7 @@ public class XPathExpectationsHelper { Node payload = transformToNode(message); String result = expression.evaluateAsString(payload); assertEquals("Evaluation of XPath expression \"" + expressionString + "\" failed.", expectedValue, - result); + result, "Payload", message.getPayloadSource()); } }; } diff --git a/test/src/test/java/org/springframework/ws/test/client/UriMatcherTest.java b/test/src/test/java/org/springframework/ws/test/client/UriMatcherTest.java index 9acb0e31..09ce1b6f 100644 --- a/test/src/test/java/org/springframework/ws/test/client/UriMatcherTest.java +++ b/test/src/test/java/org/springframework/ws/test/client/UriMatcherTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,21 +18,31 @@ package org.springframework.ws.test.client; import java.net.URI; +import org.springframework.ws.WebServiceMessage; + import org.junit.Test; +import static org.easymock.EasyMock.*; + public class UriMatcherTest { private static final URI GOOD_URI = URI.create("http://localhost"); @Test public void match() { + WebServiceMessage message = createMock(WebServiceMessage.class); + expect(message.getPayloadSource()).andReturn(null); + replay(message); UriMatcher matcher = new UriMatcher(GOOD_URI); - matcher.match(GOOD_URI, null); + matcher.match(GOOD_URI, message); } @Test(expected = AssertionError.class) public void nonMatch() { + WebServiceMessage message = createMock(WebServiceMessage.class); + expect(message.getPayloadSource()).andReturn(null); + replay(message); UriMatcher matcher = new UriMatcher(GOOD_URI); - matcher.match(URI.create("http://www.example.org"), null); + matcher.match(URI.create("http://www.example.org"), message); } } diff --git a/test/src/test/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcherTest.java b/test/src/test/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcherTest.java index 6cad8366..327b7eb9 100644 --- a/test/src/test/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcherTest.java +++ b/test/src/test/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcherTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,7 +33,7 @@ public class PayloadDiffMatcherTest { public void match() throws Exception { String xml = ""; WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource(xml)); + expect(message.getPayloadSource()).andReturn(new StringSource(xml)).times(2); replay(message); PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource(xml)); @@ -46,7 +46,7 @@ public class PayloadDiffMatcherTest { public void nonMatch() throws Exception { String actual = ""; WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource(actual)); + expect(message.getPayloadSource()).andReturn(new StringSource(actual)).times(2); replay(message); String expected = ""; @@ -63,4 +63,4 @@ public class PayloadDiffMatcherTest { matcher.createDiff(soapMessage); } -} \ No newline at end of file +} diff --git a/test/src/test/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcherTest.java b/test/src/test/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcherTest.java index c8f0c1f3..755decd4 100644 --- a/test/src/test/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcherTest.java +++ b/test/src/test/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcherTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -61,7 +61,7 @@ public class SchemaValidatingMatcherTest { @Test(expected = AssertionError.class) public void singleSchemaNonMatch() throws IOException, AssertionError { expect(message.getPayloadSource()).andReturn(new StringSource( - "atext")); + "atext")).times(2); SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1); @@ -89,7 +89,7 @@ public class SchemaValidatingMatcherTest { @Test(expected = AssertionError.class) public void multipleSchemaNotOk() throws IOException, AssertionError { expect(message.getPayloadSource()).andReturn(new StringSource( - "atext")); + "atext")).times(2); SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1, schema2); @@ -103,7 +103,7 @@ public class SchemaValidatingMatcherTest { @Test(expected = AssertionError.class) public void multipleSchemaDifferentOrderNotOk() throws IOException, AssertionError { expect(message.getPayloadSource()).andReturn(new StringSource( - "atext")); + "atext")).times(2); SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema2, schema1); @@ -117,7 +117,7 @@ public class SchemaValidatingMatcherTest { @Test(expected = AssertionError.class) public void xmlValidatorNotOk() throws IOException, AssertionError { expect(message.getPayloadSource()).andReturn(new StringSource( - "atext")); + "atext")).times(2); SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1); diff --git a/test/src/test/java/org/springframework/ws/test/support/matcher/XPathExpectationsHelperTest.java b/test/src/test/java/org/springframework/ws/test/support/matcher/XPathExpectationsHelperTest.java index 2a52266d..5d6f3c8e 100644 --- a/test/src/test/java/org/springframework/ws/test/support/matcher/XPathExpectationsHelperTest.java +++ b/test/src/test/java/org/springframework/ws/test/support/matcher/XPathExpectationsHelperTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -53,7 +53,7 @@ public class XPathExpectationsHelperTest { assertNotNull(matcher); WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource("")); + expect(message.getPayloadSource()).andReturn(new StringSource("")).times(2); replay(message); @@ -83,7 +83,7 @@ public class XPathExpectationsHelperTest { assertNotNull(matcher); WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource("")); + expect(message.getPayloadSource()).andReturn(new StringSource("")).times(2); replay(message); @@ -97,7 +97,7 @@ public class XPathExpectationsHelperTest { assertNotNull(matcher); WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource("1")); + expect(message.getPayloadSource()).andReturn(new StringSource("1")).times(2); replay(message); @@ -113,7 +113,7 @@ public class XPathExpectationsHelperTest { assertNotNull(matcher); WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource("1")); + expect(message.getPayloadSource()).andReturn(new StringSource("1")).times(2); replay(message); @@ -127,7 +127,7 @@ public class XPathExpectationsHelperTest { assertNotNull(matcher); WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource("1")); + expect(message.getPayloadSource()).andReturn(new StringSource("1")).times(2); replay(message); @@ -143,7 +143,7 @@ public class XPathExpectationsHelperTest { assertNotNull(matcher); WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource("1")); + expect(message.getPayloadSource()).andReturn(new StringSource("1")).times(2); replay(message); @@ -157,7 +157,7 @@ public class XPathExpectationsHelperTest { assertNotNull(matcher); WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource("1")); + expect(message.getPayloadSource()).andReturn(new StringSource("1")).times(2); replay(message); @@ -173,7 +173,7 @@ public class XPathExpectationsHelperTest { assertNotNull(matcher); WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource("1")); + expect(message.getPayloadSource()).andReturn(new StringSource("1")).times(2); replay(message); @@ -207,7 +207,7 @@ public class XPathExpectationsHelperTest { WebServiceMessage message = createMock(WebServiceMessage.class); expect(message.getPayloadSource()) - .andReturn(new StringSource("")); + .andReturn(new StringSource("")).times(2); replay(message);