From f4cb9e8e4686777002b058b2ee89792182bae078 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 21 Jan 2016 09:57:52 -0500 Subject: [PATCH] Fix HTTP test: provide URL for mock Request The latest SF changes relies on the `request.getRequestURL()`. We end up with the `NPE` if mock `ServletRequest`isn't supplied with `requestURL`. * Add the Mockito answer for the `request.getRequestURL()` in the `MultipartAsRawByteArrayTests` **Cherry-pick to 4.2.x** --- .../http/inbound/MultipartAsRawByteArrayTests.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java index a00b171fd7..dadcb63572 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java @@ -46,8 +46,8 @@ import org.springframework.web.context.request.RequestContextHolder; /** * @author Gary Russell + * @author Artem Bilan * @since 4.2 - * */ public class MultipartAsRawByteArrayTests { @@ -56,7 +56,7 @@ public class MultipartAsRawByteArrayTests { public void testMultiPass() throws Exception { HttpRequestHandlingMessagingGateway gw = new HttpRequestHandlingMessagingGateway(false); gw.setMessageConverters( - Collections.> singletonList(new ByteArrayHttpMessageConverter())); + Collections.>singletonList(new ByteArrayHttpMessageConverter())); gw.setMergeWithDefaultConverters(false); QueueChannel requestChannel = new QueueChannel(); gw.setRequestChannel(requestChannel); @@ -85,12 +85,13 @@ public class MultipartAsRawByteArrayTests { when(request.getMethod()).thenReturn("POST"); when(request.getHeaderNames()).thenReturn(mock(Enumeration.class)); when(request.getContentType()).thenReturn("multipart/form-data"); + when(request.getRequestURL()).thenReturn(new StringBuffer("foo")); RequestContextHolder.setRequestAttributes(mock(RequestAttributes.class)); gw.handleRequest(request, mock(HttpServletResponse.class)); Message received = requestChannel.receive(10000); assertNotNull(received); assertThat(received.getPayload(), instanceOf(byte[].class)); - assertEquals("foo", new String((byte[])received.getPayload())); + assertEquals("foo", new String((byte[]) received.getPayload())); } }