Migrated to Gradle build
This commit migrates from a Maven-based build system to a Gradle-based one. Changes include: - Removed archetype & parent - Renamed core, support, test, security and xml directories to spring-ws-core, spring-ws-test, spring-ws-security, spring-xml respectively. - Moved samples to separate project (https://github.com/spring-projects/spring-ws-samples)
This commit is contained in:
committed by
Arjen Poutsma
parent
a8c1d2ad97
commit
843ca6d2ef
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Abstract base class for the {@link ResponseCreator} interface.
|
||||
* <p/>
|
||||
* Creates a response using the given {@link WebServiceMessageFactory}, and passes it on to {@link #doWithResponse(URI,
|
||||
* WebServiceMessage, WebServiceMessage)}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract class AbstractResponseCreator implements ResponseCreator {
|
||||
|
||||
public final WebServiceMessage createResponse(URI uri,
|
||||
WebServiceMessage request,
|
||||
WebServiceMessageFactory messageFactory) throws IOException {
|
||||
WebServiceMessage response = messageFactory.createWebServiceMessage();
|
||||
doWithResponse(uri, request, response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute any number of operations on the supplied response, given the request and URI.
|
||||
*
|
||||
* @param uri the URI
|
||||
* @param request the request message
|
||||
* @param response the response message
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
protected abstract void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response)
|
||||
throws IOException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ResponseCreator} that holds an error message.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
class ErrorResponseCreator implements ResponseCreator {
|
||||
|
||||
private final String errorMessage;
|
||||
|
||||
ErrorResponseCreator(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public WebServiceMessage createResponse(URI uri,
|
||||
WebServiceMessage request,
|
||||
WebServiceMessageFactory factory) throws IOException {
|
||||
// Do nothing
|
||||
return null;
|
||||
}
|
||||
|
||||
String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ResponseCreator} that responds by throwing either an {@link IOException} or a {@link
|
||||
* RuntimeException}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
class ExceptionResponseCreator implements ResponseCreator {
|
||||
|
||||
private final Exception exception;
|
||||
|
||||
ExceptionResponseCreator(IOException exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
ExceptionResponseCreator(RuntimeException exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public WebServiceMessage createResponse(URI uri,
|
||||
WebServiceMessage request,
|
||||
WebServiceMessageFactory factory) throws IOException {
|
||||
if (exception instanceof IOException) {
|
||||
throw (IOException) exception;
|
||||
}
|
||||
else {
|
||||
throw (RuntimeException) exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.transport.WebServiceConnection;
|
||||
|
||||
/**
|
||||
* Mock implementation of {@link WebServiceConnection}. Implements {@link ResponseActions} to form a fluent API.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
class MockSenderConnection implements WebServiceConnection, ResponseActions {
|
||||
|
||||
private final List<RequestMatcher> requestMatchers = new LinkedList<RequestMatcher>();
|
||||
|
||||
private URI uri;
|
||||
|
||||
private WebServiceMessage request;
|
||||
|
||||
private ResponseCreator responseCreator;
|
||||
|
||||
void addRequestMatcher(RequestMatcher requestMatcher) {
|
||||
Assert.notNull(requestMatcher, "'requestMatcher' must not be null");
|
||||
requestMatchers.add(requestMatcher);
|
||||
}
|
||||
|
||||
void setUri(URI uri) {
|
||||
Assert.notNull(uri, "'uri' must not be null");
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
// ResponseActions implementation
|
||||
|
||||
public ResponseActions andExpect(RequestMatcher requestMatcher) {
|
||||
addRequestMatcher(requestMatcher);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void andRespond(ResponseCreator responseCreator) {
|
||||
Assert.notNull(responseCreator, "'responseCreator' must not be null");
|
||||
this.responseCreator = responseCreator;
|
||||
}
|
||||
|
||||
// FaultAwareWebServiceConnection implementation
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void send(WebServiceMessage message) throws IOException {
|
||||
if (!requestMatchers.isEmpty()) {
|
||||
for (RequestMatcher requestMatcher : requestMatchers) {
|
||||
requestMatcher.match(uri, message);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("Unexpected send() for [" + message + "]");
|
||||
}
|
||||
this.request = message;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
|
||||
if (responseCreator != null) {
|
||||
return responseCreator.createResponse(uri, request, messageFactory);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public URI getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public boolean hasError() throws IOException {
|
||||
return responseCreator instanceof ErrorResponseCreator;
|
||||
}
|
||||
|
||||
public String getErrorMessage() throws IOException {
|
||||
if (responseCreator instanceof ErrorResponseCreator) {
|
||||
return ((ErrorResponseCreator) responseCreator).getErrorMessage();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
requestMatchers.clear();
|
||||
request = null;
|
||||
responseCreator = null;
|
||||
uri = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.transport.WebServiceMessageSender;
|
||||
|
||||
/**
|
||||
* Mock implementation of {@link WebServiceMessageSender}. Contains a list of expected {@link MockSenderConnection}s,
|
||||
* and iterates over those.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
class MockWebServiceMessageSender implements WebServiceMessageSender {
|
||||
|
||||
private final List<MockSenderConnection> expectedConnections = new LinkedList<MockSenderConnection>();
|
||||
|
||||
private Iterator<MockSenderConnection> connectionIterator;
|
||||
|
||||
public MockSenderConnection createConnection(URI uri) throws IOException {
|
||||
Assert.notNull(uri, "'uri' must not be null");
|
||||
if (connectionIterator == null) {
|
||||
connectionIterator = expectedConnections.iterator();
|
||||
}
|
||||
if (!connectionIterator.hasNext()) {
|
||||
throw new AssertionError("No further connections expected");
|
||||
}
|
||||
|
||||
MockSenderConnection currentConnection = connectionIterator.next();
|
||||
currentConnection.setUri(uri);
|
||||
return currentConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
void verifyConnections() {
|
||||
if (expectedConnections.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (connectionIterator == null || connectionIterator.hasNext()) {
|
||||
throw new AssertionError("Further connection(s) expected");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.client.core.WebServiceTemplate;
|
||||
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
|
||||
import org.springframework.ws.test.support.MockStrategiesHelper;
|
||||
|
||||
/**
|
||||
* <strong>Main entry point for client-side Web service testing</strong>. Typically used to test a {@link
|
||||
* WebServiceTemplate}, set up expectations on request messages, and create response messages.
|
||||
* <p/>
|
||||
* The typical usage of this class is:
|
||||
* <ol>
|
||||
* <li>Create a {@code MockWebServiceServer} instance by calling {@link #createServer(WebServiceTemplate)},
|
||||
* {@link #createServer(WebServiceGatewaySupport)}, or {@link #createServer(ApplicationContext)}.
|
||||
* <li>Set up request expectations by calling {@link #expect(RequestMatcher)}, possibly by using the default
|
||||
* {@link RequestMatcher} implementations provided in {@link RequestMatchers} (which can be statically imported).
|
||||
* Multiple expectations can be set up by chaining {@link ResponseActions#andExpect(RequestMatcher)} calls.</li>
|
||||
* <li>Create an appropriate response message by calling
|
||||
* {@link ResponseActions#andRespond(ResponseCreator) andRespond(ResponseCreator)}, possibly by using the default
|
||||
* {@link ResponseCreator} implementations provided in {@link ResponseCreators} (which can be statically imported).</li>
|
||||
* <li>Use the {@code WebServiceTemplate} as normal, either directly of through client code.</li>
|
||||
* <li>Call {@link #verify()}.</ol>
|
||||
* Note that because of the 'fluent' API offered by this class (and related classes), you can typically use the Code
|
||||
* Completion features (i.e. ctrl-space) in your IDE to set up the mocks.
|
||||
* <p/>
|
||||
* For example:
|
||||
* <blockquote><pre>
|
||||
* import org.junit.*;
|
||||
* import org.springframework.beans.factory.annotation.Autowired;
|
||||
* 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.client.MockWebServiceServer</strong>;
|
||||
* <strong>import static org.springframework.ws.test.client.RequestMatchers.*</strong>;
|
||||
* <strong>import static org.springframework.ws.test.client.ResponseCreators.*</strong>;
|
||||
*
|
||||
* @RunWith(SpringJUnit4ClassRunner.class)
|
||||
* @ContextConfiguration("applicationContext.xml")
|
||||
* public class MyWebServiceClientIntegrationTest {
|
||||
*
|
||||
* // MyWebServiceClient extends WebServiceGatewaySupport, and is configured in applicationContext.xml
|
||||
* @Autowired
|
||||
* private MyWebServiceClient client;
|
||||
*
|
||||
* private MockWebServiceServer mockServer;
|
||||
*
|
||||
* @Before
|
||||
* public void createServer() throws Exception {
|
||||
* <strong>mockServer = MockWebServiceServer.createServer(client)</strong>;
|
||||
* }
|
||||
*
|
||||
* @Test
|
||||
* public void getCustomerCount() throws Exception {
|
||||
* Source expectedRequestPayload =
|
||||
* new StringSource("<customerCountRequest xmlns=\"http://springframework.org/spring-ws/test\" />");
|
||||
* Source responsePayload = new StringSource("<customerCountResponse xmlns='http://springframework.org/spring-ws/test'>" +
|
||||
* "<customerCount>10</customerCount>" +
|
||||
* "</customerCountResponse>");
|
||||
*
|
||||
* <strong>mockServer.expect(payload(expectedRequestPayload)).andRespond(withPayload(responsePayload));</strong>
|
||||
*
|
||||
* // client.getCustomerCount() uses the WebServiceTemplate
|
||||
* int customerCount = client.getCustomerCount();
|
||||
* assertEquals(10, response.getCustomerCount());
|
||||
*
|
||||
* <strong>mockServer.verify();</strong>
|
||||
* }
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MockWebServiceServer {
|
||||
|
||||
private final MockWebServiceMessageSender mockMessageSender;
|
||||
|
||||
private MockWebServiceServer(MockWebServiceMessageSender mockMessageSender) {
|
||||
Assert.notNull(mockMessageSender, "'mockMessageSender' must not be null");
|
||||
this.mockMessageSender = mockMessageSender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code MockWebServiceServer} instance based on the given {@link WebServiceTemplate}.
|
||||
*
|
||||
* @param webServiceTemplate the web service template
|
||||
* @return the created server
|
||||
*/
|
||||
public static MockWebServiceServer createServer(WebServiceTemplate webServiceTemplate) {
|
||||
Assert.notNull(webServiceTemplate, "'webServiceTemplate' must not be null");
|
||||
|
||||
MockWebServiceMessageSender mockMessageSender = new MockWebServiceMessageSender();
|
||||
webServiceTemplate.setMessageSender(mockMessageSender);
|
||||
|
||||
return new MockWebServiceServer(mockMessageSender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code MockWebServiceServer} instance based on the given {@link WebServiceGatewaySupport}.
|
||||
*
|
||||
* @param gatewaySupport the client class
|
||||
* @return the created server
|
||||
*/
|
||||
public static MockWebServiceServer createServer(WebServiceGatewaySupport gatewaySupport) {
|
||||
Assert.notNull(gatewaySupport, "'gatewaySupport' must not be null");
|
||||
return createServer(gatewaySupport.getWebServiceTemplate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code MockWebServiceServer} instance based on the given {@link ApplicationContext}.
|
||||
* <p/>
|
||||
* This factory method will try and find a configured {@link WebServiceTemplate} in the given application context.
|
||||
* If no template can be found, it will try and find a {@link WebServiceGatewaySupport}, and use its configured
|
||||
* template. If neither can be found, an exception is thrown.
|
||||
*
|
||||
* @param applicationContext the application context to base the client on
|
||||
* @return the created server
|
||||
* @throws IllegalArgumentException if the given application context contains neither a {@link WebServiceTemplate}
|
||||
* nor a {@link WebServiceGatewaySupport}.
|
||||
*/
|
||||
public static MockWebServiceServer createServer(ApplicationContext applicationContext) {
|
||||
MockStrategiesHelper strategiesHelper = new MockStrategiesHelper(applicationContext);
|
||||
WebServiceTemplate webServiceTemplate = strategiesHelper.getStrategy(WebServiceTemplate.class);
|
||||
if (webServiceTemplate != null) {
|
||||
return createServer(webServiceTemplate);
|
||||
}
|
||||
WebServiceGatewaySupport gatewaySupport = strategiesHelper.getStrategy(WebServiceGatewaySupport.class);
|
||||
if (gatewaySupport != null) {
|
||||
return createServer(gatewaySupport);
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"Could not find either WebServiceTemplate or WebServiceGatewaySupport in application context");
|
||||
}
|
||||
|
||||
/**
|
||||
* Records an expectation specified by the given {@link RequestMatcher}. Returns a {@link ResponseActions} object
|
||||
* that allows for creating the response, or to set up more expectations.
|
||||
*
|
||||
* @param requestMatcher the request matcher expected
|
||||
* @return the response actions
|
||||
*/
|
||||
public ResponseActions expect(RequestMatcher requestMatcher) {
|
||||
MockSenderConnection connection = mockMessageSender.expectNewConnection();
|
||||
connection.addRequestMatcher(requestMatcher);
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that all expectations were met.
|
||||
*
|
||||
* @throws AssertionError in case of unmet expectations
|
||||
*/
|
||||
public void verify() {
|
||||
mockMessageSender.verifyConnections();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
/**
|
||||
* Defines the contract for matching requests to expectations.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface RequestMatcher {
|
||||
|
||||
/**
|
||||
* Matches the given request message against the expectations. Implementations typically make use of JUnit-based
|
||||
* assertions.
|
||||
*
|
||||
* @param uri the uri connected to
|
||||
* @param request the request message to make assertions on
|
||||
* @throws IOException in case of I/O errors
|
||||
* @throws AssertionError if expectations are not met
|
||||
*/
|
||||
void match(URI uri, WebServiceMessage request) throws IOException, AssertionError;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright 2005-2012 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.QName;
|
||||
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.test.support.matcher.PayloadDiffMatcher;
|
||||
import org.springframework.ws.test.support.matcher.SchemaValidatingMatcher;
|
||||
import org.springframework.ws.test.support.matcher.SoapEnvelopeDiffMatcher;
|
||||
import org.springframework.ws.test.support.matcher.SoapHeaderMatcher;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
|
||||
/**
|
||||
* Factory methods for {@link RequestMatcher} classes. Typically used to provide input for {@link
|
||||
* MockWebServiceServer#expect(RequestMatcher)}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class RequestMatchers {
|
||||
|
||||
private 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 {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Payload
|
||||
|
||||
/**
|
||||
* Expects the given {@link javax.xml.transform.Source} XML payload.
|
||||
*
|
||||
* @param payload the XML payload
|
||||
* @return the request matcher
|
||||
*/
|
||||
public static RequestMatcher payload(Source payload) {
|
||||
Assert.notNull(payload, "'payload' must not be null");
|
||||
return new WebServiceMessageMatcherAdapter(new PayloadDiffMatcher(payload));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the given {@link org.springframework.core.io.Resource} XML payload.
|
||||
*
|
||||
* @param payload the XML payload
|
||||
* @return the request matcher
|
||||
*/
|
||||
public static RequestMatcher payload(Resource payload) throws IOException {
|
||||
Assert.notNull(payload, "'payload' must not be null");
|
||||
return payload(new ResourceSource(payload));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the payload to validate against the given XSD schema(s).
|
||||
*
|
||||
* @param schema the schema
|
||||
* @param furtherSchemas further schemas, if necessary
|
||||
* @return the request matcher
|
||||
*/
|
||||
public static RequestMatcher validPayload(Resource schema, Resource... furtherSchemas) throws IOException {
|
||||
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 RequestXPathExpectations 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 RequestXPathExpectations xpath(String xpathExpression, Map<String, String> namespaceMapping) {
|
||||
return new XPathExpectationsHelperAdapter(xpathExpression, namespaceMapping);
|
||||
}
|
||||
|
||||
// SOAP
|
||||
|
||||
/**
|
||||
* Expects the given {@link javax.xml.transform.Source} XML SOAP envelope.
|
||||
*
|
||||
* @param soapEnvelope the XML SOAP envelope
|
||||
* @return the request matcher
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public static RequestMatcher soapEnvelope(Source soapEnvelope) {
|
||||
Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
|
||||
return new WebServiceMessageMatcherAdapter(new SoapEnvelopeDiffMatcher(soapEnvelope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the given {@link org.springframework.core.io.Resource} XML SOAP envelope.
|
||||
*
|
||||
* @param soapEnvelope the XML SOAP envelope
|
||||
* @return the request matcher
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public static RequestMatcher soapEnvelope(Resource soapEnvelope) throws IOException {
|
||||
Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
|
||||
return soapEnvelope(new ResourceSource(soapEnvelope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the given SOAP header in the outgoing message.
|
||||
*
|
||||
* @param soapHeaderName the qualified name of the SOAP header to expect
|
||||
* @return the request matcher
|
||||
*/
|
||||
public static RequestMatcher soapHeader(QName soapHeaderName) {
|
||||
Assert.notNull(soapHeaderName, "'soapHeaderName' must not be null");
|
||||
return new WebServiceMessageMatcherAdapter(new SoapHeaderMatcher(soapHeaderName));
|
||||
}
|
||||
|
||||
// Other
|
||||
|
||||
/**
|
||||
* Expects a connection to the given URI.
|
||||
*
|
||||
* @param uri the String uri expected to connect to
|
||||
* @return the request matcher
|
||||
*/
|
||||
public static RequestMatcher connectionTo(String uri) {
|
||||
Assert.notNull(uri, "'uri' must not be null");
|
||||
return connectionTo(URI.create(uri));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects a connection to the given URI.
|
||||
*
|
||||
* @param uri the String uri expected to connect to
|
||||
* @return the request matcher
|
||||
*/
|
||||
public static RequestMatcher connectionTo(URI uri) {
|
||||
Assert.notNull(uri, "'uri' must not be null");
|
||||
return new UriMatcher(uri);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.client;
|
||||
|
||||
/**
|
||||
* Allows for setting up expectations on XPath expressions.
|
||||
* <p/>
|
||||
* Implementations of this interface are returned by {@link RequestMatchers#xpath(String)} and {@link
|
||||
* 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 RequestMatchers#xpath(String)
|
||||
* @see RequestMatchers#xpath(String, java.util.Map)
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface RequestXPathExpectations {
|
||||
|
||||
/**
|
||||
* Expects the XPath expression to exist.
|
||||
*
|
||||
* @return the request matcher
|
||||
*/
|
||||
RequestMatcher exists();
|
||||
|
||||
/**
|
||||
* Expects the XPath expression to not exist.
|
||||
*
|
||||
* @return the request matcher
|
||||
*/
|
||||
RequestMatcher doesNotExist();
|
||||
|
||||
/**
|
||||
* Expects the XPath expression to evaluate to the given boolean.
|
||||
*
|
||||
* @param expectedValue the expected value
|
||||
* @return the request matcher
|
||||
*/
|
||||
RequestMatcher evaluatesTo(final boolean expectedValue);
|
||||
|
||||
/**
|
||||
* Expects the XPath expression to evaluate to the given integer.
|
||||
*
|
||||
* @param expectedValue the expected value
|
||||
* @return the request matcher
|
||||
*/
|
||||
RequestMatcher evaluatesTo(int expectedValue);
|
||||
|
||||
/**
|
||||
* Expects the XPath expression to evaluate to the given double.
|
||||
*
|
||||
* @param expectedValue the expected value
|
||||
* @return the request matcher
|
||||
*/
|
||||
RequestMatcher evaluatesTo(double expectedValue);
|
||||
|
||||
/**
|
||||
* Expects the XPath expression to evaluate to the given string.
|
||||
*
|
||||
* @param expectedValue the expected value
|
||||
* @return the request matcher
|
||||
*/
|
||||
RequestMatcher evaluatesTo(String expectedValue);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
/**
|
||||
* Allows for setting up responses and additional expectations. Implementations of this interface are returned by
|
||||
* {@link MockWebServiceServer#expect(RequestMatcher)}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface ResponseActions {
|
||||
/**
|
||||
* Allows for further expectations to be set on the request.
|
||||
*
|
||||
* @return the request expectations
|
||||
*/
|
||||
ResponseActions andExpect(RequestMatcher requestMatcher);
|
||||
|
||||
/**
|
||||
* Sets the {@link ResponseCreator} for this mock.
|
||||
*
|
||||
* @param responseCreator the response creator
|
||||
*/
|
||||
void andRespond(ResponseCreator responseCreator);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Allows for creating up responses. Implementations of this interface are returned by {@link ResponseCreators}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface ResponseCreator {
|
||||
|
||||
/**
|
||||
* Create a response for the given the request and URI.
|
||||
*
|
||||
* @param uri the URI
|
||||
* @param request the request message
|
||||
* @param messageFactory the message that can be used to create responses
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
WebServiceMessage createResponse(URI uri, WebServiceMessage request, WebServiceMessageFactory messageFactory) throws IOException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright 2005-2012 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Locale;
|
||||
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.WebServiceMessageFactory;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.test.support.creator.PayloadMessageCreator;
|
||||
import org.springframework.ws.test.support.creator.SoapEnvelopeMessageCreator;
|
||||
import org.springframework.ws.test.support.creator.WebServiceMessageCreator;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
|
||||
/**
|
||||
* Factory methods for {@link ResponseCreator} classes. Typically used to provide input for {@link
|
||||
* ResponseActions#andRespond(ResponseCreator)}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class ResponseCreators {
|
||||
|
||||
private ResponseCreators() {
|
||||
}
|
||||
|
||||
// Payload
|
||||
|
||||
/**
|
||||
* Respond with the given {@link javax.xml.transform.Source} XML as payload response.
|
||||
*
|
||||
* @param payload the response payload
|
||||
* @return the response callback
|
||||
*/
|
||||
public static ResponseCreator withPayload(Source payload) {
|
||||
Assert.notNull(payload, "'payload' must not be null");
|
||||
return new WebServiceMessageCreatorAdapter(new PayloadMessageCreator(payload));
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with the given {@link org.springframework.core.io.Resource} XML as payload response.
|
||||
*
|
||||
* @param payload the response payload
|
||||
* @return the response callback
|
||||
*/
|
||||
public static ResponseCreator withPayload(Resource payload) throws IOException {
|
||||
Assert.notNull(payload, "'payload' must not be null");
|
||||
return withPayload(new ResourceSource(payload));
|
||||
}
|
||||
|
||||
// Error/Exception
|
||||
|
||||
/**
|
||||
* Respond with an error.
|
||||
*
|
||||
* @param errorMessage the error message
|
||||
* @return the response callback
|
||||
* @see org.springframework.ws.transport.WebServiceConnection#hasError()
|
||||
* @see org.springframework.ws.transport.WebServiceConnection#getErrorMessage()
|
||||
*/
|
||||
public static ResponseCreator withError(String errorMessage) {
|
||||
Assert.hasLength(errorMessage, "'errorMessage' must not be empty");
|
||||
return new ErrorResponseCreator(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with an {@link java.io.IOException}.
|
||||
*
|
||||
* @param ioException the exception to be thrown
|
||||
* @return the response callback
|
||||
*/
|
||||
public static ResponseCreator withException(IOException ioException) {
|
||||
Assert.notNull(ioException, "'ioException' must not be null");
|
||||
return new ExceptionResponseCreator(ioException);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with an {@link RuntimeException}.
|
||||
*
|
||||
* @param ex the runtime exception to be thrown
|
||||
* @return the response callback
|
||||
*/
|
||||
public static ResponseCreator withException(RuntimeException ex) {
|
||||
Assert.notNull(ex, "'ex' must not be null");
|
||||
return new ExceptionResponseCreator(ex);
|
||||
}
|
||||
|
||||
// SOAP
|
||||
|
||||
/**
|
||||
* Respond with the given {@link javax.xml.transform.Source} XML as SOAP envelope response.
|
||||
*
|
||||
* @param soapEnvelope the response SOAP envelope
|
||||
* @return the response callback
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public static ResponseCreator withSoapEnvelope(Source soapEnvelope) {
|
||||
Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
|
||||
return new WebServiceMessageCreatorAdapter(new SoapEnvelopeMessageCreator(soapEnvelope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with the given {@link org.springframework.core.io.Resource} XML as SOAP envelope response.
|
||||
*
|
||||
* @param soapEnvelope the response SOAP envelope
|
||||
* @return the response callback
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public static ResponseCreator withSoapEnvelope(Resource soapEnvelope) throws IOException {
|
||||
Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
|
||||
return withSoapEnvelope(new ResourceSource(soapEnvelope));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Respond with a {@code MustUnderstand} fault.
|
||||
*
|
||||
* @param faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text
|
||||
* @param locale the language of faultStringOrReason. Optional for SOAP 1.1
|
||||
* @see SoapBody#addMustUnderstandFault(String, java.util.Locale)
|
||||
*/
|
||||
public static ResponseCreator withMustUnderstandFault(final String faultStringOrReason, final Locale locale) {
|
||||
Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty");
|
||||
return new SoapFaultResponseCreator() {
|
||||
@Override
|
||||
public void addSoapFault(SoapBody soapBody) {
|
||||
soapBody.addMustUnderstandFault(faultStringOrReason, locale);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with a {@code Client} (SOAP 1.1) or {@code Sender} (SOAP 1.2) fault.
|
||||
*
|
||||
* @param faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text
|
||||
* @param locale the language of faultStringOrReason. Optional for SOAP 1.1
|
||||
* @see org.springframework.ws.soap.SoapBody#addClientOrSenderFault(String, Locale)
|
||||
*/
|
||||
public static ResponseCreator withClientOrSenderFault(final String faultStringOrReason, final Locale locale) {
|
||||
Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty");
|
||||
return new SoapFaultResponseCreator() {
|
||||
@Override
|
||||
public void addSoapFault(SoapBody soapBody) {
|
||||
soapBody.addClientOrSenderFault(faultStringOrReason, locale);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with a {@code Server} (SOAP 1.1) or {@code Receiver} (SOAP 1.2) fault.
|
||||
*
|
||||
* @param faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text
|
||||
* @param locale the language of faultStringOrReason. Optional for SOAP 1.1
|
||||
* @see org.springframework.ws.soap.SoapBody#addServerOrReceiverFault(String, Locale)
|
||||
*/
|
||||
public static ResponseCreator withServerOrReceiverFault(final String faultStringOrReason, final Locale locale) {
|
||||
Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty");
|
||||
return new SoapFaultResponseCreator() {
|
||||
@Override
|
||||
public void addSoapFault(SoapBody soapBody) {
|
||||
soapBody.addServerOrReceiverFault(faultStringOrReason, locale);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with a {@code VersionMismatch} fault.
|
||||
*
|
||||
* @param faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text
|
||||
* @param locale the language of faultStringOrReason. Optional for SOAP 1.1
|
||||
* @see org.springframework.ws.soap.SoapBody#addVersionMismatchFault(String, Locale)
|
||||
*/
|
||||
public static ResponseCreator withVersionMismatchFault(final String faultStringOrReason, final Locale locale) {
|
||||
Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty");
|
||||
return new SoapFaultResponseCreator() {
|
||||
@Override
|
||||
public void addSoapFault(SoapBody soapBody) {
|
||||
soapBody.addVersionMismatchFault(faultStringOrReason, locale);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts a {@link WebServiceMessageCreator} to the {@link ResponseCreator} contract.
|
||||
*/
|
||||
private static class WebServiceMessageCreatorAdapter implements ResponseCreator {
|
||||
|
||||
private final WebServiceMessageCreator adaptee;
|
||||
|
||||
private WebServiceMessageCreatorAdapter(WebServiceMessageCreator adaptee) {
|
||||
this.adaptee = adaptee;
|
||||
}
|
||||
|
||||
public WebServiceMessage createResponse(URI uri,
|
||||
WebServiceMessage request,
|
||||
WebServiceMessageFactory messageFactory) throws IOException {
|
||||
return adaptee.createMessage(messageFactory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.fail;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ResponseCreator} that responds with a SOAP fault.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract class SoapFaultResponseCreator extends AbstractResponseCreator {
|
||||
|
||||
@Override
|
||||
protected void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
if (!(response instanceof SoapMessage)) {
|
||||
fail("Response is not a SOAP message");
|
||||
return;
|
||||
}
|
||||
SoapMessage soapResponse = (SoapMessage) response;
|
||||
SoapBody responseBody = soapResponse.getSoapBody();
|
||||
if (responseBody == null) {
|
||||
fail("SOAP message [" + response + "] does not contain SOAP body");
|
||||
}
|
||||
addSoapFault(responseBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract template method that allows subclasses to add a SOAP Fault to the given Body.
|
||||
*
|
||||
* @param soapBody the body to attach a fault to
|
||||
*/
|
||||
protected abstract void addSoapFault(SoapBody soapBody);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.assertEquals;
|
||||
|
||||
/**
|
||||
* Matches {@link URI}s.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
class UriMatcher implements RequestMatcher {
|
||||
|
||||
private final URI expected;
|
||||
|
||||
UriMatcher(URI expected) {
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
public void match(URI actual, WebServiceMessage request) {
|
||||
assertEquals("Unexpected connection", expected, actual, "Payload", request.getPayloadSource());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
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 RequestMatcher} contract.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
class WebServiceMessageMatcherAdapter implements RequestMatcher {
|
||||
|
||||
private final WebServiceMessageMatcher adaptee;
|
||||
|
||||
WebServiceMessageMatcherAdapter(WebServiceMessageMatcher adaptee) {
|
||||
Assert.notNull(adaptee, "'adaptee' must not be null");
|
||||
this.adaptee = adaptee;
|
||||
}
|
||||
|
||||
public void match(URI uri, WebServiceMessage request) throws IOException, AssertionError {
|
||||
adaptee.match(request);
|
||||
}
|
||||
}
|
||||
@@ -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.client;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.ws.test.support.matcher.XPathExpectationsHelper;
|
||||
|
||||
/**
|
||||
* Adapts {@link XPathExpectationsHelper} into the {@link RequestXPathExpectations} contract.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
class XPathExpectationsHelperAdapter implements RequestXPathExpectations {
|
||||
|
||||
private final XPathExpectationsHelper helper;
|
||||
|
||||
XPathExpectationsHelperAdapter(String expression, Map<String, String> namespaces) {
|
||||
helper = new XPathExpectationsHelper(expression, namespaces);
|
||||
}
|
||||
|
||||
public RequestMatcher exists() {
|
||||
return new WebServiceMessageMatcherAdapter(helper.exists());
|
||||
}
|
||||
|
||||
public RequestMatcher doesNotExist() {
|
||||
return new WebServiceMessageMatcherAdapter(helper.doesNotExist());
|
||||
}
|
||||
|
||||
public RequestMatcher evaluatesTo(boolean expectedValue) {
|
||||
return new WebServiceMessageMatcherAdapter(helper.evaluatesTo(expectedValue));
|
||||
}
|
||||
|
||||
public RequestMatcher evaluatesTo(int expectedValue) {
|
||||
return new WebServiceMessageMatcherAdapter(helper.evaluatesTo(expectedValue));
|
||||
}
|
||||
|
||||
public RequestMatcher evaluatesTo(double expectedValue) {
|
||||
return new WebServiceMessageMatcherAdapter(helper.evaluatesTo(expectedValue));
|
||||
}
|
||||
|
||||
public RequestMatcher evaluatesTo(String expectedValue) {
|
||||
return new WebServiceMessageMatcherAdapter(helper.evaluatesTo(expectedValue));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a testing framework for client-side Web service testing. This package contains the
|
||||
* {@link org.springframework.ws.test.client.MockWebServiceServer}, and various related test interfaces.
|
||||
*/
|
||||
package org.springframework.ws.test.client;
|
||||
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* 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.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.server.SoapMessageDispatcher;
|
||||
import org.springframework.ws.test.support.MockStrategiesHelper;
|
||||
import org.springframework.ws.transport.WebServiceMessageReceiver;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.fail;
|
||||
|
||||
/**
|
||||
* <strong>Main entry point for server-side Web service testing</strong>. Typically used to test a {@link
|
||||
* org.springframework.ws.server.MessageDispatcher MessageDispatcher} (including its endpoints, mappings, etc) by
|
||||
* creating request messages, and setting up expectations about response messages.
|
||||
* <p/>
|
||||
* The typical usage of this class is:
|
||||
* <ol>
|
||||
* <li>Create a {@code MockWebServiceClient} instance by using {@link #createClient(ApplicationContext)} or
|
||||
* {@link #createClient(WebServiceMessageReceiver, WebServiceMessageFactory)}</li>
|
||||
* <li>Send request messages by calling {@link #sendRequest(RequestCreator)}, possibly by using the default
|
||||
* {@link RequestCreator} implementations provided in {@link RequestCreators} (which can be statically imported).</li>
|
||||
* <li>Set up response expectations by calling {@link ResponseActions#andExpect(ResponseMatcher) andExpect(ResponseMatcher)},
|
||||
* possibly by using the default {@link ResponseMatcher} implementations provided in {@link ResponseMatchers}
|
||||
* (which can be statically imported). Multiple expectations can be set up by chaining {@code andExpect()} calls.</li>
|
||||
* </ol>
|
||||
* Note that because of the 'fluent' API offered by this class (and related classes), you can typically use the Code
|
||||
* Completion features (i.e. ctrl-space) in your IDE to set up the mocks.
|
||||
* <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>;
|
||||
*
|
||||
* @RunWith(SpringJUnit4ClassRunner.class)
|
||||
* @ContextConfiguration("applicationContext.xml")
|
||||
* public class MyWebServiceIntegrationTest {
|
||||
*
|
||||
* // a standard MessageDispatcherServlet application context, containing endpoints, mappings, etc.
|
||||
* @Autowired
|
||||
* private ApplicationContext applicationContext;
|
||||
*
|
||||
* private MockWebServiceClient mockClient;
|
||||
*
|
||||
* @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 <customerCount/> messages
|
||||
* @Test
|
||||
* public void customerCountEndpoint() throws Exception {
|
||||
* Source requestPayload = new StringSource(
|
||||
* "<customerCountRequest xmlns='http://springframework.org/spring-ws'>" +
|
||||
* "<customerName>John Doe</customerName>" +
|
||||
* "</customerCountRequest>");
|
||||
* Source expectedResponsePayload = new StringSource(
|
||||
* "<customerCountResponse xmlns='http://springframework.org/spring-ws'>" +
|
||||
* "<customerCount>42</customerCount>" +
|
||||
* "</customerCountResponse>");
|
||||
*
|
||||
* <strong>mockClient.sendMessage(withPayload(requestPayload)).andExpect(payload(expectedResponsePayload))</strong>;
|
||||
* }
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MockWebServiceClient {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(MockWebServiceClient.class);
|
||||
|
||||
private final WebServiceMessageReceiver messageReceiver;
|
||||
|
||||
private final WebServiceMessageFactory messageFactory;
|
||||
|
||||
// Constructors
|
||||
|
||||
private MockWebServiceClient(WebServiceMessageReceiver messageReceiver, WebServiceMessageFactory messageFactory) {
|
||||
Assert.notNull(messageReceiver, "'messageReceiver' must not be null");
|
||||
Assert.notNull(messageFactory, "'messageFactory' must not be null");
|
||||
this.messageReceiver = messageReceiver;
|
||||
this.messageFactory = messageFactory;
|
||||
}
|
||||
|
||||
// Factory methods
|
||||
|
||||
/**
|
||||
* Creates a {@code MockWebServiceClient} instance based on the given {@link WebServiceMessageReceiver} and {@link
|
||||
* WebServiceMessageFactory}.
|
||||
*
|
||||
* @param messageReceiver the message receiver, typically a {@link SoapMessageDispatcher}
|
||||
* @param messageFactory the message factory
|
||||
* @return the created client
|
||||
*/
|
||||
public static MockWebServiceClient createClient(WebServiceMessageReceiver messageReceiver,
|
||||
WebServiceMessageFactory messageFactory) {
|
||||
return new MockWebServiceClient(messageReceiver, messageFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code MockWebServiceClient} instance based on the given {@link ApplicationContext}.
|
||||
*
|
||||
* This factory method works in a similar fashion as the standard
|
||||
* {@link org.springframework.ws.transport.http.MessageDispatcherServlet MessageDispatcherServlet}. That is:
|
||||
* <ul>
|
||||
* <li>If a {@link WebServiceMessageReceiver} is configured in the given application context, it will use that.
|
||||
* If no message receiver is configured, it will create a default {@link SoapMessageDispatcher}.</li>
|
||||
* <li>If a {@link WebServiceMessageFactory} is configured in the given application context, it will use that.
|
||||
* If no message factory is configured, it will create a default {@link SaajSoapMessageFactory}.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param applicationContext the application context to base the client on
|
||||
* @return the created client
|
||||
*/
|
||||
public static MockWebServiceClient createClient(ApplicationContext applicationContext) {
|
||||
Assert.notNull(applicationContext, "'applicationContext' must not be null");
|
||||
|
||||
MockStrategiesHelper strategiesHelper = new MockStrategiesHelper(applicationContext);
|
||||
|
||||
WebServiceMessageReceiver messageReceiver =
|
||||
strategiesHelper.getStrategy(WebServiceMessageReceiver.class, SoapMessageDispatcher.class);
|
||||
WebServiceMessageFactory messageFactory =
|
||||
strategiesHelper.getStrategy(WebServiceMessageFactory.class, SaajSoapMessageFactory.class);
|
||||
return new MockWebServiceClient(messageReceiver, messageFactory);
|
||||
}
|
||||
|
||||
// Sending
|
||||
|
||||
/**
|
||||
* Sends a request message by using the given {@link RequestCreator}. Typically called by using the default request
|
||||
* creators provided by {@link RequestCreators}.
|
||||
*
|
||||
* @param requestCreator the request creator
|
||||
* @return the response actions
|
||||
* @see RequestCreators
|
||||
*/
|
||||
public ResponseActions sendRequest(RequestCreator requestCreator) {
|
||||
Assert.notNull(requestCreator, "'requestCreator' must not be null");
|
||||
try {
|
||||
WebServiceMessage request = requestCreator.createRequest(messageFactory);
|
||||
MessageContext messageContext = new DefaultMessageContext(request, messageFactory);
|
||||
|
||||
messageReceiver.receive(messageContext);
|
||||
|
||||
return new MockWebServiceClientResponseActions(messageContext);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.error("Could not send request", ex);
|
||||
fail(ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ResponseActions
|
||||
|
||||
private static class MockWebServiceClientResponseActions implements ResponseActions {
|
||||
|
||||
private final MessageContext messageContext;
|
||||
|
||||
private MockWebServiceClientResponseActions(MessageContext messageContext) {
|
||||
Assert.notNull(messageContext, "'messageContext' must not be null");
|
||||
this.messageContext = messageContext;
|
||||
}
|
||||
|
||||
public ResponseActions andExpect(ResponseMatcher responseMatcher) {
|
||||
WebServiceMessage request = messageContext.getRequest();
|
||||
WebServiceMessage response = messageContext.getResponse();
|
||||
if (response == null) {
|
||||
fail("No response received");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
responseMatcher.match(request, response);
|
||||
return this;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error("Could not match request", ex);
|
||||
fail(ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Creates request messages. Implementations of this interface are returned by {@link RequestCreators}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see RequestCreators
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface RequestCreator {
|
||||
|
||||
/**
|
||||
* Create a request.
|
||||
*
|
||||
* @param messageFactory the message that can be used to create responses
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
WebServiceMessage createRequest(WebServiceMessageFactory messageFactory) throws IOException;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 2005-2012 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 javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.test.support.creator.PayloadMessageCreator;
|
||||
import org.springframework.ws.test.support.creator.SoapEnvelopeMessageCreator;
|
||||
import org.springframework.ws.test.support.creator.WebServiceMessageCreator;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
|
||||
/**
|
||||
* Factory methods for {@link RequestCreator} classes. Typically used to provide input for {@link
|
||||
* MockWebServiceClient#sendRequest(RequestCreator)}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class RequestCreators {
|
||||
|
||||
private RequestCreators() {
|
||||
}
|
||||
|
||||
// Payload
|
||||
|
||||
/**
|
||||
* Create a request with the given {@link Source} XML as payload.
|
||||
*
|
||||
* @param payload the request payload
|
||||
* @return the request creator
|
||||
*/
|
||||
public static RequestCreator withPayload(Source payload) {
|
||||
Assert.notNull(payload, "'payload' must not be null");
|
||||
return new WebServiceMessageCreatorAdapter(new PayloadMessageCreator(payload));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a request with the given {@link Resource} XML as payload.
|
||||
*
|
||||
* @param payload the request payload
|
||||
* @return the request creator
|
||||
*/
|
||||
public static RequestCreator withPayload(Resource payload) throws IOException {
|
||||
Assert.notNull(payload, "'payload' must not be null");
|
||||
return withPayload(new ResourceSource(payload));
|
||||
}
|
||||
|
||||
// SOAP
|
||||
|
||||
/**
|
||||
* Create a request with the given {@link Source} XML as SOAP envelope.
|
||||
*
|
||||
* @param soapEnvelope the request SOAP envelope
|
||||
* @return the request creator
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public static RequestCreator withSoapEnvelope(Source soapEnvelope) {
|
||||
Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
|
||||
return new WebServiceMessageCreatorAdapter(new SoapEnvelopeMessageCreator(soapEnvelope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a request with the given {@link Resource} XML as SOAP envelope.
|
||||
*
|
||||
* @param soapEnvelope the request SOAP envelope
|
||||
* @return the request creator
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public static RequestCreator withSoapEnvelope(Resource soapEnvelope) throws IOException {
|
||||
Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
|
||||
return withSoapEnvelope(new ResourceSource(soapEnvelope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts a {@link WebServiceMessageCreator} to the {@link RequestCreator} contract.
|
||||
*/
|
||||
private static class WebServiceMessageCreatorAdapter implements RequestCreator {
|
||||
|
||||
private final WebServiceMessageCreator adaptee;
|
||||
|
||||
private WebServiceMessageCreatorAdapter(WebServiceMessageCreator adaptee) {
|
||||
this.adaptee = adaptee;
|
||||
}
|
||||
|
||||
public WebServiceMessage createRequest(WebServiceMessageFactory messageFactory) throws IOException {
|
||||
return adaptee.createMessage(messageFactory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 expectation about response messages. Implementations of this interface are returned by
|
||||
* {@link MockWebServiceClient#sendRequest(RequestCreator)}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface ResponseActions {
|
||||
|
||||
/**
|
||||
* Sets up an expectation about the response message.
|
||||
*
|
||||
* @param responseMatcher the response matcher that defines expectations
|
||||
* @return an instance of {@link ResponseActions}, to set up further expectations
|
||||
*/
|
||||
ResponseActions andExpect(ResponseMatcher responseMatcher);
|
||||
|
||||
}
|
||||
@@ -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.ws.WebServiceMessage;
|
||||
|
||||
/**
|
||||
* Defines the contract for matching response messages to expectations. Implementations of this interface are returned
|
||||
* by {@link ResponseMatchers}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface ResponseMatcher {
|
||||
|
||||
/**
|
||||
* Matches the given response message against the expectations. Implementations typically make use of JUnit-based
|
||||
* assertions.
|
||||
*
|
||||
* @param request the request message
|
||||
* @param response the response message to make assertions on
|
||||
* @throws IOException in case of I/O errors
|
||||
* @throws AssertionError if expectations are not met
|
||||
*/
|
||||
void match(WebServiceMessage request, WebServiceMessage response) throws IOException, AssertionError;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright 2005-2012 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 java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.FaultAwareWebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
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.SoapEnvelopeDiffMatcher;
|
||||
import org.springframework.ws.test.support.matcher.SoapHeaderMatcher;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.fail;
|
||||
|
||||
/**
|
||||
* Factory methods for {@link ResponseMatcher} classes. Typically used to provide input for {@link
|
||||
* ResponseActions#andExpect(ResponseMatcher)}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class ResponseMatchers {
|
||||
|
||||
private ResponseMatchers() {
|
||||
}
|
||||
|
||||
// Payload
|
||||
|
||||
/**
|
||||
* Expects the given {@link Source} XML payload.
|
||||
*
|
||||
* @param payload the XML payload
|
||||
* @return the response matcher
|
||||
*/
|
||||
public static ResponseMatcher payload(Source payload) {
|
||||
return new WebServiceMessageMatcherAdapter(new PayloadDiffMatcher(payload));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the given {@link Resource} XML payload.
|
||||
*
|
||||
* @param payload the XML payload
|
||||
* @return the response matcher
|
||||
*/
|
||||
public static ResponseMatcher payload(Resource payload) throws IOException {
|
||||
return payload(new ResourceSource(payload));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the payload to validate against the given XSD schema(s).
|
||||
*
|
||||
* @param schema the schema
|
||||
* @param furtherSchemas further schemas, if necessary
|
||||
* @return the response matcher
|
||||
*/
|
||||
public static ResponseMatcher validPayload(Resource schema, Resource... furtherSchemas) throws IOException {
|
||||
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
|
||||
|
||||
/**
|
||||
* Expects the given {@link Source} XML SOAP envelope.
|
||||
*
|
||||
* @param soapEnvelope the XML SOAP envelope
|
||||
* @return the response matcher
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public static ResponseMatcher soapEnvelope(Source soapEnvelope) {
|
||||
return new WebServiceMessageMatcherAdapter(new SoapEnvelopeDiffMatcher(soapEnvelope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the given {@link Resource} XML SOAP envelope.
|
||||
*
|
||||
* @param soapEnvelope the XML SOAP envelope
|
||||
* @return the response matcher
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public static ResponseMatcher soapEnvelope(Resource soapEnvelope) throws IOException {
|
||||
return soapEnvelope(new ResourceSource(soapEnvelope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the given SOAP header in the outgoing message.
|
||||
*
|
||||
* @param soapHeaderName the qualified name of the SOAP header to expect
|
||||
* @return the request matcher
|
||||
*/
|
||||
public static ResponseMatcher soapHeader(QName soapHeaderName) {
|
||||
Assert.notNull(soapHeaderName, "'soapHeaderName' must not be null");
|
||||
return new WebServiceMessageMatcherAdapter(new SoapHeaderMatcher(soapHeaderName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the response <strong>not</strong> to contain a SOAP fault.
|
||||
*
|
||||
* @return the response matcher
|
||||
*/
|
||||
public static ResponseMatcher noFault() {
|
||||
return new ResponseMatcher() {
|
||||
public void match(WebServiceMessage request, WebServiceMessage response)
|
||||
throws IOException, AssertionError {
|
||||
if (response instanceof FaultAwareWebServiceMessage) {
|
||||
FaultAwareWebServiceMessage faultMessage = (FaultAwareWebServiceMessage) response;
|
||||
if (faultMessage.hasFault()) {
|
||||
fail("Response has a SOAP Fault: \"" + faultMessage.getFaultReason() + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects a {@code MustUnderstand} fault.
|
||||
*
|
||||
* @see org.springframework.ws.soap.SoapBody#addMustUnderstandFault(String, Locale)
|
||||
*/
|
||||
public static ResponseMatcher mustUnderstandFault() {
|
||||
return mustUnderstandFault(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects a {@code MustUnderstand} fault with a particular fault string or reason.
|
||||
*
|
||||
* @param faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text. If {@code null} the fault string or
|
||||
* reason text will not be verified
|
||||
* @see org.springframework.ws.soap.SoapBody#addMustUnderstandFault(String, Locale)
|
||||
*/
|
||||
public static ResponseMatcher mustUnderstandFault(String faultStringOrReason) {
|
||||
return new SoapFaultResponseMatcher(faultStringOrReason) {
|
||||
@Override
|
||||
protected QName getExpectedFaultCode(SoapVersion version) {
|
||||
return version.getMustUnderstandFaultName();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects a {@code Client} (SOAP 1.1) or {@code Sender} (SOAP 1.2) fault.
|
||||
*
|
||||
* @see org.springframework.ws.soap.SoapBody#addClientOrSenderFault(String, Locale)
|
||||
*/
|
||||
public static ResponseMatcher clientOrSenderFault() {
|
||||
return clientOrSenderFault(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects a {@code Client} (SOAP 1.1) or {@code Sender} (SOAP 1.2) fault with a particular fault string or reason.
|
||||
*
|
||||
* @param faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text. If {@code null} the fault string or
|
||||
* reason text will not be verified
|
||||
* @see org.springframework.ws.soap.SoapBody#addClientOrSenderFault(String, Locale)
|
||||
*/
|
||||
public static ResponseMatcher clientOrSenderFault(String faultStringOrReason) {
|
||||
return new SoapFaultResponseMatcher(faultStringOrReason) {
|
||||
@Override
|
||||
protected QName getExpectedFaultCode(SoapVersion version) {
|
||||
return version.getClientOrSenderFaultName();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects a {@code Server} (SOAP 1.1) or {@code Receiver} (SOAP 1.2) fault.
|
||||
*
|
||||
* @see org.springframework.ws.soap.SoapBody#addServerOrReceiverFault(String, java.util.Locale)
|
||||
*/
|
||||
public static ResponseMatcher serverOrReceiverFault() {
|
||||
return serverOrReceiverFault(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects a {@code Server} (SOAP 1.1) or {@code Receiver} (SOAP 1.2) fault with a particular fault string or reason.
|
||||
*
|
||||
* @param faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text. If {@code null} the fault string or
|
||||
* reason text will not be verified
|
||||
* @see org.springframework.ws.soap.SoapBody#addClientOrSenderFault(String, Locale)
|
||||
*/
|
||||
public static ResponseMatcher serverOrReceiverFault(String faultStringOrReason) {
|
||||
return new SoapFaultResponseMatcher(faultStringOrReason) {
|
||||
@Override
|
||||
protected QName getExpectedFaultCode(SoapVersion version) {
|
||||
return version.getServerOrReceiverFaultName();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects a {@code VersionMismatch} fault.
|
||||
*
|
||||
* @see org.springframework.ws.soap.SoapBody#addVersionMismatchFault(String, java.util.Locale)
|
||||
*/
|
||||
public static ResponseMatcher versionMismatchFault() {
|
||||
return versionMismatchFault(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects a {@code VersionMismatch} fault with a particular fault string or reason.
|
||||
*
|
||||
* @param faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text. If {@code null} the fault string or
|
||||
* reason text will not be verified
|
||||
* @see org.springframework.ws.soap.SoapBody#addClientOrSenderFault(String, Locale)
|
||||
*/
|
||||
public static ResponseMatcher versionMismatchFault(String faultStringOrReason) {
|
||||
return new SoapFaultResponseMatcher(faultStringOrReason) {
|
||||
@Override
|
||||
protected QName getExpectedFaultCode(SoapVersion version) {
|
||||
return version.getVersionMismatchFaultName();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 javax.xml.namespace.QName;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapFault;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.assertEquals;
|
||||
import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
|
||||
|
||||
/**
|
||||
* Abstract Implementation of {@link ResponseMatcher} that checks for a SOAP fault.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract class SoapFaultResponseMatcher implements ResponseMatcher {
|
||||
|
||||
private final String expectedFaultStringOrReason;
|
||||
|
||||
SoapFaultResponseMatcher(String expectedFaultStringOrReason) {
|
||||
this.expectedFaultStringOrReason = expectedFaultStringOrReason;
|
||||
}
|
||||
|
||||
public void match(WebServiceMessage request, WebServiceMessage response) throws IOException, AssertionError {
|
||||
assertTrue("Response is not a SOAP message", response instanceof SoapMessage);
|
||||
SoapMessage soapResponse = (SoapMessage) response;
|
||||
SoapBody responseBody = soapResponse.getSoapBody();
|
||||
assertTrue("Response has no SOAP Body", responseBody != null);
|
||||
assertTrue("Response has no SOAP Fault", responseBody.hasFault());
|
||||
SoapFault soapFault = responseBody.getFault();
|
||||
QName expectedFaultCode = getExpectedFaultCode(soapResponse.getVersion());
|
||||
assertEquals("Invalid SOAP Fault code", expectedFaultCode, soapFault.getFaultCode());
|
||||
if (expectedFaultStringOrReason != null) {
|
||||
assertEquals("Invalid SOAP Fault string/reason", expectedFaultStringOrReason,
|
||||
soapFault.getFaultStringOrReason());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SOAP fault code to check for, given the SOAP version.
|
||||
*/
|
||||
protected abstract QName getExpectedFaultCode(SoapVersion version);
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a testing framework for server-side Web service testing. This package contains the
|
||||
* {@link org.springframework.ws.test.server.MockWebServiceClient}, and various related test interfaces.
|
||||
*/
|
||||
package org.springframework.ws.test.server;
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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.Source;
|
||||
|
||||
/**
|
||||
* JUnit independent assertion class.
|
||||
*
|
||||
* @author Lukas Krecan
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AssertionErrors {
|
||||
|
||||
private AssertionErrors() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails a test with the given message.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public static void fail(String message) {
|
||||
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.
|
||||
*
|
||||
* @param message the message
|
||||
* @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, sourceLabel, source);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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 + ">", sourceLabel, source);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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.support;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Helper class for for loading default implementations of an interface.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MockStrategiesHelper {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(MockStrategiesHelper.class);
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code MockStrategiesHelper} with the given application context.
|
||||
*
|
||||
* @param applicationContext the application context
|
||||
*/
|
||||
public MockStrategiesHelper(ApplicationContext applicationContext) {
|
||||
Assert.notNull(applicationContext, "'applicationContext' must not be null");
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the application context.
|
||||
*/
|
||||
public ApplicationContext getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single strategy found in the given application context.
|
||||
*
|
||||
* @param type the type of bean to be found in the application context
|
||||
* @return the bean, or {@code null} if no bean of the given type can be found
|
||||
* @throws BeanInitializationException if there is more than 1 beans of the given type
|
||||
*/
|
||||
public <T> T getStrategy(Class<T> type) {
|
||||
Assert.notNull(type, "'type' must not be null");
|
||||
Map<String, T> map = applicationContext.getBeansOfType(type);
|
||||
if (map.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
else if (map.size() == 1) {
|
||||
Map.Entry<String, T> entry = map.entrySet().iterator().next();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Using " + ClassUtils.getShortName(type) + " [" + entry.getKey() + "]");
|
||||
}
|
||||
return entry.getValue();
|
||||
}
|
||||
else {
|
||||
throw new BeanInitializationException(
|
||||
"Could not find exactly 1 " + ClassUtils.getShortName(type) + " in application context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single strategy found in the given application context, or instantiates a default strategy if no
|
||||
* applicable strategy was found.
|
||||
*
|
||||
* @param type the type of bean to be found in the application context
|
||||
* @param defaultType the type to instantiate and return when no bean of the specified type could be found
|
||||
* @return the bean found in the application context, or the default type if no bean of the given type can be found
|
||||
* @throws BeanInitializationException if there is more than 1 beans of the given type
|
||||
*/
|
||||
public <T, D extends T> T getStrategy(Class<T> type, Class<D> defaultType) {
|
||||
Assert.notNull(defaultType, "'defaultType' must not be null");
|
||||
T t = getStrategy(type);
|
||||
if (t != null) {
|
||||
return t;
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("No " + ClassUtils.getShortName(type) + " found, using default " +
|
||||
ClassUtils.getShortName(defaultType));
|
||||
}
|
||||
T defaultStrategy = BeanUtils.instantiateClass(defaultType);
|
||||
if (defaultStrategy instanceof ApplicationContextAware) {
|
||||
ApplicationContextAware applicationContextAware = (ApplicationContextAware) defaultStrategy;
|
||||
applicationContextAware.setApplicationContext(applicationContext);
|
||||
}
|
||||
if (defaultStrategy instanceof InitializingBean) {
|
||||
InitializingBean initializingBean = (InitializingBean) defaultStrategy;
|
||||
try {
|
||||
initializingBean.afterPropertiesSet();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new BeanCreationException("Invocation of init method failed", ex);
|
||||
}
|
||||
}
|
||||
return defaultStrategy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.support.creator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Abstract base class for the {@link WebServiceMessageCreator} interface.
|
||||
* <p/>
|
||||
* Creates a message using the given {@link WebServiceMessageFactory}, and passes it on to {@link
|
||||
* #doWithMessage(WebServiceMessage)}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AbstractMessageCreator implements WebServiceMessageCreator {
|
||||
|
||||
public final WebServiceMessage createMessage(WebServiceMessageFactory messageFactory) throws IOException {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage();
|
||||
doWithMessage(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract template method, invoked by {@link #createMessage(WebServiceMessageFactory)} after a message has been
|
||||
* created.
|
||||
*
|
||||
* @param message the message
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
protected abstract void doWithMessage(WebServiceMessage message) throws IOException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.support.creator;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.xml.transform.TransformerHelper;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.fail;
|
||||
|
||||
/**
|
||||
* Implementation of {@link WebServiceMessageCreator} that creates a request based on a {@link Source}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PayloadMessageCreator extends AbstractMessageCreator {
|
||||
|
||||
private final Source payload;
|
||||
|
||||
private TransformerHelper transformerHelper = new TransformerHelper();
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code PayloadMessageCreator} with the given payload source.
|
||||
*
|
||||
* @param payload the payload source
|
||||
*/
|
||||
public PayloadMessageCreator(Source payload) {
|
||||
Assert.notNull(payload, "'payload' must not be null");
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWithMessage(WebServiceMessage message) throws IOException {
|
||||
try {
|
||||
transformerHelper.transform(payload, message.getPayloadResult());
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
fail("Could not transform request payload to message: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2005-2012 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.creator;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.xml.transform.TransformerHelper;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
|
||||
import static org.springframework.ws.test.support.AssertionErrors.fail;
|
||||
|
||||
/**
|
||||
* Implementation of {@link WebServiceMessageCreator} that creates a request based on a SOAP envelope {@link Source}.
|
||||
*
|
||||
* @author Alexander Shutyaev
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public class SoapEnvelopeMessageCreator extends AbstractMessageCreator {
|
||||
|
||||
private final Source soapEnvelope;
|
||||
|
||||
private final TransformerHelper transformerHelper = new TransformerHelper();
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code SoapEnvelopeMessageCreator} with the given SOAP envelope source.
|
||||
*
|
||||
* @param soapEnvelope the SOAP envelope source
|
||||
*/
|
||||
public SoapEnvelopeMessageCreator(Source soapEnvelope) {
|
||||
Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
|
||||
this.soapEnvelope = soapEnvelope;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWithMessage(WebServiceMessage message) throws IOException {
|
||||
assertTrue("Message created with factory is not a SOAP message", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
try {
|
||||
DOMResult result = new DOMResult();
|
||||
transformerHelper.transform(soapEnvelope, result);
|
||||
soapMessage.setDocument((Document) result.getNode());
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
fail("Could not transform request SOAP envelope to message: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.support.creator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Defines the general contract for creating messages used in test scenarios.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface WebServiceMessageCreator {
|
||||
|
||||
/**
|
||||
* Create a message.
|
||||
*
|
||||
* @param messageFactory the message that can be used to create the message
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
WebServiceMessage createMessage(WebServiceMessageFactory messageFactory) throws IOException;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides the generic {@link org.springframework.ws.test.support.creator.WebServiceMessageCreator WebServiceMessageCreator}
|
||||
* interface, and implementations.
|
||||
*/
|
||||
package org.springframework.ws.test.support.creator;
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.support.matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
|
||||
|
||||
/**
|
||||
* Abstract base class for SOAP-specific {@link WebServiceMessageMatcher} implementations.
|
||||
* <p/>
|
||||
* Asserts that the message given to {@link #match(WebServiceMessage)} is a {@link SoapMessage}, and invokes {@link
|
||||
* #match(SoapMessage)} with it if so.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AbstractSoapMessageMatcher implements WebServiceMessageMatcher {
|
||||
|
||||
public final void match(WebServiceMessage message) throws IOException, AssertionError {
|
||||
assertTrue("Message is not a SOAP message", message instanceof SoapMessage);
|
||||
match((SoapMessage) message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract template method that gets invoked from {@link #match(WebServiceMessage)} if the given message is a
|
||||
* {@link SoapMessage}.
|
||||
*
|
||||
* @param soapMessage the soap message
|
||||
* @throws IOException in case of I/O errors
|
||||
* @throws AssertionError if expectations are not met
|
||||
*/
|
||||
protected abstract void match(SoapMessage soapMessage) throws IOException, AssertionError;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
|
||||
|
||||
/**
|
||||
* Implementation of {@link WebServiceMessageMatcher} based on XMLUnit's {@link Diff}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class DiffMatcher implements WebServiceMessageMatcher {
|
||||
|
||||
static {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
public final void match(WebServiceMessage message) throws IOException, AssertionError {
|
||||
Diff diff = createDiff(message);
|
||||
assertTrue("Messages are different, " + diff.toString(), diff.similar(), "Payload", message.getPayloadSource());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Diff} for the given message.
|
||||
*
|
||||
* @param message the message
|
||||
* @return the diff
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
protected abstract Diff createDiff(WebServiceMessage message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.support.matcher;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.xml.transform.TransformerHelper;
|
||||
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.fail;
|
||||
|
||||
/**
|
||||
* Matches {@link Source} payloads.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PayloadDiffMatcher extends DiffMatcher {
|
||||
|
||||
private final Source expected;
|
||||
|
||||
private final TransformerHelper transformerHelper = new TransformerHelper();
|
||||
|
||||
public PayloadDiffMatcher(Source expected) {
|
||||
Assert.notNull(expected, "'expected' must not be null");
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Diff createDiff(WebServiceMessage message) {
|
||||
Source payload = message.getPayloadSource();
|
||||
if (payload == null) {
|
||||
fail("Request message does not contain payload");
|
||||
}
|
||||
return createDiff(payload);
|
||||
}
|
||||
|
||||
protected Diff createDiff(Source payload) {
|
||||
Document expectedDocument = createDocumentFromSource(expected);
|
||||
Document actualDocument = createDocumentFromSource(payload);
|
||||
return new Diff(expectedDocument, actualDocument);
|
||||
}
|
||||
|
||||
private Document createDocumentFromSource(Source source) {
|
||||
try {
|
||||
DOMResult result = new DOMResult();
|
||||
transformerHelper.transform(source, result);
|
||||
return (Document) result.getNode();
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
fail("Could not transform source to DOMResult" + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
import org.springframework.xml.validation.XmlValidatorFactory;
|
||||
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.fail;
|
||||
|
||||
/**
|
||||
* Uses the {@link XmlValidator} to validate request payload.
|
||||
*
|
||||
* @author Lukas Krecan
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SchemaValidatingMatcher implements WebServiceMessageMatcher {
|
||||
|
||||
private final XmlValidator xmlValidator;
|
||||
|
||||
/**
|
||||
* Creates a {@code SchemaValidatingMatcher} based on the given schema resource(s).
|
||||
*
|
||||
* @param schema the schema
|
||||
* @param furtherSchemas further schemas, if necessary
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public SchemaValidatingMatcher(Resource schema, Resource... furtherSchemas) throws IOException {
|
||||
Assert.notNull(schema, "'schema' must not be null");
|
||||
Resource[] joinedSchemas = new Resource[furtherSchemas.length + 1];
|
||||
joinedSchemas[0] = schema;
|
||||
System.arraycopy(furtherSchemas, 0, joinedSchemas, 1, furtherSchemas.length);
|
||||
xmlValidator = XmlValidatorFactory.createValidator(joinedSchemas, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
|
||||
}
|
||||
|
||||
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), "Payload", message.getPayloadSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2005-2012 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.matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.xml.transform.TransformerHelper;
|
||||
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
|
||||
import static org.springframework.ws.test.support.AssertionErrors.fail;
|
||||
|
||||
/**
|
||||
* Matches {@link Source} SOAP envelopes.
|
||||
*
|
||||
* @author Alexander Shutyaev
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public class SoapEnvelopeDiffMatcher extends AbstractSoapMessageMatcher {
|
||||
|
||||
private final Source expected;
|
||||
|
||||
private final TransformerHelper transformerHelper = new TransformerHelper();
|
||||
|
||||
static {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
public SoapEnvelopeDiffMatcher(Source expected) {
|
||||
Assert.notNull(expected, "'expected' must not be null");
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void match(SoapMessage soapMessage) throws IOException, AssertionError {
|
||||
Document actualDocument = soapMessage.getDocument();
|
||||
Document expectedDocument = createDocumentFromSource(expected);
|
||||
Diff diff = new Diff(expectedDocument, actualDocument);
|
||||
assertTrue("Envelopes are different, " + diff.toString(), diff.similar());
|
||||
}
|
||||
|
||||
private Document createDocumentFromSource(Source source) {
|
||||
try {
|
||||
DOMResult result = new DOMResult();
|
||||
transformerHelper.transform(source, result);
|
||||
return (Document) result.getNode();
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
fail("Could not transform source to DOMResult" + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.soap.SoapHeader;
|
||||
import org.springframework.ws.soap.SoapHeaderElement;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
|
||||
|
||||
/**
|
||||
* Matches SOAP headers.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SoapHeaderMatcher extends AbstractSoapMessageMatcher {
|
||||
|
||||
private final QName soapHeaderName;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code SoapHeaderMatcher} that checks for the presence of the given SOAP header
|
||||
* name.
|
||||
*
|
||||
* @param soapHeaderName the header name to check for
|
||||
*/
|
||||
public SoapHeaderMatcher(QName soapHeaderName) {
|
||||
Assert.notNull(soapHeaderName, "'soapHeaderName' must not be null");
|
||||
this.soapHeaderName = soapHeaderName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void match(SoapMessage soapMessage) throws IOException, AssertionError {
|
||||
SoapHeader soapHeader = soapMessage.getSoapHeader();
|
||||
assertTrue("SOAP message [" + soapMessage + "] does not contain SOAP header", soapHeader != null, "Envelope",
|
||||
soapMessage.getEnvelope().getSource());
|
||||
|
||||
Iterator<SoapHeaderElement> soapHeaderElementIterator = soapHeader.examineAllHeaderElements();
|
||||
boolean found = false;
|
||||
while (soapHeaderElementIterator.hasNext()) {
|
||||
SoapHeaderElement soapHeaderElement = soapHeaderElementIterator.next();
|
||||
if (soapHeaderName.equals(soapHeaderElement.getName())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue("SOAP header [" + soapHeaderName + "] not found", found, "Envelope",
|
||||
soapMessage.getEnvelope().getSource());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.support.matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
/**
|
||||
* Defines the general contract for matching messages to expectations.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface WebServiceMessageMatcher {
|
||||
|
||||
/**
|
||||
* Matches the given message against the expectations. Implementations typically make use of JUnit-based
|
||||
* assertions.
|
||||
*
|
||||
* @param message the message
|
||||
* @throws IOException in case of I/O errors
|
||||
* @throws AssertionError if expectations are not met
|
||||
*/
|
||||
void match(WebServiceMessage message) throws IOException, AssertionError;
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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.matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.xml.transform.TransformerHelper;
|
||||
import org.springframework.xml.xpath.XPathExpression;
|
||||
import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import static org.springframework.ws.test.support.AssertionErrors.assertEquals;
|
||||
import static org.springframework.ws.test.support.AssertionErrors.fail;
|
||||
|
||||
/**
|
||||
* Helper class for dealing with XPath expectations.
|
||||
*
|
||||
* @author Lukas Krecan
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XPathExpectationsHelper {
|
||||
|
||||
private final XPathExpression expression;
|
||||
|
||||
private final String expressionString;
|
||||
|
||||
private final TransformerHelper transformerHelper = new TransformerHelper();
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code XPathExpectationsSupport} with the given XPath expression.
|
||||
*
|
||||
* @param expression the XPath expression
|
||||
*/
|
||||
public XPathExpectationsHelper(String expression) {
|
||||
this(expression, null);
|
||||
}
|
||||
/**
|
||||
* Creates a new instance of the {@code XPathExpectationsSupport} with the given XPath expression and namespaces.
|
||||
*
|
||||
* @param expression the XPath expression
|
||||
* @param namespaces the namespaces, can be empty or {@code null}
|
||||
*/
|
||||
public XPathExpectationsHelper(String expression, Map<String, String> namespaces) {
|
||||
Assert.hasLength(expression, "'expression' must not be empty");
|
||||
this.expression = XPathExpressionFactory.createXPathExpression(expression, namespaces);
|
||||
this.expressionString = expression;
|
||||
}
|
||||
|
||||
public WebServiceMessageMatcher exists() {
|
||||
return new WebServiceMessageMatcher() {
|
||||
public void match(WebServiceMessage message) throws IOException, AssertionError {
|
||||
Node payload = transformToNode(message);
|
||||
Node result = expression.evaluateAsNode(payload);
|
||||
if (result == null) {
|
||||
fail("No match for \"" + expressionString + "\" found", "Payload", message.getPayloadSource());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public WebServiceMessageMatcher doesNotExist() {
|
||||
return new WebServiceMessageMatcher() {
|
||||
public void match(WebServiceMessage message) throws IOException, AssertionError {
|
||||
Node payload = transformToNode(message);
|
||||
Node result = expression.evaluateAsNode(payload);
|
||||
if (result != null) {
|
||||
fail("Match for \"" + expressionString + "\" found", "Payload", message.getPayloadSource());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public WebServiceMessageMatcher evaluatesTo(final boolean expectedValue) {
|
||||
return new WebServiceMessageMatcher() {
|
||||
public void match(WebServiceMessage message) throws IOException, AssertionError {
|
||||
Node payload = transformToNode(message);
|
||||
boolean result = expression.evaluateAsBoolean(payload);
|
||||
assertEquals("Evaluation of XPath expression \"" + expressionString + "\" failed.", expectedValue,
|
||||
result, "Payload", message.getPayloadSource());
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public WebServiceMessageMatcher evaluatesTo(int expectedValue) {
|
||||
return evaluatesTo((double) expectedValue);
|
||||
}
|
||||
|
||||
public WebServiceMessageMatcher evaluatesTo(final double expectedValue) {
|
||||
return new WebServiceMessageMatcher() {
|
||||
public void match(WebServiceMessage message) throws IOException, AssertionError {
|
||||
Node payload = transformToNode(message);
|
||||
double result = expression.evaluateAsNumber(payload);
|
||||
assertEquals("Evaluation of XPath expression \"" + expressionString + "\" failed.", expectedValue,
|
||||
result, "Payload", message.getPayloadSource());
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public WebServiceMessageMatcher evaluatesTo(final String expectedValue) {
|
||||
Assert.notNull(expectedValue, "'expectedValue' must not be null");
|
||||
return new WebServiceMessageMatcher() {
|
||||
public void match(WebServiceMessage message) throws IOException, AssertionError {
|
||||
Node payload = transformToNode(message);
|
||||
String result = expression.evaluateAsString(payload);
|
||||
assertEquals("Evaluation of XPath expression \"" + expressionString + "\" failed.", expectedValue,
|
||||
result, "Payload", message.getPayloadSource());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Node transformToNode(WebServiceMessage request) {
|
||||
DOMResult domResult = new DOMResult();
|
||||
try {
|
||||
transformerHelper.transform(request.getPayloadSource(), domResult);
|
||||
return domResult.getNode();
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
fail("Could not transform request payload: " + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides the generic {@link org.springframework.ws.test.support.matcher.WebServiceMessageMatcher WebServiceMessageMatcher}
|
||||
* interface, and implementations.
|
||||
*/
|
||||
package org.springframework.ws.test.support.matcher;
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Support classes for the testing framework, used by the classes in the {@link org.springframework.ws.test.client} and
|
||||
* {@link org.springframework.ws.test.server} packages.
|
||||
*/
|
||||
package org.springframework.ws.test.support;
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ErrorResponseCreatorTest {
|
||||
|
||||
@Test
|
||||
public void callback() throws IOException {
|
||||
String errorMessage = "Error message";
|
||||
ErrorResponseCreator callback = new ErrorResponseCreator(errorMessage);
|
||||
callback.createResponse(null, null, null);
|
||||
assertEquals(errorMessage, callback.getErrorMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExceptionResponseCreatorTest {
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void ioException() throws Exception {
|
||||
ExceptionResponseCreator callback = new ExceptionResponseCreator(new IOException());
|
||||
|
||||
callback.createResponse(null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void runtimeException() throws Exception {
|
||||
ExceptionResponseCreator callback = new ExceptionResponseCreator(new RuntimeException());
|
||||
|
||||
callback.createResponse(null, null, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.ws.test.client.ResponseCreators.withError;
|
||||
import static org.springframework.ws.test.client.ResponseCreators.withPayload;
|
||||
|
||||
public class MockSenderConnectionTest {
|
||||
|
||||
@Test
|
||||
public void error() throws IOException {
|
||||
String testErrorMessage = "Test Error Message";
|
||||
MockSenderConnection connection = new MockSenderConnection();
|
||||
connection.andRespond(withError(testErrorMessage));
|
||||
assertTrue(connection.hasError());
|
||||
assertEquals(testErrorMessage, connection.getErrorMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normal() throws IOException {
|
||||
MockSenderConnection connection = new MockSenderConnection();
|
||||
connection.andRespond(withPayload(new StringSource("<response/>")));
|
||||
assertFalse(connection.hasError());
|
||||
assertNull(connection.getErrorMessage());
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void noRequestMatchers() throws IOException {
|
||||
MockSenderConnection connection = new MockSenderConnection();
|
||||
connection.andRespond(withPayload(new StringSource("<response/>")));
|
||||
connection.send(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MockWebServiceMessageSenderTest {
|
||||
|
||||
private MockWebServiceMessageSender sender;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
sender = new MockWebServiceMessageSender();
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void noMoreExpectedConnections() throws IOException {
|
||||
sender.createConnection(URI.create("http://localhost"));
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void verify() throws IOException {
|
||||
sender.expectNewConnection();
|
||||
sender.verifyConnections();
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void verifyMoteThanOne() throws IOException {
|
||||
sender.expectNewConnection();
|
||||
sender.expectNewConnection();
|
||||
sender.createConnection(URI.create("http://localhost"));
|
||||
sender.verifyConnections();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.client.core.WebServiceMessageCallback;
|
||||
import org.springframework.ws.client.core.WebServiceTemplate;
|
||||
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.client.SoapFaultClientException;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.ws.test.client.RequestMatchers.*;
|
||||
import static org.springframework.ws.test.client.ResponseCreators.withClientOrSenderFault;
|
||||
import static org.springframework.ws.test.client.ResponseCreators.withPayload;
|
||||
|
||||
public class MockWebServiceServerTest {
|
||||
|
||||
private WebServiceTemplate template;
|
||||
|
||||
private MockWebServiceServer server;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
template = new WebServiceTemplate();
|
||||
template.setDefaultUri("http://example.com");
|
||||
|
||||
server = MockWebServiceServer.createServer(template);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createServerWebServiceTemplate() throws Exception {
|
||||
WebServiceTemplate template = new WebServiceTemplate();
|
||||
|
||||
MockWebServiceServer server = MockWebServiceServer.createServer(template);
|
||||
assertNotNull(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createServerGatewaySupport() throws Exception {
|
||||
MyClient client = new MyClient();
|
||||
|
||||
MockWebServiceServer server = MockWebServiceServer.createServer(client);
|
||||
assertNotNull(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createServerApplicationContextWebServiceTemplate() throws Exception {
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
applicationContext.registerSingleton("webServiceTemplate", WebServiceTemplate.class);
|
||||
applicationContext.refresh();
|
||||
|
||||
MockWebServiceServer server = MockWebServiceServer.createServer(applicationContext);
|
||||
assertNotNull(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createServerApplicationContextWebServiceGatewaySupport() throws Exception {
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
applicationContext.registerSingleton("myClient", MyClient.class);
|
||||
applicationContext.refresh();
|
||||
|
||||
MockWebServiceServer server = MockWebServiceServer.createServer(applicationContext);
|
||||
assertNotNull(server);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void createServerApplicationContextEmpty() throws Exception {
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
applicationContext.refresh();
|
||||
|
||||
MockWebServiceServer server = MockWebServiceServer.createServer(applicationContext);
|
||||
assertNotNull(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mocks() throws Exception {
|
||||
URI uri = URI.create("http://example.com");
|
||||
|
||||
RequestMatcher requestMatcher1 = createStrictMock("requestMatcher1", RequestMatcher.class);
|
||||
RequestMatcher requestMatcher2 = createStrictMock("requestMatcher2", RequestMatcher.class);
|
||||
ResponseCreator responseCreator = createStrictMock(ResponseCreator.class);
|
||||
|
||||
SaajSoapMessage response = new SaajSoapMessageFactory(MessageFactory.newInstance()).createWebServiceMessage();
|
||||
|
||||
requestMatcher1.match(eq(uri), isA(SaajSoapMessage.class));
|
||||
requestMatcher2.match(eq(uri), isA(SaajSoapMessage.class));
|
||||
expect(responseCreator.createResponse(eq(uri), isA(SaajSoapMessage.class), isA(SaajSoapMessageFactory.class)))
|
||||
.andReturn(response);
|
||||
|
||||
replay(requestMatcher1, requestMatcher2, responseCreator);
|
||||
|
||||
server.expect(requestMatcher1).andExpect(requestMatcher2).andRespond(responseCreator);
|
||||
template.sendSourceAndReceiveToResult(uri.toString(), new StringSource("<request xmlns='http://example.com'/>"),
|
||||
new StringResult());
|
||||
|
||||
verify(requestMatcher1, requestMatcher2, responseCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void payloadMatch() throws Exception {
|
||||
Source request = new StringSource("<request xmlns='http://example.com'/>");
|
||||
Source response = new StringSource("<response xmlns='http://example.com'/>");
|
||||
|
||||
server.expect(payload(request)).andRespond(withPayload(response));
|
||||
|
||||
StringResult result = new StringResult();
|
||||
template.sendSourceAndReceiveToResult(request, result);
|
||||
assertXMLEqual(result.toString(), response.toString());
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void payloadNonMatch() throws Exception {
|
||||
Source expected = new StringSource("<request xmlns='http://example.com'/>");
|
||||
|
||||
server.expect(payload(expected));
|
||||
|
||||
StringResult result = new StringResult();
|
||||
String actual = "<request xmlns='http://other.com'/>";
|
||||
template.sendSourceAndReceiveToResult(new StringSource(actual), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void soapHeaderMatch() throws Exception {
|
||||
final QName soapHeaderName = new QName("http://example.com", "mySoapHeader");
|
||||
|
||||
server.expect(soapHeader(soapHeaderName));
|
||||
|
||||
template.sendSourceAndReceiveToResult(new StringSource("<request xmlns='http://example.com'/>"),
|
||||
new WebServiceMessageCallback() {
|
||||
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
soapMessage.getSoapHeader().addHeaderElement(soapHeaderName);
|
||||
}
|
||||
}, new StringResult());
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void soapHeaderNonMatch() throws Exception {
|
||||
QName soapHeaderName = new QName("http://example.com", "mySoapHeader");
|
||||
|
||||
server.expect(soapHeader(soapHeaderName));
|
||||
|
||||
template.sendSourceAndReceiveToResult(new StringSource("<request xmlns='http://example.com'/>"),
|
||||
new StringResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionMatch() throws Exception {
|
||||
String uri = "http://example.com";
|
||||
server.expect(connectionTo(uri));
|
||||
|
||||
template.sendSourceAndReceiveToResult(uri, new StringSource("<request xmlns='http://example.com'/>"),
|
||||
new StringResult());
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void connectionNonMatch() throws Exception {
|
||||
String expected = "http://expected.com";
|
||||
server.expect(connectionTo(expected));
|
||||
|
||||
String actual = "http://actual.com";
|
||||
template.sendSourceAndReceiveToResult(actual, new StringSource("<request xmlns='http://example.com'/>"),
|
||||
new StringResult());
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void unexpectedConnection() throws Exception {
|
||||
Source request = new StringSource("<request xmlns='http://example.com'/>");
|
||||
Source response = new StringSource("<response xmlns='http://example.com'/>");
|
||||
|
||||
server.expect(payload(request)).andRespond(withPayload(response));
|
||||
|
||||
template.sendSourceAndReceiveToResult(request, new StringResult());
|
||||
template.sendSourceAndReceiveToResult(request, new StringResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xsdMatch() throws Exception {
|
||||
Resource schema = new ByteArrayResource(
|
||||
"<schema xmlns=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://example.com\" elementFormDefault=\"qualified\"><element name=\"request\"/></schema>".getBytes());
|
||||
|
||||
server.expect(validPayload(schema));
|
||||
|
||||
StringResult result = new StringResult();
|
||||
String actual = "<request xmlns='http://example.com'/>";
|
||||
template.sendSourceAndReceiveToResult(new StringSource(actual), result);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void xsdNonMatch() throws Exception {
|
||||
Resource schema = new ByteArrayResource(
|
||||
"<schema xmlns=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://example.com\" elementFormDefault=\"qualified\"><element name=\"request\"/></schema>".getBytes());
|
||||
|
||||
server.expect(validPayload(schema));
|
||||
|
||||
StringResult result = new StringResult();
|
||||
String actual = "<request2 xmlns='http://example.com'/>";
|
||||
template.sendSourceAndReceiveToResult(new StringSource(actual), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xpathExistsMatch() throws Exception {
|
||||
final Map<String, String> ns = Collections.singletonMap("ns", "http://example.com");
|
||||
|
||||
server.expect(xpath("/ns:request", ns).exists());
|
||||
|
||||
template.sendSourceAndReceiveToResult(new StringSource("<request xmlns='http://example.com'/>"),
|
||||
new StringResult());
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void xpathExistsNonMatch() throws Exception {
|
||||
final Map<String, String> ns = Collections.singletonMap("ns", "http://example.com");
|
||||
|
||||
server.expect(xpath("/ns:foo", ns).exists());
|
||||
|
||||
template.sendSourceAndReceiveToResult(new StringSource("<request xmlns='http://example.com'/>"),
|
||||
new StringResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anythingMatch() throws Exception {
|
||||
Source request = new StringSource("<request xmlns='http://example.com'/>");
|
||||
Source response = new StringSource("<response xmlns='http://example.com'/>");
|
||||
|
||||
server.expect(anything()).andRespond(withPayload(response));
|
||||
|
||||
StringResult result = new StringResult();
|
||||
template.sendSourceAndReceiveToResult(request, result);
|
||||
assertXMLEqual(result.toString(), response.toString());
|
||||
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void recordWhenReplay() throws Exception {
|
||||
Source request = new StringSource("<request xmlns='http://example.com'/>");
|
||||
Source response = new StringSource("<response xmlns='http://example.com'/>");
|
||||
|
||||
server.expect(anything()).andRespond(withPayload(response));
|
||||
server.expect(anything()).andRespond(withPayload(response));
|
||||
|
||||
StringResult result = new StringResult();
|
||||
template.sendSourceAndReceiveToResult(request, result);
|
||||
assertXMLEqual(result.toString(), response.toString());
|
||||
|
||||
server.expect(anything()).andRespond(withPayload(response));
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void verifyFailure() throws Exception {
|
||||
server.expect(anything());
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyOnly() throws Exception {
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test(expected = SoapFaultClientException.class)
|
||||
public void fault() throws Exception {
|
||||
Source request = new StringSource("<request xmlns='http://example.com'/>");
|
||||
|
||||
server.expect(anything()).andRespond(withClientOrSenderFault("reason", Locale.ENGLISH));
|
||||
|
||||
StringResult result = new StringResult();
|
||||
template.sendSourceAndReceiveToResult(request, result);
|
||||
}
|
||||
|
||||
public static class MyClient extends WebServiceGatewaySupport {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright 2005-2012 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.soap11.Soap11Fault;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ResponseCreatorsTest {
|
||||
|
||||
private final TransformerHelper transformerHelper = new TransformerHelper();
|
||||
|
||||
private SaajSoapMessageFactory messageFactory;
|
||||
|
||||
@Before
|
||||
public void createMessageFactory() {
|
||||
messageFactory = new SaajSoapMessageFactory();
|
||||
messageFactory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withPayloadSource() throws Exception {
|
||||
String payload = "<payload xmlns='http://springframework.org'/>";
|
||||
ResponseCreator responseCreator = ResponseCreators.withPayload(new StringSource(payload));
|
||||
|
||||
WebServiceMessage response = responseCreator.createResponse(null, null, messageFactory);
|
||||
|
||||
assertXMLEqual(payload, getPayloadAsString(response));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withPayloadResource() throws Exception {
|
||||
String payload = "<payload xmlns='http://springframework.org'/>";
|
||||
ResponseCreator responseCreator =
|
||||
ResponseCreators.withPayload(new ByteArrayResource(payload.getBytes("UTF-8")));
|
||||
|
||||
WebServiceMessage response = responseCreator.createResponse(null, null, messageFactory);
|
||||
|
||||
assertXMLEqual(payload, getPayloadAsString(response));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withSoapEnvelopeSource() throws Exception {
|
||||
StringBuilder xmlBuilder = new StringBuilder();
|
||||
xmlBuilder.append("<?xml version='1.0'?>");
|
||||
xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
|
||||
xmlBuilder.append("<soap:Header><header xmlns='http://springframework.org'/></soap:Header>");
|
||||
xmlBuilder.append("<soap:Body><payload xmlns='http://springframework.org'/></soap:Body>");
|
||||
xmlBuilder.append("</soap:Envelope>");
|
||||
String envelope = xmlBuilder.toString();
|
||||
ResponseCreator responseCreator = ResponseCreators.withSoapEnvelope(new StringSource(envelope));
|
||||
WebServiceMessage response = responseCreator.createResponse(null, null, messageFactory);
|
||||
assertXMLEqual(envelope, getSoapEnvelopeAsString((SoapMessage)response));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withSoapEnvelopeResource() throws Exception {
|
||||
StringBuilder xmlBuilder = new StringBuilder();
|
||||
xmlBuilder.append("<?xml version='1.0'?>");
|
||||
xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
|
||||
xmlBuilder.append("<soap:Header><header xmlns='http://springframework.org'/></soap:Header>");
|
||||
xmlBuilder.append("<soap:Body><payload xmlns='http://springframework.org'/></soap:Body>");
|
||||
xmlBuilder.append("</soap:Envelope>");
|
||||
String envelope = xmlBuilder.toString();
|
||||
ResponseCreator responseCreator = ResponseCreators.withSoapEnvelope(new ByteArrayResource(envelope.getBytes("UTF-8")));
|
||||
WebServiceMessage response = responseCreator.createResponse(null, null, messageFactory);
|
||||
assertXMLEqual(envelope, getSoapEnvelopeAsString((SoapMessage)response));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withIOException() throws Exception {
|
||||
IOException expected = new IOException("Foo");
|
||||
ResponseCreator responseCreator = ResponseCreators.withException(expected);
|
||||
|
||||
try {
|
||||
responseCreator.createResponse(null, null, null);
|
||||
}
|
||||
catch (IOException actual) {
|
||||
assertSame(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withRuntimeException() throws Exception {
|
||||
RuntimeException expected = new RuntimeException("Foo");
|
||||
ResponseCreator responseCreator = ResponseCreators.withException(expected);
|
||||
|
||||
try {
|
||||
responseCreator.createResponse(null, null, null);
|
||||
}
|
||||
catch (RuntimeException actual) {
|
||||
assertSame(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withMustUnderstandFault() throws Exception {
|
||||
String faultString = "Foo";
|
||||
ResponseCreator responseCreator = ResponseCreators.withMustUnderstandFault(faultString, Locale.ENGLISH);
|
||||
|
||||
testFault(responseCreator, faultString, SoapVersion.SOAP_11.getMustUnderstandFaultName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withClientOrSenderFault() throws Exception {
|
||||
String faultString = "Foo";
|
||||
ResponseCreator responseCreator = ResponseCreators.withClientOrSenderFault(faultString, Locale.ENGLISH);
|
||||
|
||||
testFault(responseCreator, faultString, SoapVersion.SOAP_11.getClientOrSenderFaultName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withServerOrReceiverFault() throws Exception {
|
||||
String faultString = "Foo";
|
||||
ResponseCreator responseCreator = ResponseCreators.withServerOrReceiverFault(faultString, Locale.ENGLISH);
|
||||
|
||||
testFault(responseCreator, faultString, SoapVersion.SOAP_11.getServerOrReceiverFaultName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withVersionMismatchFault() throws Exception {
|
||||
String faultString = "Foo";
|
||||
ResponseCreator responseCreator = ResponseCreators.withVersionMismatchFault(faultString, Locale.ENGLISH);
|
||||
|
||||
testFault(responseCreator, faultString, SoapVersion.SOAP_11.getVersionMismatchFaultName());
|
||||
}
|
||||
|
||||
private void testFault(ResponseCreator responseCreator, String faultString, QName faultCode) throws IOException {
|
||||
SoapMessage response = (SoapMessage) responseCreator.createResponse(null, null, messageFactory);
|
||||
|
||||
assertTrue("Response has no fault", response.hasFault());
|
||||
Soap11Fault soapFault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Response has invalid fault code", faultCode, soapFault.getFaultCode());
|
||||
assertEquals("Response has invalid fault string", faultString, soapFault.getFaultStringOrReason());
|
||||
assertEquals("Response has invalid fault locale", Locale.ENGLISH, soapFault.getFaultStringLocale());
|
||||
}
|
||||
|
||||
private String getPayloadAsString(WebServiceMessage message) throws TransformerException {
|
||||
Result result = new StringResult();
|
||||
transformerHelper.transform(message.getPayloadSource(), result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private String getSoapEnvelopeAsString(SoapMessage message) throws TransformerException {
|
||||
DOMSource source = new DOMSource(message.getDocument());
|
||||
Result result = new StringResult();
|
||||
transformerHelper.transform(source, result);
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.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, 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"), message);
|
||||
}
|
||||
}
|
||||
@@ -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.client;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.client.integration;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.ws.test.client.MockWebServiceServer;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.ws.test.client.RequestMatchers.payload;
|
||||
import static org.springframework.ws.test.client.ResponseCreators.withPayload;
|
||||
|
||||
/**
|
||||
* Integration test for client-side WebService testing. In different package so we can't use the package-protected
|
||||
* classes.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("integration-test.xml")
|
||||
public class ClientIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private CustomerClient client;
|
||||
|
||||
private MockWebServiceServer mockServer;
|
||||
|
||||
@Before
|
||||
public void createServer() throws Exception {
|
||||
mockServer = MockWebServiceServer.createServer(client);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic() throws Exception {
|
||||
Source expectedRequestPayload = new StringSource(
|
||||
"<customerCountRequest xmlns='http://springframework.org/spring-ws'>" +
|
||||
"<customerName>John Doe</customerName>" + "</customerCountRequest>");
|
||||
Source responsePayload = new StringSource(
|
||||
"<customerCountResponse xmlns='http://springframework.org/spring-ws'>" +
|
||||
"<customerCount>10</customerCount>" + "</customerCountResponse>");
|
||||
|
||||
mockServer.expect(payload(expectedRequestPayload)).andRespond(withPayload(responsePayload));
|
||||
|
||||
int result = client.getCustomerCount();
|
||||
assertEquals(10, result);
|
||||
|
||||
mockServer.verify();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.client.integration;
|
||||
|
||||
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
|
||||
import org.springframework.ws.test.integration.CustomerCountRequest;
|
||||
import org.springframework.ws.test.integration.CustomerCountResponse;
|
||||
|
||||
|
||||
public class CustomerClient extends WebServiceGatewaySupport {
|
||||
|
||||
public int getCustomerCount() {
|
||||
CustomerCountRequest request = new CustomerCountRequest();
|
||||
request.setCustomerName("John Doe");
|
||||
|
||||
CustomerCountResponse response = (CustomerCountResponse) getWebServiceTemplate().marshalSendAndReceive(request);
|
||||
return response.getCustomerCount();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.integration;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(namespace = "http://springframework.org/spring-ws")
|
||||
public class CustomerCountRequest {
|
||||
|
||||
private String customerName;
|
||||
|
||||
@XmlElement(namespace = "http://springframework.org/spring-ws")
|
||||
public String getCustomerName() {
|
||||
return customerName;
|
||||
}
|
||||
|
||||
public void setCustomerName(String name) {
|
||||
this.customerName = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.integration;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(namespace = "http://springframework.org/spring-ws")
|
||||
public class CustomerCountResponse {
|
||||
|
||||
private int customerCount;
|
||||
|
||||
@XmlElement(namespace = "http://springframework.org/spring-ws")
|
||||
public int getCustomerCount() {
|
||||
return customerCount;
|
||||
}
|
||||
|
||||
public void setCustomerCount(int customerCount) {
|
||||
this.customerCount = customerCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.server.SoapMessageDispatcher;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class MockWebServiceClientTest {
|
||||
|
||||
@Test
|
||||
public void createServerApplicationContext() throws Exception {
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
applicationContext.registerSingleton("messageDispatcher", SoapMessageDispatcher.class);
|
||||
applicationContext.registerSingleton("messageFactory", SaajSoapMessageFactory.class);
|
||||
applicationContext.refresh();
|
||||
|
||||
MockWebServiceClient client = MockWebServiceClient.createClient(applicationContext);
|
||||
assertNotNull(client);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createServerApplicationContextDefaults() throws Exception {
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
applicationContext.refresh();
|
||||
|
||||
MockWebServiceClient client = MockWebServiceClient.createClient(applicationContext);
|
||||
assertNotNull(client);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.integration;
|
||||
|
||||
import org.springframework.ws.server.endpoint.annotation.Endpoint;
|
||||
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
|
||||
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
|
||||
import org.springframework.ws.test.integration.CustomerCountRequest;
|
||||
import org.springframework.ws.test.integration.CustomerCountResponse;
|
||||
|
||||
@Endpoint
|
||||
public class CustomerEndpoint {
|
||||
|
||||
@ResponsePayload
|
||||
public CustomerCountResponse getCustomerCount(@RequestPayload CustomerCountRequest request) {
|
||||
CustomerCountResponse response = new CustomerCountResponse();
|
||||
response.setCustomerCount(42);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.integration;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
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.ws.test.server.MockWebServiceClient;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Before;
|
||||
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.payload;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("integration-test.xml")
|
||||
public class ServerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private MockWebServiceClient mockClient;
|
||||
|
||||
@Before
|
||||
public void createClient() {
|
||||
mockClient = MockWebServiceClient.createClient(applicationContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic() throws Exception {
|
||||
Source requestPayload = new StringSource("<customerCountRequest xmlns='http://springframework.org/spring-ws'>" +
|
||||
"<customerName>John Doe</customerName>" + "</customerCountRequest>");
|
||||
Source expectedResponsePayload = new StringSource(
|
||||
"<customerCountResponse xmlns='http://springframework.org/spring-ws'>" +
|
||||
"<customerCount>42</customerCount>" + "</customerCountResponse>");
|
||||
|
||||
mockClient.sendRequest(withPayload(requestPayload)).andExpect(payload(expectedResponsePayload));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.support;
|
||||
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class MockStrategiesHelperTest {
|
||||
|
||||
@Test
|
||||
public void none() {
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
|
||||
MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
|
||||
assertNull(helper.getStrategy(IMyBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void one() {
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
applicationContext.registerSingleton("myBean", MyBean.class);
|
||||
|
||||
MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
|
||||
assertNotNull(helper.getStrategy(IMyBean.class));
|
||||
}
|
||||
|
||||
@Test(expected = BeanInitializationException.class)
|
||||
public void many() {
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
applicationContext.registerSingleton("myBean1", MyBean.class);
|
||||
applicationContext.registerSingleton("myBean2", MyBean.class);
|
||||
|
||||
MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
|
||||
helper.getStrategy(IMyBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noneWithDefault() {
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
|
||||
|
||||
MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
|
||||
assertNotNull(helper.getStrategy(IMyBean.class, MyBean.class));
|
||||
}
|
||||
|
||||
|
||||
public interface IMyBean {
|
||||
|
||||
}
|
||||
|
||||
public static class MyBean implements IMyBean {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.matcher;
|
||||
|
||||
import javax.xml.soap.MessageFactory;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class PayloadDiffMatcherTest {
|
||||
|
||||
@Test
|
||||
public void match() throws Exception {
|
||||
String xml = "<element xmlns='http://example.com'/>";
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource(xml)).times(2);
|
||||
replay(message);
|
||||
|
||||
PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource(xml));
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void nonMatch() throws Exception {
|
||||
String actual = "<element1 xmlns='http://example.com'/>";
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource(actual)).times(2);
|
||||
replay(message);
|
||||
|
||||
String expected = "<element2 xmlns='http://example.com'/>";
|
||||
PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource(expected));
|
||||
matcher.match(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void noPayload() throws Exception {
|
||||
PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource("<message/>"));
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SoapMessage soapMessage = new SaajSoapMessage(messageFactory.createMessage());
|
||||
|
||||
matcher.createDiff(soapMessage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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.matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class SchemaValidatingMatcherTest {
|
||||
|
||||
private Resource schema2;
|
||||
|
||||
private Resource schema1;
|
||||
|
||||
private WebServiceMessage message;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
message = createMock(WebServiceMessage.class);
|
||||
schema1 = new ClassPathResource("schemaValidatingMatcherTest.xsd", SchemaValidatingMatcherTest.class);
|
||||
schema2 = new ByteArrayResource("".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleSchemaMatch() throws IOException, AssertionError {
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource(
|
||||
"<test xmlns=\"http://www.example.org/schema\"><number>0</number><text>text</text></test>"));
|
||||
|
||||
SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void singleSchemaNonMatch() throws IOException, AssertionError {
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource(
|
||||
"<test xmlns=\"http://www.example.org/schema\"><number>a</number><text>text</text></test>")).times(2);
|
||||
|
||||
SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleSchemaMatch() throws IOException, AssertionError {
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource(
|
||||
"<test xmlns=\"http://www.example.org/schema\"><number>0</number><text>text</text></test>"));
|
||||
|
||||
SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1, schema2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void multipleSchemaNotOk() throws IOException, AssertionError {
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource(
|
||||
"<test xmlns=\"http://www.example.org/schema\"><number>a</number><text>text</text></test>")).times(2);
|
||||
|
||||
SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1, schema2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void multipleSchemaDifferentOrderNotOk() throws IOException, AssertionError {
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource(
|
||||
"<test xmlns=\"http://www.example.org/schema\"><number>a</number><text>text</text></test>")).times(2);
|
||||
|
||||
SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema2, schema1);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void xmlValidatorNotOk() throws IOException, AssertionError {
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource(
|
||||
"<test xmlns=\"http://www.example.org/schema\"><number>a</number><text>text</text></test>")).times(2);
|
||||
|
||||
SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2005-2012 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.matcher;
|
||||
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerHelper;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class SoapEnvelopeDiffMatcherTest {
|
||||
|
||||
@Test
|
||||
public void match() throws Exception {
|
||||
StringBuilder xmlBuilder = new StringBuilder();
|
||||
xmlBuilder.append("<?xml version='1.0'?>");
|
||||
xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
|
||||
xmlBuilder.append("<soap:Header><header xmlns='http://example.com'/></soap:Header>");
|
||||
xmlBuilder.append("<soap:Body><payload xmlns='http://example.com'/></soap:Body>");
|
||||
xmlBuilder.append("</soap:Envelope>");
|
||||
String xml = xmlBuilder.toString();
|
||||
DOMResult result = new DOMResult();
|
||||
TransformerHelper transformerHelper = new TransformerHelper();
|
||||
transformerHelper.transform(new StringSource(xml), result);
|
||||
SoapMessage message = createMock(SoapMessage.class);
|
||||
expect(message.getDocument()).andReturn((Document)result.getNode()).once();
|
||||
replay(message);
|
||||
|
||||
SoapEnvelopeDiffMatcher matcher = new SoapEnvelopeDiffMatcher(new StringSource(xml));
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void nonMatch() throws Exception {
|
||||
StringBuilder xmlBuilder = new StringBuilder();
|
||||
xmlBuilder.append("<?xml version='1.0'?>");
|
||||
xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
|
||||
xmlBuilder.append("<soap:Header><header xmlns='http://example.com'/></soap:Header>");
|
||||
xmlBuilder.append("<soap:Body><payload%s xmlns='http://example.com'/></soap:Body>");
|
||||
xmlBuilder.append("</soap:Envelope>");
|
||||
String xml = xmlBuilder.toString();
|
||||
String actual = String.format(xml, "1");
|
||||
DOMResult result = new DOMResult();
|
||||
TransformerHelper transformerHelper = new TransformerHelper();
|
||||
transformerHelper.transform(new StringSource(actual), result);
|
||||
SoapMessage message = createMock(SoapMessage.class);
|
||||
expect(message.getDocument()).andReturn((Document)result.getNode()).once();
|
||||
replay(message);
|
||||
|
||||
String expected = String.format(xml, "2");
|
||||
SoapEnvelopeDiffMatcher matcher = new SoapEnvelopeDiffMatcher(new StringSource(expected));
|
||||
matcher.match(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.support.matcher;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
|
||||
public class SoapHeaderMatcherTest {
|
||||
|
||||
private SoapHeaderMatcher matcher;
|
||||
|
||||
private QName expectedHeaderName;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
expectedHeaderName = new QName("http://example.com", "header");
|
||||
matcher = new SoapHeaderMatcher(expectedHeaderName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void match() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SOAPMessage saajMessage = messageFactory.createMessage();
|
||||
saajMessage.getSOAPHeader().addHeaderElement(expectedHeaderName);
|
||||
SoapMessage soapMessage = new SaajSoapMessage(saajMessage);
|
||||
|
||||
matcher.match(soapMessage);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void nonMatch() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SOAPMessage saajMessage = messageFactory.createMessage();
|
||||
SoapMessage soapMessage = new SaajSoapMessage(saajMessage);
|
||||
|
||||
matcher.match(soapMessage);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void nonSoap() throws Exception {
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
|
||||
matcher.match(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* 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.matcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class XPathExpectationsHelperTest {
|
||||
|
||||
@Test
|
||||
public void existsMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//b");
|
||||
WebServiceMessageMatcher matcher = helper.exists();
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b/></a>"));
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void existsNonMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//c");
|
||||
WebServiceMessageMatcher matcher = helper.exists();
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b/></a>")).times(2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotExistMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//c");
|
||||
WebServiceMessageMatcher matcher = helper.doesNotExist();
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b/></a>"));
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void doesNotExistNonMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//a");
|
||||
WebServiceMessageMatcher matcher = helper.doesNotExist();
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b/></a>")).times(2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evaluatesToTrueMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//b=1");
|
||||
WebServiceMessageMatcher matcher = helper.evaluatesTo(true);
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b>1</b></a>")).times(2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void evaluatesToTrueNonMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//b=2");
|
||||
WebServiceMessageMatcher matcher = helper.evaluatesTo(true);
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b>1</b></a>")).times(2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evaluatesToFalseMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//b!=1");
|
||||
WebServiceMessageMatcher matcher = helper.evaluatesTo(false);
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b>1</b></a>")).times(2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void evaluatesToFalseNonMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//b!=2");
|
||||
WebServiceMessageMatcher matcher = helper.evaluatesTo(false);
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b>1</b></a>")).times(2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evaluatesToIntegerMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//b");
|
||||
WebServiceMessageMatcher matcher = helper.evaluatesTo(1);
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b>1</b></a>")).times(2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void evaluatesToIntegerNonMatch() throws IOException, AssertionError {
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//b");
|
||||
WebServiceMessageMatcher matcher = helper.evaluatesTo(2);
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource()).andReturn(new StringSource("<a><b>1</b></a>")).times(2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void existsWithNamespacesMatch() throws IOException, AssertionError {
|
||||
Map<String, String> ns = Collections.singletonMap("x", "http://example.org");
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//x:b", ns);
|
||||
WebServiceMessageMatcher matcher = helper.exists();
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource())
|
||||
.andReturn(new StringSource("<a:a xmlns:a=\"http://example.org\"><a:b/></a:a>"));
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
|
||||
verify(message);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void existsWithNamespacesNonMatch() throws IOException, AssertionError {
|
||||
Map<String, String> ns = Collections.singletonMap("x", "http://example.org");
|
||||
XPathExpectationsHelper helper = new XPathExpectationsHelper("//b", ns);
|
||||
WebServiceMessageMatcher matcher = helper.exists();
|
||||
assertNotNull(matcher);
|
||||
|
||||
WebServiceMessage message = createMock(WebServiceMessage.class);
|
||||
expect(message.getPayloadSource())
|
||||
.andReturn(new StringSource("<a:a xmlns:a=\"http://example.org\"><a:b/></a:a>")).times(2);
|
||||
|
||||
replay(message);
|
||||
|
||||
matcher.match(message);
|
||||
}
|
||||
|
||||
}
|
||||
6
spring-ws-test/src/test/resources/log4j.properties
Normal file
6
spring-ws-test/src/test/resources/log4j.properties
Normal file
@@ -0,0 +1,6 @@
|
||||
log4j.rootCategory=INFO, stdout
|
||||
log4j.logger.org.springframework.ws=DEBUG
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="client" class="org.springframework.ws.test.client.integration.CustomerClient">
|
||||
<property name="webServiceTemplate" ref="webServiceTemplate"/>
|
||||
</bean>
|
||||
|
||||
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
|
||||
<property name="marshaller" ref="marshaller"/>
|
||||
<property name="unmarshaller" ref="marshaller"/>
|
||||
<property name="defaultUri" value="http://example.com"/>
|
||||
</bean>
|
||||
|
||||
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
||||
<property name="classesToBeBound">
|
||||
<list>
|
||||
<value>org.springframework.ws.test.integration.CustomerCountRequest</value>
|
||||
<value>org.springframework.ws.test.integration.CustomerCountResponse</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/schema" xmlns:tns="http://www.example.org/schema" elementFormDefault="qualified">
|
||||
|
||||
<element name="test" type="tns:testMessage"/>
|
||||
|
||||
<complexType name="testMessage">
|
||||
<sequence>
|
||||
<element name="number" type="int"/>
|
||||
<element name="text" type="string" minOccurs="0"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</schema>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean class="org.springframework.ws.server.endpoint.mapping.jaxb.XmlRootElementEndpointMapping"/>
|
||||
|
||||
<bean class="org.springframework.ws.test.server.integration.CustomerEndpoint"/>
|
||||
|
||||
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
||||
<property name="classesToBeBound">
|
||||
<list>
|
||||
<value>org.springframework.ws.test.integration.CustomerCountRequest</value>
|
||||
<value>org.springframework.ws.test.integration.CustomerCountResponse</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/schema" xmlns:tns="http://www.example.org/schema" elementFormDefault="qualified">
|
||||
|
||||
<element name="test" type="tns:testMessage"/>
|
||||
|
||||
<complexType name="testMessage">
|
||||
<sequence>
|
||||
<element name="number" type="int"/>
|
||||
<element name="text" type="string" minOccurs="0"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</schema>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/schema" xmlns:tns="http://www.example.org/schema" elementFormDefault="qualified">
|
||||
|
||||
<element name="test" type="tns:testMessage"/>
|
||||
|
||||
<complexType name="testMessage">
|
||||
<sequence>
|
||||
<element name="number" type="int"/>
|
||||
<element name="text" type="string" minOccurs="0"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</schema>
|
||||
Reference in New Issue
Block a user