Merge branch '1.1.x' and fix failure caused by XML response

Spring 4.1 has added support for XML HTTP message conversion using
Jackson. This was resulting in the response being sent back as XML
rather than JSON. Jackson's XML support doesn't cope well with lists
when it's being asked to deserialize to a Map [1] which is what the
test was doing.

This commit updates the test to indicate that it only accepts
application/json, thereby ensuring that the response can be correctly
deserialized into a Map.

Fixes gh-1715

[1] https://github.com/FasterXML/jackson-dataformat-xml/issues/122
This commit is contained in:
Andy Wilkinson 2014-10-15 16:12:12 +01:00
commit 0a3d8a9bfb
1 changed files with 10 additions and 5 deletions

View File

@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.web;
import java.net.URI;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@ -25,13 +26,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.web.BasicErrorControllerIntegrationTests.TestConfiguration;
import org.springframework.boot.autoconfigure.web.BasicErrorControllerMockMvcTests.MinimalWebConfiguration;
import org.springframework.boot.autoconfigure.web.BasicErrorControllerMockMvcTests.TestConfiguration;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -58,7 +61,7 @@ import static org.junit.Assert.assertThat;
@WebAppConfiguration
@DirtiesContext
@IntegrationTest("server.port=0")
public class BasicErrorControllerIntegrationTest {
public class BasicErrorControllerIntegrationTests {
@Value("${local.server.port}")
private int port;
@ -77,8 +80,10 @@ public class BasicErrorControllerIntegrationTest {
@Test
@SuppressWarnings("rawtypes")
public void testBindingExceptionForMachineClient() throws Exception {
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/bind", Map.class);
RequestEntity request = RequestEntity
.get(URI.create("http://localhost:" + this.port + "/bind"))
.accept(MediaType.APPLICATION_JSON).build();
ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class);
String resp = entity.getBody().toString();
assertThat(resp, containsString("Error count: 1"));
assertThat(resp, containsString("errors=[{"));
@ -120,7 +125,7 @@ public class BasicErrorControllerIntegrationTest {
}
@RequestMapping("/bind")
public String bind() throws Exception {
public String bind(HttpServletRequest request) throws Exception {
BindException error = new BindException(this, "test");
error.rejectValue("foo", "bar.error");
throw error;