|
56 | 56 | import static org.mockito.Mockito.isNull; |
57 | 57 | import static org.mockito.Mockito.mock; |
58 | 58 | import static org.mockito.Mockito.reset; |
| 59 | +import static org.mockito.Mockito.verify; |
59 | 60 | import static org.mockito.Mockito.when; |
60 | 61 |
|
61 | 62 | @SuppressWarnings("unchecked") |
@@ -271,25 +272,43 @@ void testSendAndReceiveResultNoResponsePayload() throws Exception { |
271 | 272 |
|
272 | 273 | @Test |
273 | 274 | void testSendAndReceiveMarshalResponse() throws Exception { |
| 275 | + Object unmarshalled = new Object(); |
| 276 | + setupMarshallerAndUnmarshaller(unmarshalled); |
| 277 | + Object result = this.template.marshalSendAndReceive(new Object()); |
| 278 | + assertThat(result).isEqualTo(unmarshalled); |
| 279 | + } |
274 | 280 |
|
| 281 | + @Test |
| 282 | + void testSendAndReceiveInvokesCallback() throws Exception { |
| 283 | + WebServiceMessageCallback callback = mock(WebServiceMessageCallback.class); |
| 284 | + setupMarshallerAndUnmarshaller(new Object()); |
| 285 | + this.template.marshalSendAndReceive(new Object(), callback); |
| 286 | + verify(callback).doWithMessage(isA(MockWebServiceMessage.class)); |
| 287 | + } |
| 288 | + |
| 289 | + @Test |
| 290 | + void testSendAndReceiveWithNoBodyInvokesCallback() throws Exception { |
| 291 | + WebServiceMessageCallback callback = mock(WebServiceMessageCallback.class); |
| 292 | + setupMarshallerAndUnmarshaller(new Object()); |
| 293 | + Object requestPayload = null; |
| 294 | + this.template.marshalSendAndReceive(requestPayload, callback); |
| 295 | + verify(callback).doWithMessage(isA(MockWebServiceMessage.class)); |
| 296 | + } |
| 297 | + |
| 298 | + private void setupMarshallerAndUnmarshaller(Object unmarshalled) throws Exception { |
275 | 299 | Marshaller marshallerMock = mock(Marshaller.class); |
276 | 300 | this.template.setMarshaller(marshallerMock); |
277 | 301 | marshallerMock.marshal(isA(Object.class), isA(Result.class)); |
278 | 302 |
|
279 | 303 | Unmarshaller unmarshallerMock = mock(Unmarshaller.class); |
280 | 304 | this.template.setUnmarshaller(unmarshallerMock); |
281 | | - Object unmarshalled = new Object(); |
282 | 305 | when(unmarshallerMock.unmarshal(isA(Source.class))).thenReturn(unmarshalled); |
283 | 306 |
|
284 | 307 | this.connectionMock.send(isA(WebServiceMessage.class)); |
285 | 308 | when(this.connectionMock.hasError()).thenReturn(false); |
286 | 309 | when(this.connectionMock.receive(this.messageFactory)).thenReturn(new MockWebServiceMessage("<response/>")); |
287 | 310 | when(this.connectionMock.hasFault()).thenReturn(false); |
288 | 311 | this.connectionMock.close(); |
289 | | - |
290 | | - Object result = this.template.marshalSendAndReceive(new Object()); |
291 | | - |
292 | | - assertThat(result).isEqualTo(unmarshalled); |
293 | 312 | } |
294 | 313 |
|
295 | 314 | @Test |
|
0 commit comments