Commit 0a3d8a9b authored by Andy Wilkinson's avatar Andy Wilkinson

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
parents cd3729b4 fff94733
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.web; package org.springframework.boot.autoconfigure.web;
import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -25,13 +26,15 @@ import org.junit.Test; ...@@ -25,13 +26,15 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication; 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.MinimalWebConfiguration;
import org.springframework.boot.autoconfigure.web.BasicErrorControllerMockMvcTests.TestConfiguration;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
...@@ -58,7 +61,7 @@ import static org.junit.Assert.assertThat; ...@@ -58,7 +61,7 @@ import static org.junit.Assert.assertThat;
@WebAppConfiguration @WebAppConfiguration
@DirtiesContext @DirtiesContext
@IntegrationTest("server.port=0") @IntegrationTest("server.port=0")
public class BasicErrorControllerIntegrationTest { public class BasicErrorControllerIntegrationTests {
@Value("${local.server.port}") @Value("${local.server.port}")
private int port; private int port;
...@@ -77,8 +80,10 @@ public class BasicErrorControllerIntegrationTest { ...@@ -77,8 +80,10 @@ public class BasicErrorControllerIntegrationTest {
@Test @Test
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public void testBindingExceptionForMachineClient() throws Exception { public void testBindingExceptionForMachineClient() throws Exception {
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( RequestEntity request = RequestEntity
"http://localhost:" + this.port + "/bind", Map.class); .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(); String resp = entity.getBody().toString();
assertThat(resp, containsString("Error count: 1")); assertThat(resp, containsString("Error count: 1"));
assertThat(resp, containsString("errors=[{")); assertThat(resp, containsString("errors=[{"));
...@@ -120,7 +125,7 @@ public class BasicErrorControllerIntegrationTest { ...@@ -120,7 +125,7 @@ public class BasicErrorControllerIntegrationTest {
} }
@RequestMapping("/bind") @RequestMapping("/bind")
public String bind() throws Exception { public String bind(HttpServletRequest request) throws Exception {
BindException error = new BindException(this, "test"); BindException error = new BindException(this, "test");
error.rejectValue("foo", "bar.error"); error.rejectValue("foo", "bar.error");
throw error; throw error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment