Eliminate the need for Encoder#getContentLength

Issue: SPR-16892
This commit is contained in:
Rossen Stoyanchev
2018-06-04 15:46:58 -04:00
parent 124d4c833c
commit 010352163b
9 changed files with 55 additions and 72 deletions

View File

@@ -128,45 +128,59 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
@Test
public void personResponseBody() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/person", JSON, Person.class).getBody());
ResponseEntity<Person> responseEntity = performGet("/person-response/person", JSON, Person.class);
assertEquals(17, responseEntity.getHeaders().getContentLength());
assertEquals(expected, responseEntity.getBody());
}
@Test
public void personResponseBodyWithCompletableFuture() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/completable-future", JSON, Person.class).getBody());
ResponseEntity<Person> responseEntity = performGet("/person-response/completable-future", JSON, Person.class);
assertEquals(17, responseEntity.getHeaders().getContentLength());
assertEquals(expected, responseEntity.getBody());
}
@Test
public void personResponseBodyWithMono() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/mono", JSON, Person.class).getBody());
ResponseEntity<Person> responseEntity = performGet("/person-response/mono", JSON, Person.class);
assertEquals(17, responseEntity.getHeaders().getContentLength());
assertEquals(expected, responseEntity.getBody());
}
@Test
public void personResponseBodyWithMonoDeclaredAsObject() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/mono-declared-as-object", JSON, Person.class).getBody());
ResponseEntity<Person> entity = performGet("/person-response/mono-declared-as-object", JSON, Person.class);
assertEquals(17, entity.getHeaders().getContentLength());
assertEquals(expected, entity.getBody());
}
@Test
public void personResponseBodyWithSingle() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/single", JSON, Person.class).getBody());
ResponseEntity<Person> entity = performGet("/person-response/single", JSON, Person.class);
assertEquals(17, entity.getHeaders().getContentLength());
assertEquals(expected, entity.getBody());
}
@Test
public void personResponseBodyWithMonoResponseEntity() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/mono-response-entity", JSON, Person.class).getBody());
ResponseEntity<Person> entity = performGet("/person-response/mono-response-entity", JSON, Person.class);
assertEquals(17, entity.getHeaders().getContentLength());
assertEquals(expected, entity.getBody());
}
@Test // SPR-16172
public void personResponseBodyWithMonoResponseEntityXml() throws Exception {
String actual = performGet("/person-response/mono-response-entity-xml",
new HttpHeaders(), String.class).getBody();
String url = "/person-response/mono-response-entity-xml";
ResponseEntity<String> entity = performGet(url, new HttpHeaders(), String.class);
String actual = entity.getBody();
assertEquals(91, entity.getHeaders().getContentLength());
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
"<person><name>Robert</name></person>", actual);
}
@@ -174,13 +188,17 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
@Test
public void personResponseBodyWithList() throws Exception {
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
assertEquals(expected, performGet("/person-response/list", JSON, PERSON_LIST).getBody());
ResponseEntity<List<Person>> entity = performGet("/person-response/list", JSON, PERSON_LIST);
assertEquals(36, entity.getHeaders().getContentLength());
assertEquals(expected, entity.getBody());
}
@Test
public void personResponseBodyWithPublisher() throws Exception {
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
assertEquals(expected, performGet("/person-response/publisher", JSON, PERSON_LIST).getBody());
ResponseEntity<List<Person>> entity = performGet("/person-response/publisher", JSON, PERSON_LIST);
assertEquals(-1, entity.getHeaders().getContentLength());
assertEquals(expected, entity.getBody());
}
@Test