Added XPath support to server-side

This commit is contained in:
Arjen Poutsma
2010-11-04 12:40:20 +00:00
parent 4f0711426a
commit 6fbf40c856
8 changed files with 268 additions and 22 deletions

View File

@@ -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<String, String> namespaceMapping) {
public static RequestXPathExpectations xpath(String xpathExpression, Map<String, String> namespaceMapping) {
return new XPathExpectationsHelperAdapter(xpathExpression, namespaceMapping);
}

View File

@@ -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.

View File

@@ -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;

View File

@@ -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<String, String> 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);
}
}
}

View File

@@ -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.
* <p/>
* 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);
}

View File

@@ -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);
}
}

View File

@@ -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<String, String> 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));
}
}

View File

@@ -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);
}
}