Added request as parameter of ReponseCallback
This commit is contained in:
@@ -36,7 +36,7 @@ class ExceptionResponseCallback implements ResponseCallback {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public void doWithResponse(WebServiceMessage message) throws IOException {
|
||||
public void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
if (exception instanceof IOException) {
|
||||
throw (IOException) exception;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, RequestExp
|
||||
|
||||
private URI uri;
|
||||
|
||||
private WebServiceMessage request;
|
||||
|
||||
private ResponseCallback responseCallback;
|
||||
|
||||
private String errorMessage;
|
||||
@@ -169,13 +171,13 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, RequestExp
|
||||
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(response);
|
||||
responseCallback.doWithResponse(request, response);
|
||||
return response;
|
||||
}
|
||||
else {
|
||||
@@ -209,6 +211,7 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, RequestExp
|
||||
|
||||
public void close() throws IOException {
|
||||
requestMatchers.clear();
|
||||
request = null;
|
||||
responseCallback = null;
|
||||
errorMessage = null;
|
||||
uri = null;
|
||||
|
||||
@@ -43,9 +43,9 @@ class PayloadResponseCallback extends TransformerObjectSupport implements Respon
|
||||
this.payload = new ResourceSource(payload);
|
||||
}
|
||||
|
||||
public void doWithResponse(WebServiceMessage message) throws IOException {
|
||||
public void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
try {
|
||||
transform(payload, message.getPayloadResult());
|
||||
transform(payload, response.getPayloadResult());
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
throw new AssertionError("Could not transform response payload to message: " + ex.getMessage());
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.io.IOException;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
/**
|
||||
* Callback interface for code that operates on a {@link WebServiceMessage}. Defines the contract for matching request
|
||||
* messages to expectations.
|
||||
* 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
|
||||
@@ -30,6 +30,13 @@ import org.springframework.ws.WebServiceMessage;
|
||||
*/
|
||||
public interface ResponseCallback {
|
||||
|
||||
void doWithResponse(WebServiceMessage message) throws IOException;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ import static org.junit.Assert.fail;
|
||||
*/
|
||||
abstract class SoapFaultResponseCallback implements ResponseCallback {
|
||||
|
||||
public final void doWithResponse(WebServiceMessage message) throws IOException {
|
||||
Assert.isInstanceOf(SoapMessage.class, message);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
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");
|
||||
|
||||
@@ -26,13 +26,13 @@ public class ExceptionResponseCallbackTest {
|
||||
public void ioException() throws Exception {
|
||||
ExceptionResponseCallback callback = new ExceptionResponseCallback(new IOException());
|
||||
|
||||
callback.doWithResponse(null);
|
||||
callback.doWithResponse(null, null);
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void runtimeException() throws Exception {
|
||||
ExceptionResponseCallback callback = new ExceptionResponseCallback(new RuntimeException());
|
||||
|
||||
callback.doWithResponse(null);
|
||||
callback.doWithResponse(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class MockSenderConnectionTest {
|
||||
connection.setResponseCallback(responseCallback);
|
||||
|
||||
expect(messageFactory.createWebServiceMessage()).andReturn(response);
|
||||
responseCallback.doWithResponse(response);
|
||||
responseCallback.doWithResponse(null, response);
|
||||
|
||||
replay(responseCallback, messageFactory, response);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user