Skip to content

Commit 3b334e4

Browse files
committed
SWS-544 - Added URI to ResponseCallback
1 parent 2e059f6 commit 3b334e4

File tree

10 files changed

+41
-29
lines changed

10 files changed

+41
-29
lines changed

test/src/main/java/org/springframework/ws/mock/client/ErrorResponseCallback.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.ws.mock.client;
1818

1919
import java.io.IOException;
20+
import java.net.URI;
2021

2122
import org.springframework.ws.WebServiceMessage;
2223

@@ -35,11 +36,11 @@ class ErrorResponseCallback implements ResponseCallback {
3536
this.errorMessage = errorMessage;
3637
}
3738

38-
public void doWithResponse(WebServiceMessage response, WebServiceMessage request) throws IOException {
39+
public void doWithResponse(URI uri, WebServiceMessage response, WebServiceMessage request) throws IOException {
3940
// Do nothing
4041
}
4142

4243
String getErrorMessage() {
4344
return errorMessage;
4445
}
45-
}
46+
}

test/src/main/java/org/springframework/ws/mock/client/ExceptionResponseCallback.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.ws.mock.client;
1818

1919
import java.io.IOException;
20+
import java.net.URI;
2021

2122
import org.springframework.ws.WebServiceMessage;
2223

@@ -39,12 +40,12 @@ class ExceptionResponseCallback implements ResponseCallback {
3940
this.exception = exception;
4041
}
4142

42-
public void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException {
43+
public void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
4344
if (exception instanceof IOException) {
4445
throw (IOException) exception;
4546
}
4647
else {
4748
throw (RuntimeException) exception;
4849
}
4950
}
50-
}
51+
}

test/src/main/java/org/springframework/ws/mock/client/MockSenderConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void send(WebServiceMessage message) throws IOException {
8989
public WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
9090
if (responseCallback != null) {
9191
WebServiceMessage response = messageFactory.createWebServiceMessage();
92-
responseCallback.doWithResponse(request, response);
92+
responseCallback.doWithResponse(uri, request, response);
9393
return response;
9494
}
9595
else {
@@ -132,4 +132,4 @@ public void close() throws IOException {
132132
}
133133
}
134134

135-
}
135+
}

test/src/main/java/org/springframework/ws/mock/client/PayloadResponseCallback.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.ws.mock.client;
1818

1919
import java.io.IOException;
20+
import java.net.URI;
2021
import javax.xml.transform.Source;
2122
import javax.xml.transform.TransformerException;
2223

@@ -37,12 +38,12 @@ class PayloadResponseCallback extends TransformerObjectSupport implements Respon
3738
this.payload = payload;
3839
}
3940

40-
public void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException {
41+
public void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
4142
try {
4243
transform(payload, response.getPayloadResult());
4344
}
4445
catch (TransformerException ex) {
4546
throw new AssertionError("Could not transform response payload to message: " + ex.getMessage());
4647
}
4748
}
48-
}
49+
}

test/src/main/java/org/springframework/ws/mock/client/ResponseCallback.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
package org.springframework.ws.mock.client;
1818

1919
import java.io.IOException;
20+
import java.net.URI;
2021

2122
import org.springframework.ws.WebServiceMessage;
2223

2324
/**
24-
* Callback interface for code that operates on response {@link org.springframework.ws.WebServiceMessage}s. Defines the contract for creating
25-
* responses in test scenarios.
25+
* Callback interface for code that operates on response {@link org.springframework.ws.WebServiceMessage}s. Defines the
26+
* contract for creating responses in test scenarios.
2627
*
2728
* @author Arjen Poutsma
2829
* @author Lukas Krecan
@@ -33,10 +34,11 @@ public interface ResponseCallback {
3334
/**
3435
* Execute any number of operations on the supplied response, given the request.
3536
*
37+
* @param uri of the service called
3638
* @param request the request message
3739
* @param response the response message
38-
* @throws java.io.IOException in case of I/O errors
40+
* @throws IOException in case of I/O errors
3941
*/
40-
void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException;
42+
void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException;
4143

4244
}

test/src/main/java/org/springframework/ws/mock/client/SoapFaultResponseCallback.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.ws.mock.client;
1818

1919
import java.io.IOException;
20+
import java.net.URI;
2021
import java.util.Locale;
2122

