|
47 | 47 | import static org.mockito.Mockito.isNull;
|
48 | 48 | import static org.mockito.Mockito.mock;
|
49 | 49 | import static org.mockito.Mockito.reset;
|
| 50 | +import static org.mockito.Mockito.verify; |
50 | 51 | import static org.mockito.Mockito.when;
|
51 | 52 |
|
52 | 53 | @SuppressWarnings("unchecked")
|
@@ -262,25 +263,43 @@ void testSendAndReceiveResultNoResponsePayload() throws Exception {
|
262 | 263 |
|
263 | 264 | @Test
|
264 | 265 | void testSendAndReceiveMarshalResponse() throws Exception {
|
| 266 | + Object unmarshalled = new Object(); |
| 267 | + setupMarshallerAndUnmarshaller(unmarshalled); |
| 268 | + Object result = this.template.marshalSendAndReceive(new Object()); |
| 269 | + assertThat(result).isEqualTo(unmarshalled); |
| 270 | + } |
265 | 271 |
|
| 272 | + @Test |
| 273 | + void testSendAndReceiveInvokesCallback() throws Exception { |
| 274 | + WebServiceMessageCallback callback = mock(WebServiceMessageCallback.class); |
| 275 | + setupMarshallerAndUnmarshaller(new Object()); |
| 276 | + this.template.marshalSendAndReceive(new Object(), callback); |
| 277 | + verify(callback).doWithMessage(isA(MockWebServiceMessage.class)); |
| 278 | + } |
| 279 | + |
| 280 | + @Test |
| 281 | + void testSendAndReceiveWithNoBodyInvokesCallback() throws Exception { |
| 282 | + WebServiceMessageCallback callback = mock(WebServiceMessageCallback.class); |
| 283 | + setupMarshallerAndUnmarshaller(new Object()); |
| 284 | + Object requestPayload = null; |
| 285 | + this.template.marshalSendAndReceive(requestPayload, callback); |
| 286 | + verify(callback).doWithMessage(isA(MockWebServiceMessage.class)); |
| 287 | + } |
| 288 | + |
| 289 | + private void setupMarshallerAndUnmarshaller(Object unmarshalled) throws Exception { |
266 | 290 | Marshaller marshallerMock = mock(Marshaller.class);
|
267 | 291 | this.template.setMarshaller(marshallerMock);
|
268 | 292 | marshallerMock.marshal(isA(Object.class), isA(Result.class));
|
269 | 293 |
|
270 | 294 | Unmarshaller unmarshallerMock = mock(Unmarshaller.class);
|
271 | 295 | this.template.setUnmarshaller(unmarshallerMock);
|
272 |
| - Object unmarshalled = new Object(); |
273 | 296 | when(unmarshallerMock.unmarshal(isA(Source.class))).thenReturn(unmarshalled);
|
274 | 297 |
|
275 | 298 | this.connectionMock.send(isA(WebServiceMessage.class));
|
276 | 299 | when(this.connectionMock.hasError()).thenReturn(false);
|
277 | 300 | when(this.connectionMock.receive(this.messageFactory)).thenReturn(new MockWebServiceMessage("<response/>"));
|
278 | 301 | when(this.connectionMock.hasFault()).thenReturn(false);
|
279 | 302 | this.connectionMock.close();
|
280 |
| - |
281 |
| - Object result = this.template.marshalSendAndReceive(new Object()); |
282 |
| - |
283 |
| - assertThat(result).isEqualTo(unmarshalled); |
284 | 303 | }
|
285 | 304 |
|
286 | 305 | @Test
|
|
0 commit comments