From f4b37ceadbc28e93978f8480044414d3c673d4ef Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Wed, 14 Jul 2010 06:55:53 +0000 Subject: [PATCH] Moving client2 to client --- .../ws/mock/client/DiffMatcher.java | 59 ----- .../client/ExceptionResponseCallback.java | 47 ---- .../ws/mock/client/MockSenderConnection.java | 221 ------------------ .../client/MockWebServiceMessageSender.java | 192 --------------- .../ws/mock/client/PayloadMatcher.java | 67 ------ .../mock/client/PayloadResponseCallback.java | 54 ----- .../ws/mock/client/RequestExpectations.java | 78 ------- .../ws/mock/client/RequestMatcher.java | 42 ---- .../ws/mock/client/ResponseActions.java | 120 ---------- .../ws/mock/client/ResponseCallback.java | 42 ---- .../client/SoapFaultResponseCallback.java | 87 ------- .../ws/mock/client/SoapHeaderMatcher.java | 66 ------ 12 files changed, 1075 deletions(-) delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/ExceptionResponseCallback.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/MockSenderConnection.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/MockWebServiceMessageSender.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/PayloadMatcher.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/PayloadResponseCallback.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/RequestExpectations.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/RequestMatcher.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/ResponseActions.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/ResponseCallback.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/SoapFaultResponseCallback.java delete mode 100644 test/src/main/java/org/springframework/ws/mock/client/SoapHeaderMatcher.java diff --git a/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java b/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java deleted file mode 100644 index 0dc41e3f..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.mock.client; - -import java.io.IOException; - -import org.springframework.ws.WebServiceMessage; -import org.springframework.xml.transform.TransformerObjectSupport; - -import org.custommonkey.xmlunit.Diff; - -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; -import static org.custommonkey.xmlunit.XMLAssert.fail; - -/** - * Implementation of {@link RequestMatcher} based on XMLUnit's {@link Diff}. - * - * @author Arjen Poutsma - * @since 2.0 - */ -abstract class DiffMatcher extends TransformerObjectSupport implements RequestMatcher { - - public final void match(WebServiceMessage request) throws IOException, AssertionError { - try { - Diff diff = createDiff(request); - assertXMLEqual(diff, true); - } - catch (IOException ex) { - throw ex; - } - catch (Exception ex) { - fail("Could not create Diff: " + ex.getMessage()); - } - } - - /** - * Creates a {@link Diff} for the given request message. - * - * @param request the request message - * @return the diff - * @throws Exception in case of errors - */ - protected abstract Diff createDiff(WebServiceMessage request) throws Exception; - -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/ExceptionResponseCallback.java b/test/src/main/java/org/springframework/ws/mock/client/ExceptionResponseCallback.java deleted file mode 100644 index dcc57d18..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/ExceptionResponseCallback.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.mock.client; - -import java.io.IOException; - -import org.springframework.ws.WebServiceMessage; - -/** - * @author Arjen Poutsma - * @since 2.0 - */ -class ExceptionResponseCallback implements ResponseCallback { - - private final Exception exception; - - ExceptionResponseCallback(IOException exception) { - this.exception = exception; - } - - ExceptionResponseCallback(RuntimeException exception) { - this.exception = exception; - } - - public void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException { - if (exception instanceof IOException) { - throw (IOException) exception; - } - else { - throw (RuntimeException) exception; - } - } -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/MockSenderConnection.java b/test/src/main/java/org/springframework/ws/mock/client/MockSenderConnection.java deleted file mode 100644 index b8e6eed2..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/MockSenderConnection.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * 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.mock.client; - -import java.io.IOException; -import java.net.URI; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -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.WebServiceMessageFactory; -import org.springframework.ws.transport.FaultAwareWebServiceConnection; -import org.springframework.ws.transport.WebServiceConnection; -import org.springframework.xml.transform.ResourceSource; -import org.springframework.xml.transform.StringSource; - -import static org.junit.Assert.fail; - -/** - * Mock implementation of {@link WebServiceConnection}. Implements {@link RequestExpectations} and {@link - * ResponseActions} to form a fluent API. - * - * @author Arjen Poutsma - * @author Lukas Krecan - * @since 2.0 - */ -class MockSenderConnection implements FaultAwareWebServiceConnection, RequestExpectations, ResponseActions { - - private static final URI ANY_URI = URI.create("ANY"); - - private final List requestMatchers = new LinkedList(); - - private URI uri; - - private WebServiceMessage request; - - private ResponseCallback responseCallback; - - private String errorMessage; - - /** Creates a new {@code MockSenderConnection} for use with any URI. */ - MockSenderConnection() { - this.uri = ANY_URI; - } - - /** Creates a new {@code MockSenderConnection} for use with the specified URI. */ - MockSenderConnection(URI uri) { - this.uri = uri; - } - - // RequestExpectations implementation - - public ResponseActions expectPayload(String payload) { - Assert.notNull(payload, "'payload' must not be null"); - return addRequestMatcher(new PayloadMatcher(new StringSource(payload))); - } - - public ResponseActions expectPayload(Source payload) { - Assert.notNull(payload, "'payload' must not be null"); - return addRequestMatcher(new PayloadMatcher(payload)); - } - - public ResponseActions expectPayload(Resource payload) { - Assert.notNull(payload, "'payload' must not be null"); - try { - return addRequestMatcher(new PayloadMatcher(new ResourceSource(payload))); - } - catch (IOException ex) { - throw new IllegalArgumentException(payload + " could not be opened", ex); - } - } - - public ResponseActions expectSoapHeader(QName soapHeaderName) { - Assert.notNull(soapHeaderName, "'soapHeaderName' must not be null"); - return addRequestMatcher(new SoapHeaderMatcher(soapHeaderName)); - } - - public ResponseActions addRequestMatcher(RequestMatcher requestMatcher) { - requestMatchers.add(requestMatcher); - return this; - } - - // ResponseActions implementation - - public RequestExpectations and() { - return this; - } - - public void andRespondWithPayload(Resource resource) { - Assert.notNull(resource, "'resource' must not be null"); - try { - this.responseCallback = new PayloadResponseCallback(resource); - } - catch (IOException ex) { - fail("Could not open [" + resource + "]: " + ex.getMessage()); - } - } - - public void andRespondWithPayload(String payload) { - Assert.notNull(payload, "'payload' must not be null"); - this.responseCallback = new PayloadResponseCallback(payload); - } - - public void andRespondWithError(String errorMessage) { - Assert.hasLength(errorMessage, "'errorMessage' must not be empty"); - this.errorMessage = errorMessage; - } - - public void andThrowException(IOException ioException) { - Assert.notNull(ioException, "'ex' must not be null"); - this.responseCallback = new ExceptionResponseCallback(ioException); - } - - public void andThrowException(RuntimeException ex) { - Assert.notNull(ex, "'ex' must not be null"); - this.responseCallback = new ExceptionResponseCallback(ex); - } - - public void andRespondWithMustUnderstandFault(String faultStringOrReason, Locale locale) { - Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty"); - this.responseCallback = SoapFaultResponseCallback.createMustUnderstandFault(faultStringOrReason, locale); - } - - public void andRespondWithClientOrSenderFault(String faultStringOrReason, Locale locale) { - Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty"); - this.responseCallback = SoapFaultResponseCallback.createClientOrSenderFault(faultStringOrReason, locale); - } - - public void andRespondWithServerOrReceiverFault(String faultStringOrReason, Locale locale) { - Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty"); - this.responseCallback = SoapFaultResponseCallback.createServerOrReceiverFault(faultStringOrReason, locale); - } - - public void andRespondWithVersionMismatchFault(String faultStringOrReason, Locale locale) { - Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty"); - this.responseCallback = SoapFaultResponseCallback.createVersionMismatchFault(faultStringOrReason, locale); - } - - public void setResponseCallback(ResponseCallback responseCallback) { - Assert.notNull(responseCallback, "'responseCallback' must not be null"); - this.responseCallback = responseCallback; - } - - // WebServiceConnection implementation - - public void send(WebServiceMessage message) throws IOException { - if (!requestMatchers.isEmpty()) { - for (RequestMatcher requestMatcher : requestMatchers) { - requestMatcher.match(message); - } - } - else { - throw new AssertionError("Unexpected send() for [" + message + "]"); - } - this.request = message; - } - - public WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException { - if (responseCallback != null) { - WebServiceMessage response = messageFactory.createWebServiceMessage(); - responseCallback.doWithResponse(request, response); - return response; - } - else { - return null; - } - } - - public URI getUri() { - return uri; - } - - public boolean hasAnyUri() { - return ANY_URI.equals(uri); - } - - public boolean hasError() throws IOException { - return errorMessage != null; - } - - public String getErrorMessage() throws IOException { - return errorMessage; - } - - public boolean hasFault() throws IOException { - return responseCallback instanceof SoapFaultResponseCallback; - } - - public void setFault(boolean fault) throws IOException { - // Do nothing - } - - public void close() throws IOException { - requestMatchers.clear(); - request = null; - responseCallback = null; - errorMessage = null; - uri = null; - } - - -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/MockWebServiceMessageSender.java b/test/src/main/java/org/springframework/ws/mock/client/MockWebServiceMessageSender.java deleted file mode 100644 index f0738c4b..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/MockWebServiceMessageSender.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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.mock.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; - -/** - * Main entry point for client-side Web Service testing. Typically used in combination with a {@link - * org.springframework.ws.client.core.WebServiceTemplate WebServiceTemplate}. - *

- * The typical usage of this mock is similar to any other mocking library (such as EasyMock), that is: - *

    - *
  1. Inject this mock into the {@link org.springframework.ws.client.core.WebServiceTemplate WebServiceTemplate}. - * See {@link org.springframework.ws.client.core.WebServiceTemplate#setMessageSender(WebServiceMessageSender) WebServiceTemplate.setMessageSender()}.
  2. - *
  3. Set up expectations about the URI to connect to, and about the outgoing request message. - * See {@link #whenConnecting()}, {@link #whenConnectingTo(String)}, and {@link RequestExpectations}.
  4. - *
  5. Indicate the desired response actions. See {@link ResponseActions}.
  6. - *
  7. Call {@link #replay()}. - *
  8. Use the {@code WebServiceTemplate} as normal. - *
  9. Call {@link #verify()}. - *
- * Note that because of the 'fluent' API used by this class, you can typically use the Code Completion features - * offered by your IDE to set up the mocks. - *

- * For example: - *

- * // set up
- * MockWebServiceMessageSender mockMessageSender = new MockWebServiceMessageSender();
- * AirlineClient client = new AirlineClient(); // AirlineClient extends WebServiceGatewaySupport
- * client.getWebServiceTemplate().setMessageSender(mockMessageSender);
- * // expectations
- * String uri = "http://example.com/airline";
- * String expectedRequest = "<getFlightsRequest xmlns=\"http://example.com/\" >";
- * String response = "<getFlightsResponse xmlns=\"http://example.com/\">";
- * mockMessageSender.whenConnectingTo(uri).expectPayload(request).andRespondWithPayload(response);
- * mockMessageSender.replay();
- * // execution
- * StringResult result = new StringResult();
- * template.sendSourceAndReceiveToResult(uri, new StringSource(expectedRequest), stringResult);
- * assertXMLEqual(response, result.toString()); // from XMLUnit
- * mockMessageSender.verify();
- * 
- * - * @author Arjen Poutsma - * @author Lukas Krecan - * @see org.springframework.ws.client.core.WebServiceTemplate#setMessageSender - * @see #whenConnecting() - * @see #whenConnectingTo - * @see RequestExpectations - * @see ResponseActions - * @see #replay() - * @see #verify() - * @since 2.0 - */ -public class MockWebServiceMessageSender implements WebServiceMessageSender { - - private final List expectedConnections = new LinkedList(); - - private Iterator connectionIterator; - - /** Creates a new {@code MockWebServiceMessageSender}. */ - public MockWebServiceMessageSender() { - reset(); - } - - /** - * {@inheritDoc} - *

- * This implementation checks whether the given URI has been recorded as expected, and throws an {@code AssertionError} if not. - * - * @throws IllegalStateException if this mock is not in {@linkplain #replay() replay} state - * @throws AssertionError if the given URI is not expected - */ - public MockSenderConnection createConnection(URI uri) throws IOException { - Assert.notNull(uri, "'uri' must not be null"); - if (connectionIterator == null) { - throw new IllegalStateException("Please call replay() after recording expected connections"); - } - if (!connectionIterator.hasNext()) { - throw new AssertionError("No further connections expected"); - } - MockSenderConnection currentConnection = connectionIterator.next(); - if (!currentConnection.getUri().equals(uri) && !currentConnection.hasAnyUri()) { - throw new AssertionError("Unexpected connection to \"" + uri + "\""); - } - return currentConnection; - } - - /** Always returns {@code true}. */ - public boolean supports(URI uri) { - return true; - } - - /** - * Sets up an expected connection to the specific URI. Returns a {@link RequestExpectations} object that allows for - * further expectations on the request. - * - * @param uri the URI expected to connect to - * @return the request expectations - */ - public RequestExpectations whenConnectingTo(String uri) { - Assert.hasLength(uri, "'uri' must not be empty"); - return whenConnectingTo(URI.create(uri)); - } - - /** - * Sets up an expected connection to the specific URI. Returns a {@link RequestExpectations} object that allows for - * further expectations on the request. - * - * @param uri the URI expected to connect to - * @return the request expectations - */ - public RequestExpectations whenConnectingTo(URI uri) { - Assert.notNull(uri, "'uri' must not be null"); - MockSenderConnection connection = new MockSenderConnection(uri); - expectedConnections.add(connection); - return connection; - } - - /** - * Sets up an expected connection to any URI. Returns a {@link RequestExpectations} object that allows for - * further expectations on the request. - * - * @return the request expectations - */ - public RequestExpectations whenConnecting() { - MockSenderConnection connection = new MockSenderConnection(); - expectedConnections.add(connection); - return connection; - } - - /** Resets the mock to the state directly after creation. */ - public void reset() { - connectionIterator = null; - expectedConnections.clear(); - } - - /** - * Switches the mock from record state to replay state. - * - * @throws IllegalStateException if this mock already is in replay state. - */ - public void replay() { - Assert.state(connectionIterator == null, "Already in replay state"); - connectionIterator = expectedConnections.iterator(); - } - - /** - * Verifies that all expectations have been met. - * - * @throws IllegalStateException if this mock is in record state - * @throws AssertionError if any expectation have not been met - */ - public void verify() { - Assert.state(connectionIterator != null, "Calling verify() is only allowed after replay()"); - if (connectionIterator.hasNext()) { - StringBuilder builder = new StringBuilder("Expected connection(s) to ["); - while (connectionIterator.hasNext()) { - MockSenderConnection connection = connectionIterator.next(); - builder.append(connection.getUri()); - if (connectionIterator.hasNext()) { - builder.append(", "); - } - } - builder.append(']'); - throw new AssertionError(builder.toString()); - } - } - - -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/PayloadMatcher.java b/test/src/main/java/org/springframework/ws/mock/client/PayloadMatcher.java deleted file mode 100644 index 86bc7865..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/PayloadMatcher.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.mock.client; - -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.custommonkey.xmlunit.Diff; -import org.w3c.dom.Document; - -import static junit.framework.Assert.fail; - -/** - * Abstract base class that matches payloads. - * - * @author Arjen Poutsma - * @author Lukas Krecan - * @since 2.0 - */ -class PayloadMatcher extends DiffMatcher { - - private final Source expected; - - PayloadMatcher(Source expected) { - Assert.notNull(expected, "'expected' must not be null"); - this.expected = expected; - } - - @Override - protected final Diff createDiff(WebServiceMessage request) throws Exception { - Source payload = request.getPayloadSource(); - if (payload == null) { - fail("Request message does not contain payload"); - } - return createDiff(payload); - } - - protected Diff createDiff(Source payload) throws TransformerException { - Document expectedDocument = createDocumentFromSource(expected); - Document actualDocument = createDocumentFromSource(payload); - return new Diff(expectedDocument, actualDocument); - } - - private Document createDocumentFromSource(Source source) throws TransformerException { - DOMResult result = new DOMResult(); - transform(source, result); - return (Document) result.getNode(); - } -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/PayloadResponseCallback.java b/test/src/main/java/org/springframework/ws/mock/client/PayloadResponseCallback.java deleted file mode 100644 index 86fa6338..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/PayloadResponseCallback.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.mock.client; - -import java.io.IOException; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; - -import org.springframework.core.io.Resource; -import org.springframework.ws.WebServiceMessage; -import org.springframework.xml.transform.ResourceSource; -import org.springframework.xml.transform.StringSource; -import org.springframework.xml.transform.TransformerObjectSupport; - -/** @author Arjen Poutsma */ -class PayloadResponseCallback extends TransformerObjectSupport implements ResponseCallback { - - private final Source payload; - - PayloadResponseCallback(Source payload) { - this.payload = payload; - } - - PayloadResponseCallback(String payload) { - this.payload = new StringSource(payload); - } - - PayloadResponseCallback(Resource payload) throws IOException { - this.payload = new ResourceSource(payload); - } - - public void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException { - try { - transform(payload, response.getPayloadResult()); - } - catch (TransformerException ex) { - throw new AssertionError("Could not transform response payload to message: " + ex.getMessage()); - } - } -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/RequestExpectations.java b/test/src/main/java/org/springframework/ws/mock/client/RequestExpectations.java deleted file mode 100644 index 775e0f25..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/RequestExpectations.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.mock.client; - -import javax.xml.namespace.QName; -import javax.xml.transform.Source; - -import org.springframework.core.io.Resource; - -/** - * Allows for setting expectations on the request. Implementations of this interface are returned by {@link - * MockWebServiceMessageSender#whenConnectingTo(java.net.URI)}, and by {@link MockWebServiceMessageSender#whenConnecting()}. - * - * @author Arjen Poutsma - * @author Lukas Krecan - * @since 2.0 - */ -public interface RequestExpectations { - - /** - * Records that the mock will expect the given String XML payload. Returns a {@link ResponseActions} object that - * allows for setting up the response. - * - * @param payload the String XML payload - * @return the response actions - */ - ResponseActions expectPayload(String payload); - - /** - * Records that the mock will expect the given {@link Source} payload. Returns a {@link ResponseActions} object that - * allows for setting up the response. - * - * @param payload the payload - * @return the response actions - */ - ResponseActions expectPayload(Source payload); - - /** - * Records that the mock will expect the given {@link Resource} payload. Returns a {@link ResponseActions} object - * that allows for setting up the response. - * - * @param payload the String XML payload - * @return the response actions - */ - ResponseActions expectPayload(Resource payload); - - /** - * Records that the mock will expect the given SOAP header to exist on the outgoing message. Returns a {@link - * ResponseActions} object that allows for setting up the response. - * - * @param soapHeaderName the qualified name of the SOAP header to expect - * @return the response actions - */ - ResponseActions expectSoapHeader(QName soapHeaderName); - - /** - * Adds the {@link RequestMatcher} to the list of expectations. Returns a {@link ResponseActions} object that allows - * for setting up the response. - * - * @param requestMatcher the request matcher - * @return the response actions - */ - ResponseActions addRequestMatcher(RequestMatcher requestMatcher); -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/RequestMatcher.java b/test/src/main/java/org/springframework/ws/mock/client/RequestMatcher.java deleted file mode 100644 index b5fffef2..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/RequestMatcher.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.mock.client; - -import java.io.IOException; - -import org.springframework.ws.WebServiceMessage; - -/** - * Defines the contract for matching request messages 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 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(WebServiceMessage request) throws IOException, AssertionError; - -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/ResponseActions.java b/test/src/main/java/org/springframework/ws/mock/client/ResponseActions.java deleted file mode 100644 index e65c385e..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/ResponseActions.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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.mock.client; - -import java.io.IOException; -import java.util.Locale; - -import org.springframework.core.io.Resource; - -/** - * Allows for setting up responses. Implementations of this interface are returned by {@link RequestExpectations}. - * - * @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 - */ - RequestExpectations and(); - - /** - * Records that the mock will receive the given String XML as payload response. - * - * @param payload the response payload - */ - void andRespondWithPayload(String payload); - - /** - * Records that the mock will receive the given {@link Resource} as payload response. - * - * @param resource the response payload - */ - void andRespondWithPayload(Resource resource); - - /** - * Records that the mock will respond with the given error message. - * - * @param errorMessage the error message - * @see org.springframework.ws.transport.WebServiceConnection#hasError() - * @see org.springframework.ws.transport.WebServiceConnection#getErrorMessage() - */ - void andRespondWithError(String errorMessage); - - /** - * Records that the mock will respond by throwing the given {@link IOException}. - * - * @param ex the I/O exception - */ - void andThrowException(IOException ex); - - /** - * Records that the mock will respond by throwing the given runtime exception. - * - * @param ex the runtime exception - */ - void andThrowException(RuntimeException ex); - - /** - * Records that the mock will 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 org.springframework.ws.soap.SoapBody#addMustUnderstandFault(String, java.util.Locale) - */ - void andRespondWithMustUnderstandFault(String faultStringOrReason, Locale locale); - - /** - * Records that the mock will 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, java.util.Locale) - */ - void andRespondWithClientOrSenderFault(String faultStringOrReason, Locale locale); - - /** - * Records that the mock will 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, java.util.Locale) - */ - void andRespondWithServerOrReceiverFault(String faultStringOrReason, Locale locale); - - /** - * Records that the mock will 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, java.util.Locale) - */ - void andRespondWithVersionMismatchFault(String faultStringOrReason, Locale locale); - - /** - * Sets the {@link ResponseCallback} for this mock. - * - * @param responseCallback the response callback - */ - void setResponseCallback(ResponseCallback responseCallback); - -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/ResponseCallback.java b/test/src/main/java/org/springframework/ws/mock/client/ResponseCallback.java deleted file mode 100644 index 81110d0f..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/ResponseCallback.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.mock.client; - -import java.io.IOException; - -import org.springframework.ws.WebServiceMessage; - -/** - * Callback interface for code that operates on response {@link WebServiceMessage}s. Defines the contract for creating - * responses in test scenarios. - * - * @author Arjen Poutsma - * @author Lukas Krecan - * @since 2.0 - */ -public interface ResponseCallback { - - /** - * Execute any number of operations on the supplied response, given the request. - * - * @param request the request message - * @param response the response message - * @throws IOException in case of I/O errors - */ - void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException; - -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/SoapFaultResponseCallback.java b/test/src/main/java/org/springframework/ws/mock/client/SoapFaultResponseCallback.java deleted file mode 100644 index 3ff3d9d0..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/SoapFaultResponseCallback.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.mock.client; - -import java.io.IOException; -import java.util.Locale; - -import org.springframework.util.Assert; -import org.springframework.ws.WebServiceMessage; -import org.springframework.ws.soap.SoapBody; -import org.springframework.ws.soap.SoapMessage; - -import static org.junit.Assert.fail; - -/** - * @author Arjen Poutsma - * @since 2.0 - */ -abstract class SoapFaultResponseCallback implements ResponseCallback { - - public final void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException { - Assert.isInstanceOf(SoapMessage.class, response); - SoapMessage soapMessage = (SoapMessage) response; - SoapBody soapBody = soapMessage.getSoapBody(); - if (soapBody == null) { - fail("SOAP message [" + soapMessage + "] does not contain SOAP body"); - } - addSoapFault(soapBody); - } - - public abstract void addSoapFault(SoapBody soapBody); - - public static SoapFaultResponseCallback createMustUnderstandFault(final String faultStringOrReason, final Locale locale) { - return new SoapFaultResponseCallback() { - @Override - public void addSoapFault(SoapBody soapBody) { - soapBody.addMustUnderstandFault(faultStringOrReason, locale); - } - }; - - } - - public static SoapFaultResponseCallback createClientOrSenderFault(final String faultStringOrReason, final Locale locale) { - return new SoapFaultResponseCallback() { - @Override - public void addSoapFault(SoapBody soapBody) { - soapBody.addClientOrSenderFault(faultStringOrReason, locale); - } - }; - } - - public static SoapFaultResponseCallback createServerOrReceiverFault(final String faultStringOrReason, final Locale locale) { - return new SoapFaultResponseCallback() { - @Override - public void addSoapFault(SoapBody soapBody) { - soapBody.addServerOrReceiverFault(faultStringOrReason, locale); - } - }; - - } - - public static SoapFaultResponseCallback createVersionMismatchFault(final String faultStringOrReason, final Locale locale) { - return new SoapFaultResponseCallback() { - @Override - public void addSoapFault(SoapBody soapBody) { - soapBody.addVersionMismatchFault(faultStringOrReason, locale); - } - }; - - } - - -} diff --git a/test/src/main/java/org/springframework/ws/mock/client/SoapHeaderMatcher.java b/test/src/main/java/org/springframework/ws/mock/client/SoapHeaderMatcher.java deleted file mode 100644 index 2f11cb62..00000000 --- a/test/src/main/java/org/springframework/ws/mock/client/SoapHeaderMatcher.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.mock.client; - -import java.io.IOException; -import java.util.Iterator; -import javax.xml.namespace.QName; - -import org.springframework.ws.WebServiceMessage; -import org.springframework.ws.soap.SoapHeader; -import org.springframework.ws.soap.SoapHeaderElement; -import org.springframework.ws.soap.SoapMessage; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * Matches SOAP headers. - * - * @author Arjen Poutsma - * @since 2.0 - */ -class SoapHeaderMatcher implements RequestMatcher { - - private final QName soapHeaderName; - - SoapHeaderMatcher(QName soapHeaderName) { - this.soapHeaderName = soapHeaderName; - } - - public void match(WebServiceMessage request) throws IOException, AssertionError { - if (!(request instanceof SoapMessage)) { - fail("Request message is not a SOAP message"); - return; - } - SoapMessage soapMessage = (SoapMessage) request; - SoapHeader soapHeader = soapMessage.getSoapHeader(); - if (soapHeader == null) { - fail("SOAP message [" + soapMessage + "] does not contain SOAP header"); - } - Iterator 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); - } -}