Added request as parameter of ReponseCallback

This commit is contained in:
Arjen Poutsma
2010-06-30 08:57:01 +00:00
parent 4bc5bfd452
commit c06312eefd
7 changed files with 24 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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