Made WebServiceMessageFactory generic
SWS-631 - ResponseCallback -> ResponseCreator
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* 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.
|
||||
@@ -29,14 +29,14 @@ import java.io.InputStream;
|
||||
* @see org.springframework.ws.WebServiceMessage
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface WebServiceMessageFactory {
|
||||
public interface WebServiceMessageFactory<T extends WebServiceMessage> {
|
||||
|
||||
/**
|
||||
* Creates a new, empty <code>WebServiceMessage</code>.
|
||||
*
|
||||
* @return the empty message
|
||||
*/
|
||||
WebServiceMessage createWebServiceMessage();
|
||||
T createWebServiceMessage();
|
||||
|
||||
/**
|
||||
* Reads a {@link WebServiceMessage} from the given input stream.
|
||||
@@ -48,6 +48,6 @@ public interface WebServiceMessageFactory {
|
||||
* @return the created message
|
||||
* @throws java.io.IOException if an I/O exception occurs
|
||||
*/
|
||||
WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException;
|
||||
T createWebServiceMessage(InputStream inputStream) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* 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.
|
||||
@@ -37,7 +37,7 @@ import org.xml.sax.SAXException;
|
||||
* @see org.springframework.ws.pox.dom.DomPoxMessage
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class DomPoxMessageFactory extends TransformerObjectSupport implements WebServiceMessageFactory {
|
||||
public class DomPoxMessageFactory extends TransformerObjectSupport implements WebServiceMessageFactory<DomPoxMessage> {
|
||||
|
||||
/** The default content type for the POX messages. */
|
||||
public static final String DEFAULT_CONTENT_TYPE = "application/xml";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.ws.soap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
@@ -30,7 +27,7 @@ import org.springframework.ws.WebServiceMessageFactory;
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface SoapMessageFactory extends WebServiceMessageFactory {
|
||||
public interface SoapMessageFactory<T extends SoapMessage> extends WebServiceMessageFactory<T> {
|
||||
|
||||
/**
|
||||
* Sets the SOAP Version used by this factory.
|
||||
@@ -41,24 +38,4 @@ public interface SoapMessageFactory extends WebServiceMessageFactory {
|
||||
*/
|
||||
void setSoapVersion(SoapVersion version);
|
||||
|
||||
/**
|
||||
* Creates a new, empty <code>SoapMessage</code>.
|
||||
*
|
||||
* @return the empty message
|
||||
*/
|
||||
SoapMessage createWebServiceMessage();
|
||||
|
||||
/**
|
||||
* Reads a {@link SoapMessage} from the given input stream.
|
||||
* <p/>
|
||||
* If the given stream is an instance of {@link org.springframework.ws.transport.TransportInputStream
|
||||
* TransportInputStream}, the headers will be read from the request.
|
||||
*
|
||||
* @param inputStream the input stream to read the message from
|
||||
* @return the created message
|
||||
* @throws java.io.IOException if an I/O exception occurs
|
||||
*/
|
||||
SoapMessage createWebServiceMessage(InputStream inputStream) throws IOException;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* 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.
|
||||
@@ -79,7 +79,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@SuppressWarnings("Since15")
|
||||
public class AxiomSoapMessageFactory implements SoapMessageFactory, InitializingBean {
|
||||
public class AxiomSoapMessageFactory implements SoapMessageFactory<AxiomSoapMessage>, InitializingBean {
|
||||
|
||||
private static final String CHARSET_PARAMETER = "charset";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* 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.
|
||||
@@ -55,7 +55,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
* @see org.springframework.ws.soap.saaj.SaajSoapMessage
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class SaajSoapMessageFactory implements SoapMessageFactory, InitializingBean {
|
||||
public class SaajSoapMessageFactory implements SoapMessageFactory<SaajSoapMessage>, InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SaajSoapMessageFactory.class);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* 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.
|
||||
@@ -21,13 +21,13 @@ import java.io.InputStream;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
public class MockWebServiceMessageFactory implements WebServiceMessageFactory {
|
||||
public class MockWebServiceMessageFactory implements WebServiceMessageFactory<MockWebServiceMessage> {
|
||||
|
||||
public WebServiceMessage createWebServiceMessage() {
|
||||
public MockWebServiceMessage createWebServiceMessage() {
|
||||
return new MockWebServiceMessage();
|
||||
}
|
||||
|
||||
public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
|
||||
public MockWebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
|
||||
try {
|
||||
return new MockWebServiceMessage(new StreamSource(inputStream));
|
||||
}
|
||||
|
||||
@@ -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.mock.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
|
||||
/**
|
||||
* 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<T extends WebServiceMessage> extends TransformerObjectSupport
|
||||
implements ResponseCreator<T> {
|
||||
|
||||
public final T createResponse(URI uri, T request, WebServiceMessageFactory<T> messageFactory) throws IOException {
|
||||
T 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, T request, T response) throws IOException;
|
||||
|
||||
}
|
||||
@@ -20,24 +20,28 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ResponseCallback} that holds an error message.
|
||||
* Implementation of {@link ResponseCreator} that holds an error message.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
class ErrorResponseCallback implements ResponseCallback {
|
||||
class ErrorResponseCreator implements ResponseCreator<WebServiceMessage> {
|
||||
|
||||
private final String errorMessage;
|
||||
|
||||
ErrorResponseCallback(String errorMessage) {
|
||||
ErrorResponseCreator(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public void doWithResponse(URI uri, WebServiceMessage response, WebServiceMessage request) throws IOException {
|
||||
public WebServiceMessage createResponse(URI uri,
|
||||
WebServiceMessage request,
|
||||
WebServiceMessageFactory<WebServiceMessage> factory) throws IOException {
|
||||
// Do nothing
|
||||
return null;
|
||||
}
|
||||
|
||||
String getErrorMessage() {
|
||||
@@ -20,27 +20,30 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ResponseCallback} that responds by throwing either an {@link IOException} or a {@link
|
||||
* Implementation of {@link ResponseCreator} that responds by throwing either an {@link IOException} or a {@link
|
||||
* RuntimeException}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
class ExceptionResponseCallback implements ResponseCallback {
|
||||
class ExceptionResponseCreator implements ResponseCreator<WebServiceMessage> {
|
||||
|
||||
private final Exception exception;
|
||||
|
||||
ExceptionResponseCallback(IOException exception) {
|
||||
ExceptionResponseCreator(IOException exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
ExceptionResponseCallback(RuntimeException exception) {
|
||||
ExceptionResponseCreator(RuntimeException exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
public WebServiceMessage createResponse(URI uri,
|
||||
WebServiceMessage request,
|
||||
WebServiceMessageFactory<WebServiceMessage> factory) throws IOException {
|
||||
if (exception instanceof IOException) {
|
||||
throw (IOException) exception;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
|
||||
|
||||
private WebServiceMessage request;
|
||||
|
||||
private ResponseCallback responseCallback;
|
||||
private ResponseCreator responseCreator;
|
||||
|
||||
void addRequestMatcher(RequestMatcher requestMatcher) {
|
||||
Assert.notNull(requestMatcher, "'requestMatcher' must not be null");
|
||||
@@ -67,13 +67,14 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
|
||||
return this;
|
||||
}
|
||||
|
||||
public void andRespond(ResponseCallback responseCallback) {
|
||||
Assert.notNull(responseCallback, "'responseCallback' must not be null");
|
||||
this.responseCallback = responseCallback;
|
||||
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) {
|
||||
@@ -86,11 +87,10 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
|
||||
this.request = message;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
|
||||
if (responseCallback != null) {
|
||||
WebServiceMessage response = messageFactory.createWebServiceMessage();
|
||||
responseCallback.doWithResponse(uri, request, response);
|
||||
return response;
|
||||
if (responseCreator != null) {
|
||||
return responseCreator.createResponse(uri, request, messageFactory);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -102,12 +102,12 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
|
||||
}
|
||||
|
||||
public boolean hasError() throws IOException {
|
||||
return responseCallback instanceof ErrorResponseCallback;
|
||||
return responseCreator instanceof ErrorResponseCreator;
|
||||
}
|
||||
|
||||
public String getErrorMessage() throws IOException {
|
||||
if (responseCallback instanceof ErrorResponseCallback) {
|
||||
return ((ErrorResponseCallback) responseCallback).getErrorMessage();
|
||||
if (responseCreator instanceof ErrorResponseCreator) {
|
||||
return ((ErrorResponseCreator) responseCreator).getErrorMessage();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -115,7 +115,7 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
|
||||
}
|
||||
|
||||
public boolean hasFault() throws IOException {
|
||||
return responseCallback instanceof SoapFaultResponseCallback;
|
||||
return responseCreator instanceof SoapFaultResponseCallback;
|
||||
}
|
||||
|
||||
public void setFault(boolean fault) throws IOException {
|
||||
@@ -125,7 +125,7 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
|
||||
public void close() throws IOException {
|
||||
requestMatchers.clear();
|
||||
request = null;
|
||||
responseCallback = null;
|
||||
responseCreator = null;
|
||||
uri = null;
|
||||
if (lastConnection) {
|
||||
MockWebServiceMessageSenderHolder.clear();
|
||||
|
||||
@@ -22,15 +22,14 @@ import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ResponseCallback} that writes a {@link Source} response.
|
||||
* Implementation of {@link ResponseCreator} that writes a {@link Source} response.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
class PayloadResponseCallback extends TransformerObjectSupport implements ResponseCallback {
|
||||
class PayloadResponseCallback extends AbstractResponseCreator<WebServiceMessage> {
|
||||
|
||||
private final Source payload;
|
||||
|
||||
@@ -38,6 +37,7 @@ class PayloadResponseCallback extends TransformerObjectSupport implements Respon
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
try {
|
||||
transform(payload, response.getPayloadResult());
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.ws.WebServiceMessage;
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface RequestMatcher {
|
||||
public interface RequestMatcher<T extends WebServiceMessage> {
|
||||
|
||||
/**
|
||||
* Matches the given request message against the expectations. Implementations typically make use of JUnit-based
|
||||
@@ -39,6 +39,6 @@ public interface RequestMatcher {
|
||||
* @throws IOException in case of I/O errors
|
||||
* @throws AssertionError if expectations are not met
|
||||
*/
|
||||
void match(URI uri, WebServiceMessage request) throws IOException, AssertionError;
|
||||
void match(URI uri, T request) throws IOException, AssertionError;
|
||||
|
||||
}
|
||||
@@ -32,10 +32,10 @@ public interface ResponseActions {
|
||||
ResponseActions andExpect(RequestMatcher requestMatcher);
|
||||
|
||||
/**
|
||||
* Sets the {@link ResponseCallback} for this mock.
|
||||
* Sets the {@link ResponseCreator} for this mock.
|
||||
*
|
||||
* @param responseCallback the response callback
|
||||
* @param responseCreator the response creator
|
||||
*/
|
||||
void andRespond(ResponseCallback responseCallback);
|
||||
void andRespond(ResponseCreator responseCreator);
|
||||
|
||||
}
|
||||
@@ -20,25 +20,25 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Callback interface for code that operates on response {@link org.springframework.ws.WebServiceMessage}s. Defines the
|
||||
* contract for creating responses in test scenarios.
|
||||
* Allows for creating up responses. Implementations of this interface are returned by {@link WebServiceMock}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface ResponseCallback {
|
||||
public interface ResponseCreator<T extends WebServiceMessage> {
|
||||
|
||||
/**
|
||||
* Execute any number of operations on the supplied response, given the request and URI.
|
||||
* Create a response for the given the request and URI.
|
||||
*
|
||||
* @param uri the URI
|
||||
* @param request the request message
|
||||
* @param response the response message
|
||||
* @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
|
||||
*/
|
||||
void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException;
|
||||
T createResponse(URI uri, T request, WebServiceMessageFactory<T> messageFactory) throws IOException;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -20,32 +20,26 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
|
||||
import static org.springframework.ws.mock.client.Assert.fail;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ResponseCallback} that responds with a SOAP fault.
|
||||
* Implementation of {@link ResponseCreator} that responds with a SOAP fault.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract class SoapFaultResponseCallback implements ResponseCallback {
|
||||
abstract class SoapFaultResponseCallback extends AbstractResponseCreator<SoapMessage> {
|
||||
|
||||
public final void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response)
|
||||
throws IOException {
|
||||
if (!(response instanceof SoapMessage)) {
|
||||
fail("Response message is not a SOAP message");
|
||||
return;
|
||||
@Override
|
||||
protected void doWithResponse(URI uri, SoapMessage request, SoapMessage response) throws IOException {
|
||||
SoapBody responseBody = response.getSoapBody();
|
||||
if (responseBody == null) {
|
||||
fail("SOAP message [" + response + "] does not contain SOAP body");
|
||||
}
|
||||
SoapMessage soapResponse = (SoapMessage) response;
|
||||
SoapBody soapResponseBody = soapResponse.getSoapBody();
|
||||
if (soapResponseBody == null) {
|
||||
fail("SOAP message [" + soapResponse + "] does not contain SOAP body");
|
||||
}
|
||||
addSoapFault(soapResponseBody);
|
||||
addSoapFault(responseBody);
|
||||
}
|
||||
|
||||
public abstract void addSoapFault(SoapBody soapBody);
|
||||
|
||||
@@ -175,7 +175,7 @@ public abstract class WebServiceMock {
|
||||
return new UriMatcher(uri);
|
||||
}
|
||||
|
||||
// ResponseCallbacks
|
||||
// ResponseCreators
|
||||
|
||||
/**
|
||||
* Respond with the given {@link Source} XML as payload response.
|
||||
@@ -183,7 +183,7 @@ public abstract class WebServiceMock {
|
||||
* @param payload the response payload
|
||||
* @return the response callback
|
||||
*/
|
||||
public static ResponseCallback withPayload(Source payload) {
|
||||
public static ResponseCreator withPayload(Source payload) {
|
||||
Assert.notNull(payload, "'payload' must not be null");
|
||||
return new PayloadResponseCallback(payload);
|
||||
}
|
||||
@@ -194,7 +194,7 @@ public abstract class WebServiceMock {
|
||||
* @param payload the response payload
|
||||
* @return the response callback
|
||||
*/
|
||||
public static ResponseCallback withPayload(Resource payload) {
|
||||
public static ResponseCreator withPayload(Resource payload) {
|
||||
Assert.notNull(payload, "'payload' must not be null");
|
||||
return new PayloadResponseCallback(createResourceSource(payload));
|
||||
}
|
||||
@@ -207,9 +207,9 @@ public abstract class WebServiceMock {
|
||||
* @see org.springframework.ws.transport.WebServiceConnection#hasError()
|
||||
* @see org.springframework.ws.transport.WebServiceConnection#getErrorMessage()
|
||||
*/
|
||||
public static ResponseCallback withError(String errorMessage) {
|
||||
public static ResponseCreator withError(String errorMessage) {
|
||||
Assert.hasLength(errorMessage, "'errorMessage' must not be empty");
|
||||
return new ErrorResponseCallback(errorMessage);
|
||||
return new ErrorResponseCreator(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,9 +218,9 @@ public abstract class WebServiceMock {
|
||||
* @param ioException the exception to be thrown
|
||||
* @return the response callback
|
||||
*/
|
||||
public static ResponseCallback withException(IOException ioException) {
|
||||
public static ResponseCreator withException(IOException ioException) {
|
||||
Assert.notNull(ioException, "'ioException' must not be null");
|
||||
return new ExceptionResponseCallback(ioException);
|
||||
return new ExceptionResponseCreator(ioException);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,9 +229,9 @@ public abstract class WebServiceMock {
|
||||
* @param ex the runtime exception to be thrown
|
||||
* @return the response callback
|
||||
*/
|
||||
public static ResponseCallback withException(RuntimeException ex) {
|
||||
public static ResponseCreator withException(RuntimeException ex) {
|
||||
Assert.notNull(ex, "'ex' must not be null");
|
||||
return new ExceptionResponseCallback(ex);
|
||||
return new ExceptionResponseCreator(ex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,7 +241,7 @@ public abstract class WebServiceMock {
|
||||
* @param locale the language of faultStringOrReason. Optional for SOAP 1.1
|
||||
* @see org.springframework.ws.soap.SoapBody#addMustUnderstandFault(String, Locale)
|
||||
*/
|
||||
public static ResponseCallback withMustUnderstandFault(String faultStringOrReason, Locale locale) {
|
||||
public static ResponseCreator withMustUnderstandFault(String faultStringOrReason, Locale locale) {
|
||||
Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty");
|
||||
return SoapFaultResponseCallback.createMustUnderstandFault(faultStringOrReason, locale);
|
||||
}
|
||||
@@ -253,7 +253,7 @@ public abstract class WebServiceMock {
|
||||
* @param locale the language of faultStringOrReason. Optional for SOAP 1.1
|
||||
* @see org.springframework.ws.soap.SoapBody#addClientOrSenderFault(String, Locale)
|
||||
*/
|
||||
public static ResponseCallback withClientOrSenderFault(String faultStringOrReason, Locale locale) {
|
||||
public static ResponseCreator withClientOrSenderFault(String faultStringOrReason, Locale locale) {
|
||||
Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty");
|
||||
return SoapFaultResponseCallback.createClientOrSenderFault(faultStringOrReason, locale);
|
||||
}
|
||||
@@ -265,7 +265,7 @@ public abstract class WebServiceMock {
|
||||
* @param locale the language of faultStringOrReason. Optional for SOAP 1.1
|
||||
* @see org.springframework.ws.soap.SoapBody#addServerOrReceiverFault(String, Locale)
|
||||
*/
|
||||
public static ResponseCallback withServerOrReceiverFault(String faultStringOrReason, Locale locale) {
|
||||
public static ResponseCreator withServerOrReceiverFault(String faultStringOrReason, Locale locale) {
|
||||
Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty");
|
||||
return SoapFaultResponseCallback.createServerOrReceiverFault(faultStringOrReason, locale);
|
||||
}
|
||||
@@ -277,7 +277,7 @@ public abstract class WebServiceMock {
|
||||
* @param locale the language of faultStringOrReason. Optional for SOAP 1.1
|
||||
* @see org.springframework.ws.soap.SoapBody#addVersionMismatchFault(String, Locale)
|
||||
*/
|
||||
public static ResponseCallback withVersionMismatchFault(String faultStringOrReason, Locale locale) {
|
||||
public static ResponseCreator withVersionMismatchFault(String faultStringOrReason, Locale locale) {
|
||||
Assert.hasLength(faultStringOrReason, "'faultStringOrReason' must not be empty");
|
||||
return SoapFaultResponseCallback.createVersionMismatchFault(faultStringOrReason, locale);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ public class ErrorResponseCallbackTest {
|
||||
@Test
|
||||
public void callback() throws IOException {
|
||||
String errorMessage = "Error message";
|
||||
ErrorResponseCallback callback = new ErrorResponseCallback(errorMessage);
|
||||
callback.doWithResponse(null, null, null);
|
||||
ErrorResponseCreator callback = new ErrorResponseCreator(errorMessage);
|
||||
callback.createResponse(null, null, null);
|
||||
assertEquals(errorMessage, callback.getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,15 +24,15 @@ public class ExceptionResponseCallbackTest {
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void ioException() throws Exception {
|
||||
ExceptionResponseCallback callback = new ExceptionResponseCallback(new IOException());
|
||||
ExceptionResponseCreator callback = new ExceptionResponseCreator(new IOException());
|
||||
|
||||
callback.doWithResponse(null, null, null);
|
||||
callback.createResponse(null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void runtimeException() throws Exception {
|
||||
ExceptionResponseCallback callback = new ExceptionResponseCallback(new RuntimeException());
|
||||
ExceptionResponseCreator callback = new ExceptionResponseCreator(new RuntimeException());
|
||||
|
||||
callback.doWithResponse(null, null, null);
|
||||
callback.createResponse(null, null, null);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class MockSenderConnectionTest {
|
||||
public void error() throws IOException {
|
||||
String testErrorMessage = "Test Error Message";
|
||||
MockSenderConnection connection = new MockSenderConnection();
|
||||
connection.andRespond(new ErrorResponseCallback(testErrorMessage));
|
||||
connection.andRespond(new ErrorResponseCreator(testErrorMessage));
|
||||
assertTrue(connection.hasError());
|
||||
assertEquals(testErrorMessage, connection.getErrorMessage());
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
@@ -31,6 +32,7 @@ import org.springframework.ws.client.core.WebServiceMessageCallback;
|
||||
import org.springframework.ws.client.core.WebServiceTemplate;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
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;
|
||||
|
||||
@@ -56,25 +58,28 @@ public class WebServiceMockTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void mocks() throws Exception {
|
||||
URI uri = URI.create("http://example.com");
|
||||
|
||||
RequestMatcher requestMatcher1 = EasyMock.createStrictMock("requestMatcher1", RequestMatcher.class);
|
||||
RequestMatcher requestMatcher2 = EasyMock.createStrictMock("requestMatcher2", RequestMatcher.class);
|
||||
ResponseCallback responseCallback = EasyMock.createStrictMock(ResponseCallback.class);
|
||||
ResponseCreator responseCreator = EasyMock.createStrictMock(ResponseCreator.class);
|
||||
|
||||
SaajSoapMessage response = new SaajSoapMessageFactory(MessageFactory.newInstance()).createWebServiceMessage();
|
||||
|
||||
requestMatcher1.match(EasyMock.eq(uri), EasyMock.isA(SaajSoapMessage.class));
|
||||
requestMatcher2.match(EasyMock.eq(uri), EasyMock.isA(SaajSoapMessage.class));
|
||||
responseCallback.doWithResponse(EasyMock.eq(uri), EasyMock.isA(SaajSoapMessage.class),
|
||||
EasyMock.isA(SaajSoapMessage.class));
|
||||
EasyMock.expect(responseCreator.createResponse(EasyMock.eq(uri), EasyMock.isA(SaajSoapMessage.class),
|
||||
EasyMock.isA(SaajSoapMessageFactory.class))).andReturn(response);
|
||||
|
||||
EasyMock.replay(requestMatcher1, requestMatcher2, responseCallback);
|
||||
EasyMock.replay(requestMatcher1, requestMatcher2, responseCreator);
|
||||
|
||||
expect(requestMatcher1).andExpect(requestMatcher2).andRespond(responseCallback);
|
||||
expect(requestMatcher1).andExpect(requestMatcher2).andRespond(responseCreator);
|
||||
template.sendSourceAndReceiveToResult(uri.toString(), new StringSource("<request xmlns='http://example.com'/>"),
|
||||
new StringResult());
|
||||
|
||||
EasyMock.verify(requestMatcher1, requestMatcher2, responseCallback);
|
||||
EasyMock.verify(requestMatcher1, requestMatcher2, responseCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user