GH-228 Added support for treating text/* CT as a special case

Resolves #228
This commit is contained in:
Oleg Zhurakousky
2018-11-16 12:46:58 +01:00
parent e9b289d995
commit c46f25a000
5 changed files with 69 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,8 @@ package com.example;
import java.net.URI;
import java.util.Arrays;
import org.junit.Ignore;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -26,6 +27,8 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.test.context.junit4.SpringRunner;
@@ -35,15 +38,24 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Dave Syer
* @author Oleg Zhurakousky
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SampleApplicationTests {
private HttpHeaders headers;
@LocalServerPort
private int port;
private TestRestTemplate rest = new TestRestTemplate();
@Before
public void before() {
headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
}
@Test
public void words() {
assertThat(rest.getForObject("http://localhost:" + port + "/words", String.class))
@@ -53,7 +65,7 @@ public class SampleApplicationTests {
@Test
public void uppercase() {
assertThat(rest.postForObject("http://localhost:" + port + "/uppercase",
"[{\"value\":\"foo\"}]", String.class))
new HttpEntity<>("[{\"value\":\"foo\"}]", headers), String.class))
.isEqualTo("[{\"value\":\"FOO\"}]");
}
@@ -66,13 +78,13 @@ public class SampleApplicationTests {
@Test
public void single() {
assertThat(rest.postForObject("http://localhost:" + port + "/uppercase",
"{\"value\":\"foo\"}", String.class)).isEqualTo("{\"value\":\"FOO\"}");
new HttpEntity<>("{\"value\":\"foo\"}", headers), String.class)).isEqualTo("{\"value\":\"FOO\"}");
}
@Test
public void lowercase() {
assertThat(rest.postForObject("http://localhost:" + port + "/lowercase",
"[{\"value\":\"Foo\"}]", String.class))
new HttpEntity<>("[{\"value\":\"Foo\"}]", headers), String.class))
.isEqualTo("[{\"value\":\"foo\"}]");
}