2223
import org.springframework.ws.WebServiceMessage;
@@ -33,7 +34,8 @@
3334
*/
3435
abstract class SoapFaultResponseCallback implements ResponseCallback {
3536

36-
public final void doWithResponse(WebServiceMessage request, WebServiceMessage response) throws IOException {
37+
public final void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response)
38+
throws IOException {
3739
if (!(response instanceof SoapMessage)) {
3840
fail("Response message is not a SOAP message");
3941
return;

test/src/test/java/org/springframework/ws/mock/client/ErrorResponseCallbackTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ErrorResponseCallbackTest {
2828
public void callback() throws IOException {
2929
String errorMessage = "Error message";
3030
ErrorResponseCallback callback = new ErrorResponseCallback(errorMessage);
31-
callback.doWithResponse(null, null);
31+
callback.doWithResponse(null, null, null);
3232
assertEquals(errorMessage, callback.getErrorMessage());
3333
}
3434
}

test/src/test/java/org/springframework/ws/mock/client/ExceptionResponseCallbackTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public class ExceptionResponseCallbackTest {
2626
public void ioException() throws Exception {
2727
ExceptionResponseCallback callback = new ExceptionResponseCallback(new IOException());
2828

29-
callback.doWithResponse(null, null);
29+
callback.doWithResponse(null, null, null);
3030
}
3131

3232
@Test(expected = RuntimeException.class)
3333
public void runtimeException() throws Exception {
3434
ExceptionResponseCallback callback = new ExceptionResponseCallback(new RuntimeException());
3535

36-
callback.doWithResponse(null, null);
36+
callback.doWithResponse(null, null, null);
3737
}
3838
}

test/src/test/java/org/springframework/ws/mock/client/SoapFaultResponseCallbackTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ public void createResponse() throws SOAPException {
4747
@Test
4848
public void clientOrSenderFault() throws IOException {
4949
String faultString = "Foo";
50-
SoapFaultResponseCallback callback = SoapFaultResponseCallback.createClientOrSenderFault(faultString, Locale.ENGLISH);
50+
SoapFaultResponseCallback callback =
51+
SoapFaultResponseCallback.createClientOrSenderFault(faultString, Locale.ENGLISH);
5152

52-
callback.doWithResponse(null, response);
53+
callback.doWithResponse(null, null, response);
5354

5455
assertTrue("Response has no fault", response.hasFault());
5556
Soap11Fault soapFault = (Soap11Fault) response.getSoapBody().getFault();
@@ -62,9 +63,10 @@ public void clientOrSenderFault() throws IOException {
6263
@Test
6364
public void mustUnderstandFault() throws IOException {
6465
String faultString = "Foo";
65-
SoapFaultResponseCallback callback = SoapFaultResponseCallback.createMustUnderstandFault(faultString, Locale.ENGLISH);
66+
SoapFaultResponseCallback callback =
67+
SoapFaultResponseCallback.createMustUnderstandFault(faultString, Locale.ENGLISH);
6668

67-
callback.doWithResponse(null, response);
69+
callback.doWithResponse(null, null, response);
6870

6971
assertTrue("Response has no fault", response.hasFault());
7072
Soap11Fault soapFault = (Soap11Fault) response.getSoapBody().getFault();
@@ -77,9 +79,10 @@ public void mustUnderstandFault() throws IOException {
7779
@Test
7880
public void serverOrReceiverFault() throws IOException {
7981
String faultString = "Foo";
80-
SoapFaultResponseCallback callback = SoapFaultResponseCallback.createServerOrReceiverFault(faultString, Locale.ENGLISH);
82+
SoapFaultResponseCallback callback =
83+
SoapFaultResponseCallback.createServerOrReceiverFault(faultString, Locale.ENGLISH);
8184

82-
callback.doWithResponse(null, response);
85+
callback.doWithResponse(null, null, response);
8386

8487
assertTrue("Response has no fault", response.hasFault());
8588
Soap11Fault soapFault = (Soap11Fault) response.getSoapBody().getFault();
@@ -92,9 +95,10 @@ public void serverOrReceiverFault() throws IOException {
9295
@Test
9396
public void versionMismatchFault() throws IOException {
9497
String faultString = "Foo";
95-
SoapFaultResponseCallback callback = SoapFaultResponseCallback.createVersionMismatchFault(faultString, Locale.ENGLISH);
98+
SoapFaultResponseCallback callback =
99+
SoapFaultResponseCallback.createVersionMismatchFault(faultString, Locale.ENGLISH);
96100

97-
callback.doWithResponse(null, response);
101+
callback.doWithResponse(null, null, response);
98102

99103
assertTrue("Response has no fault", response.hasFault());
100104
Soap11Fault soapFault = (Soap11Fault) response.getSoapBody().getFault();

test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,21 @@ public void setUp() throws Exception {
5757

5858
@Test
5959
public void mocks() throws Exception {
60-
String uri = "http://example.com";
60+
URI uri = URI.create("http://example.com");
6161

6262
RequestMatcher requestMatcher1 = EasyMock.createStrictMock("requestMatcher1", RequestMatcher.class);
6363
RequestMatcher requestMatcher2 = EasyMock.createStrictMock("requestMatcher2", RequestMatcher.class);
6464
ResponseCallback responseCallback = EasyMock.createStrictMock(ResponseCallback.class);
6565

66-
requestMatcher1.match(EasyMock.eq(URI.create(uri)), EasyMock.isA(SaajSoapMessage.class));
67-
requestMatcher2.match(EasyMock.eq(URI.create(uri)), EasyMock.isA(SaajSoapMessage.class));
68-
responseCallback.doWithResponse(EasyMock.isA(SaajSoapMessage.class), EasyMock.isA(SaajSoapMessage.class));
66+
requestMatcher1.match(EasyMock.eq(uri), EasyMock.isA(SaajSoapMessage.class));
67+
requestMatcher2.match(EasyMock.eq(uri), EasyMock.isA(SaajSoapMessage.class));
68+
responseCallback.doWithResponse(EasyMock.eq(uri), EasyMock.isA(SaajSoapMessage.class),
69+
EasyMock.isA(SaajSoapMessage.class));
6970

7071
EasyMock.replay(requestMatcher1, requestMatcher2, responseCallback);
7172

7273
expect(requestMatcher1).andExpect(requestMatcher2).andRespond(responseCallback);
73-
template.sendSourceAndReceiveToResult(uri, new StringSource("<request xmlns='http://example.com'/>"),
74+
template.sendSourceAndReceiveToResult(uri.toString(), new StringSource("<request xmlns='http://example.com'/>"),
7475
new StringResult());
7576

7677
EasyMock.verify(requestMatcher1, requestMatcher2, responseCallback);

0 commit comments

Comments
 (0)