SPR-8883 - RestTemplate.headForHeaders throws "IllegalArgumentException: No InputStream specified" on server resource which status code are 4xx

This commit is contained in:
Arjen Poutsma
2011-12-08 19:17:48 +00:00
parent b94040f329
commit 3beef9a92e
2 changed files with 29 additions and 6 deletions

View File

@@ -19,16 +19,17 @@ package org.springframework.web.client;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse;
import org.junit.Before;
import org.junit.Test;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** @author Arjen Poutsma */
public class DefaultResponseErrorHandlerTests {
@@ -96,4 +97,21 @@ public class DefaultResponseErrorHandlerTests {
verify(response);
}
@Test(expected = HttpClientErrorException.class)
public void handleErrorNullResponse() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
expect(response.getStatusCode()).andReturn(HttpStatus.NOT_FOUND);
expect(response.getStatusText()).andReturn("Not Found");
expect(response.getHeaders()).andReturn(headers);
expect(response.getBody()).andReturn(null);
replay(response);
handler.handleError(response);
verify(response);
}
}