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**
This commit is contained in:
Artem Bilan
2016-01-21 09:57:52 -05:00
parent 2024b8a4b3
commit f4cb9e8e46

View File

@@ -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.<HttpMessageConverter<?>> singletonList(new ByteArrayHttpMessageConverter()));
Collections.<HttpMessageConverter<?>>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()));
}
}