SWS-544 - Added URI to ResponseCallback
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.ws.mock.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
@@ -35,11 +36,11 @@ class ErrorResponseCallback implements ResponseCallback {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public void doWithResponse(WebServiceMessage response, WebServiceMessage request) throws IOException {
|
||||
public void doWithResponse(URI uri, WebServiceMessage response, WebServiceMessage request) throws IOException {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.ws.mock.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
@@ -39,7 +40,7 @@ class ExceptionResponseCallback implements ResponseCallback {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
public void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
if (exception instanceof IOException) {
|
||||
throw (IOException) exception;
|
||||
}
|
||||
@@ -47,4 +48,4 @@ class ExceptionResponseCallback implements ResponseCallback {
|
||||
throw (RuntimeException) exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
|
||||
public WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
|
||||
if (responseCallback != null) {
|
||||
WebServiceMessage response = messageFactory.createWebServiceMessage();
|
||||
responseCallback.doWithResponse(request, response);
|
||||
responseCallback.doWithResponse(uri, request, response);
|
||||
return response;
|
||||
}
|
||||
else {
|
||||
@@ -132,4 +132,4 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.ws.mock.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
@@ -37,7 +38,7 @@ class PayloadResponseCallback extends TransformerObjectSupport implements Respon
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
public void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
try {
|
||||
transform(payload, response.getPayloadResult());
|
||||
}
|
||||
@@ -45,4 +46,4 @@ class PayloadResponseCallback extends TransformerObjectSupport implements Respon
|
||||
throw new AssertionError("Could not transform response payload to message: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package org.springframework.ws.mock.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
/**
|
||||
* Callback interface for code that operates on response {@link org.springframework.ws.WebServiceMessage}s. Defines the contract for creating
|
||||
* responses in test scenarios.
|
||||
* Callback interface for code that operates on response {@link org.springframework.ws.WebServiceMessage}s. Defines the
|
||||
* contract for creating responses in test scenarios.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Lukas Krecan
|
||||
@@ -33,10 +34,11 @@ public interface ResponseCallback {
|
||||
/**
|
||||
* Execute any number of operations on the supplied response, given the request.
|
||||
*
|
||||
* @param uri of the service called
|
||||
* @param request the request message
|
||||
* @param response the response message
|
||||
* @throws java.io.IOException in case of I/O errors
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException;
|
||||
void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException;
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.ws.mock.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
@@ -33,7 +34,8 @@ import static org.springframework.ws.mock.client.Assert.fail;
|
||||
*/
|
||||
abstract class SoapFaultResponseCallback implements ResponseCallback {
|
||||
|
||||
public final void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException {
|
||||
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;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ErrorResponseCallbackTest {
|
||||
public void callback() throws IOException {
|
||||
String errorMessage = "Error message";
|
||||
ErrorResponseCallback callback = new ErrorResponseCallback(errorMessage);
|
||||
callback.doWithResponse(null, null);
|
||||
callback.doWithResponse(null, null, null);
|
||||
assertEquals(errorMessage, callback.getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ public class ExceptionResponseCallbackTest {
|
||||
public void ioException() throws Exception {
|
||||
ExceptionResponseCallback callback = new ExceptionResponseCallback(new IOException());
|
||||
|
||||
callback.doWithResponse(null, null);
|
||||
callback.doWithResponse(null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void runtimeException() throws Exception {
|
||||
ExceptionResponseCallback callback = new ExceptionResponseCallback(new RuntimeException());
|
||||
|
||||
callback.doWithResponse(null, null);
|
||||
callback.doWithResponse(null, null, null);
|
||||
}
|
||||
}
|
||||
@@ -47,9 +47,10 @@ public class SoapFaultResponseCallbackTest {
|
||||
@Test
|
||||
public void clientOrSenderFault() throws IOException {
|
||||
String faultString = "Foo";
|
||||
SoapFaultResponseCallback callback = SoapFaultResponseCallback.createClientOrSenderFault(faultString, Locale.ENGLISH);
|
||||
SoapFaultResponseCallback callback =
|
||||
SoapFaultResponseCallback.createClientOrSenderFault(faultString, Locale.ENGLISH);
|
||||
|
||||
callback.doWithResponse(null, response);
|
||||
callback.doWithResponse(null, null, response);
|
||||
|
||||
assertTrue("Response has no fault", response.hasFault());
|
||||
Soap11Fault soapFault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
@@ -62,9 +63,10 @@ public class SoapFaultResponseCallbackTest {
|
||||
@Test
|
||||
public void mustUnderstandFault() throws IOException {
|
||||
String faultString = "Foo";
|
||||
SoapFaultResponseCallback callback = SoapFaultResponseCallback.createMustUnderstandFault(faultString, Locale.ENGLISH);
|
||||
SoapFaultResponseCallback callback =
|
||||
SoapFaultResponseCallback.createMustUnderstandFault(faultString, Locale.ENGLISH);
|
||||
|
||||
callback.doWithResponse(null, response);
|
||||
callback.doWithResponse(null, null, response);
|
||||
|
||||
assertTrue("Response has no fault", response.hasFault());
|
||||
Soap11Fault soapFault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
@@ -77,9 +79,10 @@ public class SoapFaultResponseCallbackTest {
|
||||
@Test
|
||||
public void serverOrReceiverFault() throws IOException {
|
||||
String faultString = "Foo";
|
||||
SoapFaultResponseCallback callback = SoapFaultResponseCallback.createServerOrReceiverFault(faultString, Locale.ENGLISH);
|
||||
SoapFaultResponseCallback callback =
|
||||
SoapFaultResponseCallback.createServerOrReceiverFault(faultString, Locale.ENGLISH);
|
||||
|
||||
callback.doWithResponse(null, response);
|
||||
callback.doWithResponse(null, null, response);
|
||||
|
||||
assertTrue("Response has no fault", response.hasFault());
|
||||
Soap11Fault soapFault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
@@ -92,9 +95,10 @@ public class SoapFaultResponseCallbackTest {
|
||||
@Test
|
||||
public void versionMismatchFault() throws IOException {
|
||||
String faultString = "Foo";
|
||||
SoapFaultResponseCallback callback = SoapFaultResponseCallback.createVersionMismatchFault(faultString, Locale.ENGLISH);
|
||||
SoapFaultResponseCallback callback =
|
||||
SoapFaultResponseCallback.createVersionMismatchFault(faultString, Locale.ENGLISH);
|
||||
|
||||
callback.doWithResponse(null, response);
|
||||
callback.doWithResponse(null, null, response);
|
||||
|
||||
assertTrue("Response has no fault", response.hasFault());
|
||||
Soap11Fault soapFault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
|
||||
@@ -57,20 +57,21 @@ public class WebServiceMockTest {
|
||||
|
||||
@Test
|
||||
public void mocks() throws Exception {
|
||||
String uri = "http://example.com";
|
||||
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);
|
||||
|
||||
requestMatcher1.match(EasyMock.eq(URI.create(uri)), EasyMock.isA(SaajSoapMessage.class));
|
||||
requestMatcher2.match(EasyMock.eq(URI.create(uri)), EasyMock.isA(SaajSoapMessage.class));
|
||||
responseCallback.doWithResponse(EasyMock.isA(SaajSoapMessage.class), EasyMock.isA(SaajSoapMessage.class));
|
||||
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.replay(requestMatcher1, requestMatcher2, responseCallback);
|
||||
|
||||
expect(requestMatcher1).andExpect(requestMatcher2).andRespond(responseCallback);
|
||||
template.sendSourceAndReceiveToResult(uri, new StringSource("<request xmlns='http://example.com'/>"),
|
||||
template.sendSourceAndReceiveToResult(uri.toString(), new StringSource("<request xmlns='http://example.com'/>"),
|
||||
new StringResult());
|
||||
|
||||
EasyMock.verify(requestMatcher1, requestMatcher2, responseCallback);
|
||||
|
||||
Reference in New Issue
Block a user