diff --git a/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java b/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java index c5c3f6a8..cd2c41ff 100644 --- a/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java +++ b/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java @@ -93,7 +93,7 @@ public abstract class RequestMatchers { * @param xpathExpression the XPath expression * @return the XPath expectations, to be further configured */ - public static XPathExpectations xpath(String xpathExpression) { + public static RequestXPathExpectations xpath(String xpathExpression) { return new XPathExpectationsHelperAdapter(xpathExpression, null); } @@ -104,7 +104,7 @@ public abstract class RequestMatchers { * @param namespaceMapping the namespaces * @return the XPath expectations, to be further configured */ - public static XPathExpectations xpath(String xpathExpression, Map namespaceMapping) { + public static RequestXPathExpectations xpath(String xpathExpression, Map namespaceMapping) { return new XPathExpectationsHelperAdapter(xpathExpression, namespaceMapping); } diff --git a/test/src/main/java/org/springframework/ws/test/client/XPathExpectations.java b/test/src/main/java/org/springframework/ws/test/client/RequestXPathExpectations.java similarity index 98% rename from test/src/main/java/org/springframework/ws/test/client/XPathExpectations.java rename to test/src/main/java/org/springframework/ws/test/client/RequestXPathExpectations.java index 4e646093..3ea3a02f 100644 --- a/test/src/main/java/org/springframework/ws/test/client/XPathExpectations.java +++ b/test/src/main/java/org/springframework/ws/test/client/RequestXPathExpectations.java @@ -29,7 +29,7 @@ package org.springframework.ws.test.client; * @see RequestMatchers#xpath(String, java.util.Map) * @since 2.0 */ -public interface XPathExpectations { +public interface RequestXPathExpectations { /** * Expects the XPath expression to exist. diff --git a/test/src/main/java/org/springframework/ws/test/client/XPathExpectationsHelperAdapter.java b/test/src/main/java/org/springframework/ws/test/client/XPathExpectationsHelperAdapter.java index 668922ff..21a5fdd2 100644 --- a/test/src/main/java/org/springframework/ws/test/client/XPathExpectationsHelperAdapter.java +++ b/test/src/main/java/org/springframework/ws/test/client/XPathExpectationsHelperAdapter.java @@ -21,12 +21,12 @@ import java.util.Map; import org.springframework.ws.test.support.matcher.XPathExpectationsHelper; /** - * Adapts {@link XPathExpectationsHelper} into the {@link XPathExpectations} contract. + * Adapts {@link XPathExpectationsHelper} into the {@link RequestXPathExpectations} contract. * * @author Arjen Poutsma * @since 2.0 */ -class XPathExpectationsHelperAdapter implements XPathExpectations { +class XPathExpectationsHelperAdapter implements RequestXPathExpectations { private final XPathExpectationsHelper helper; diff --git a/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java b/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java index 4fd2c1ce..dcb8ebd6 100644 --- a/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java +++ b/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java @@ -18,6 +18,7 @@ package org.springframework.ws.test.server; import java.io.IOException; import java.util.Locale; +import java.util.Map; import javax.xml.namespace.QName; import javax.xml.transform.Source; @@ -29,7 +30,6 @@ import org.springframework.ws.soap.SoapVersion; import org.springframework.ws.test.support.matcher.PayloadDiffMatcher; import org.springframework.ws.test.support.matcher.SchemaValidatingMatcher; import org.springframework.ws.test.support.matcher.SoapHeaderMatcher; -import org.springframework.ws.test.support.matcher.WebServiceMessageMatcher; import org.springframework.xml.transform.ResourceSource; import static org.springframework.ws.test.support.AssertionErrors.assertTrue; @@ -92,6 +92,27 @@ public abstract class ResponseMatchers { return new WebServiceMessageMatcherAdapter(new SchemaValidatingMatcher(schema, furtherSchemas)); } + /** + * Expects the given XPath expression to (not) exist or be evaluated to a value. + * + * @param xpathExpression the XPath expression + * @return the XPath expectations, to be further configured + */ + public static ResponseXPathExpectations xpath(String xpathExpression) { + return new XPathExpectationsHelperAdapter(xpathExpression, null); + } + + /** + * Expects the given XPath expression to (not) exist or be evaluated to a value. + * + * @param xpathExpression the XPath expression + * @param namespaceMapping the namespaces + * @return the XPath expectations, to be further configured + */ + public static ResponseXPathExpectations xpath(String xpathExpression, Map namespaceMapping) { + return new XPathExpectationsHelperAdapter(xpathExpression, namespaceMapping); + } + // SOAP @@ -224,20 +245,4 @@ public abstract class ResponseMatchers { }; } - /** - * Adapts a {@link WebServiceMessageMatcher} to the {@link ResponseMatcher} contract. - */ - private static class WebServiceMessageMatcherAdapter implements ResponseMatcher { - - private final WebServiceMessageMatcher adaptee; - - private WebServiceMessageMatcherAdapter(WebServiceMessageMatcher adaptee) { - this.adaptee = adaptee; - } - - public void match(WebServiceMessage request, WebServiceMessage response) throws IOException, AssertionError { - adaptee.match(response); - } - } - } diff --git a/test/src/main/java/org/springframework/ws/test/server/ResponseXPathExpectations.java b/test/src/main/java/org/springframework/ws/test/server/ResponseXPathExpectations.java new file mode 100644 index 00000000..0ad008e1 --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/server/ResponseXPathExpectations.java @@ -0,0 +1,80 @@ +/* + * Copyright 2005-2010 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.server; + +/** + * Allows for setting up expectations on XPath expressions. + *

+ * Implementations of this interface are returned by {@link org.springframework.ws.test.client.RequestMatchers#xpath(String)} and {@link + * org.springframework.ws.test.client.RequestMatchers#xpath(String, java.util.Map)}, as part of the fluent API. As such, it is not typical to implement this + * interface yourself. + * + * @author Lukas Krecan + * @author Arjen Poutsma + * @see org.springframework.ws.test.client.RequestMatchers#xpath(String) + * @see org.springframework.ws.test.client.RequestMatchers#xpath(String, java.util.Map) + * @since 2.0 + */ +public interface ResponseXPathExpectations { + + /** + * Expects the XPath expression to exist. + * + * @return the request matcher + */ + ResponseMatcher exists(); + + /** + * Expects the XPath expression to not exist. + * + * @return the request matcher + */ + ResponseMatcher doesNotExist(); + + /** + * Expects the XPath expression to evaluate to the given boolean. + * + * @param expectedValue the expected value + * @return the request matcher + */ + ResponseMatcher evaluatesTo(final boolean expectedValue); + + /** + * Expects the XPath expression to evaluate to the given integer. + * + * @param expectedValue the expected value + * @return the request matcher + */ + ResponseMatcher evaluatesTo(int expectedValue); + + /** + * Expects the XPath expression to evaluate to the given double. + * + * @param expectedValue the expected value + * @return the request matcher + */ + ResponseMatcher evaluatesTo(double expectedValue); + + /** + * Expects the XPath expression to evaluate to the given string. + * + * @param expectedValue the expected value + * @return the request matcher + */ + ResponseMatcher evaluatesTo(String expectedValue); + +} diff --git a/test/src/main/java/org/springframework/ws/test/server/WebServiceMessageMatcherAdapter.java b/test/src/main/java/org/springframework/ws/test/server/WebServiceMessageMatcherAdapter.java new file mode 100644 index 00000000..782197d7 --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/server/WebServiceMessageMatcherAdapter.java @@ -0,0 +1,43 @@ +/* + * Copyright 2005-2010 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.server; + +import java.io.IOException; + +import org.springframework.util.Assert; +import org.springframework.ws.WebServiceMessage; +import org.springframework.ws.test.support.matcher.WebServiceMessageMatcher; + +/** + * Adapts a {@link WebServiceMessageMatcher} to the {@link ResponseMatcher} contract. + * + * @author Arjen Poutsma + * @since 2.0 + */ +class WebServiceMessageMatcherAdapter implements ResponseMatcher { + + private final WebServiceMessageMatcher adaptee; + + WebServiceMessageMatcherAdapter(WebServiceMessageMatcher adaptee) { + Assert.notNull(adaptee, "'adaptee' must not be null"); + this.adaptee = adaptee; + } + + public void match(WebServiceMessage request, WebServiceMessage response) throws IOException, AssertionError { + adaptee.match(response); + } +} diff --git a/test/src/main/java/org/springframework/ws/test/server/XPathExpectationsHelperAdapter.java b/test/src/main/java/org/springframework/ws/test/server/XPathExpectationsHelperAdapter.java new file mode 100644 index 00000000..7aef6ac4 --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/server/XPathExpectationsHelperAdapter.java @@ -0,0 +1,61 @@ +/* + * Copyright 2005-2010 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.server; + +import java.util.Map; + +import org.springframework.ws.test.support.matcher.XPathExpectationsHelper; + +/** + * Adapts {@link XPathExpectationsHelper} into the {@link ResponseXPathExpectations} contract. + * + * @author Arjen Poutsma + * @since 2.0 + */ +class XPathExpectationsHelperAdapter implements ResponseXPathExpectations { + + private final XPathExpectationsHelper helper; + + XPathExpectationsHelperAdapter(String expression, Map namespaces) { + helper = new XPathExpectationsHelper(expression, namespaces); + } + + public ResponseMatcher exists() { + return new WebServiceMessageMatcherAdapter(helper.exists()); + } + + public ResponseMatcher doesNotExist() { + return new WebServiceMessageMatcherAdapter(helper.doesNotExist()); + } + + public ResponseMatcher evaluatesTo(boolean expectedValue) { + return new WebServiceMessageMatcherAdapter(helper.evaluatesTo(expectedValue)); + } + + public ResponseMatcher evaluatesTo(int expectedValue) { + return new WebServiceMessageMatcherAdapter(helper.evaluatesTo(expectedValue)); + } + + public ResponseMatcher evaluatesTo(double expectedValue) { + return new WebServiceMessageMatcherAdapter(helper.evaluatesTo(expectedValue)); + } + + public ResponseMatcher evaluatesTo(String expectedValue) { + return new WebServiceMessageMatcherAdapter(helper.evaluatesTo(expectedValue)); + } + +} diff --git a/test/src/test/java/org/springframework/ws/test/server/WebServiceMessageMatcherAdapterTest.java b/test/src/test/java/org/springframework/ws/test/server/WebServiceMessageMatcherAdapterTest.java new file mode 100644 index 00000000..5ca763ef --- /dev/null +++ b/test/src/test/java/org/springframework/ws/test/server/WebServiceMessageMatcherAdapterTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2005-2010 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.server; + +import java.io.IOException; + +import org.springframework.ws.WebServiceMessage; +import org.springframework.ws.test.support.matcher.WebServiceMessageMatcher; + +import org.junit.Before; +import org.junit.Test; + +import static org.easymock.EasyMock.*; + +/** + * @author Arjen Poutsma + */ +public class WebServiceMessageMatcherAdapterTest { + + private WebServiceMessage message; + + private WebServiceMessageMatcher adaptee; + + private WebServiceMessageMatcherAdapter adapter; + + @Before + public void setUp() throws Exception { + message = createMock(WebServiceMessage.class); + adaptee = createMock(WebServiceMessageMatcher.class); + adapter = new WebServiceMessageMatcherAdapter(adaptee); + } + + @Test + public void match() throws IOException { + adaptee.match(message); + + replay(message, adaptee); + + adapter.match(null, message); + + verify(message, adaptee); + } +}