Rename RestTemplates to TestRestTemplate
Rename the RestTemplates to TestRestTemplate to help indicate that it's primarily intended for testing. Also now extend RestTemplate to allow direct use, rather than via factory methods. Fixes gh-599
This commit is contained in:
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -46,7 +46,7 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -59,7 +59,7 @@ public class SampleActuatorUiApplicationPortTests {
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
}
|
||||
@@ -67,14 +67,14 @@ public class SampleActuatorUiApplicationPortTests {
|
||||
@Test
|
||||
public void testMetrics() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("ok", entity.getBody());
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -53,7 +53,7 @@ public class SampleActuatorUiApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
||||
ResponseEntity<String> entity = RestTemplates.get().exchange(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:8080", HttpMethod.GET, new HttpEntity<Void>(headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@@ -63,7 +63,7 @@ public class SampleActuatorUiApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
@@ -72,7 +72,7 @@ public class SampleActuatorUiApplicationTests {
|
||||
@Test
|
||||
public void testMetrics() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/metrics", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
}
|
||||
@@ -81,9 +81,9 @@ public class SampleActuatorUiApplicationTests {
|
||||
public void testError() throws Exception {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
||||
ResponseEntity<String> entity = RestTemplates.get().exchange(
|
||||
"http://localhost:8080/error", HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:8080/error", HttpMethod.GET, new HttpEntity<Void>(
|
||||
headers), String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody()
|
||||
.contains("<html>"));
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -48,8 +48,8 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testCustomErrorPath() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get("user", "password").getForEntity(
|
||||
"http://localhost:8080/oops", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", "password")
|
||||
.getForEntity("http://localhost:8080/oops", Map.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -59,7 +59,7 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testCustomContextPath() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/admin/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
String body = entity.getBody();
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -60,14 +60,14 @@ public class ManagementAddressActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get()
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/health",
|
||||
String.class);
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -60,7 +60,7 @@ public class ManagementPortSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -72,14 +72,14 @@ public class ManagementPortSampleActuatorApplicationTests {
|
||||
public void testMetrics() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("ok", entity.getBody());
|
||||
@@ -88,7 +88,7 @@ public class ManagementPortSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testErrorPage() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/error", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -53,7 +53,7 @@ public class NoManagementSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -65,7 +65,7 @@ public class NoManagementSampleActuatorApplicationTests {
|
||||
public void testMetricsNotAvailable() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080/metrics", Map.class);
|
||||
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode());
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -60,7 +60,7 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHomeIsSecure() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -73,7 +73,7 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -85,7 +85,7 @@ public class SampleActuatorApplicationTests {
|
||||
public void testMetrics() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080/metrics", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -96,7 +96,7 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testEnv() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080/env", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -106,7 +106,7 @@ public class SampleActuatorApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("ok", entity.getBody());
|
||||
@@ -114,7 +114,7 @@ public class SampleActuatorApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testErrorPage() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080/foo", String.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
String body = entity.getBody();
|
||||
@@ -127,7 +127,7 @@ public class SampleActuatorApplicationTests {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
||||
HttpEntity<?> request = new HttpEntity<Void>(headers);
|
||||
ResponseEntity<String> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||
.exchange("http://localhost:8080/foo", HttpMethod.GET, request,
|
||||
String.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
@@ -139,9 +139,9 @@ public class SampleActuatorApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testTrace() throws Exception {
|
||||
RestTemplates.get().getForEntity("http://localhost:8080/health", String.class);
|
||||
new TestRestTemplate().getForEntity("http://localhost:8080/health", String.class);
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<List> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<List> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080/trace", List.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -156,7 +156,7 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testErrorPageDirectAccess() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/error", Map.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -168,7 +168,7 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testBeans() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<List> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<List> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080/beans", List.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals(1, entity.getBody().size());
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -52,7 +52,7 @@ public class ShutdownSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -63,7 +63,7 @@ public class ShutdownSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testShutdown() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.postForEntity("http://localhost:8080/shutdown", null, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -51,7 +51,7 @@ public class UnsecureManagementSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHomeIsSecure() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -70,7 +70,7 @@ public class UnsecureManagementSampleActuatorApplicationTests {
|
||||
// ignore;
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/metrics", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -50,7 +50,7 @@ public class UnsecureSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -19,7 +19,7 @@ package sample.jetty;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -43,7 +43,7 @@ public class SampleJettyApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -48,14 +48,14 @@ public class SampleServletApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHomeIsSecure() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", String.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get("user", getPassword())
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:8080", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfi
|
||||
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -72,7 +72,7 @@ public class NonAutoConfigurationSampleTomcatApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
|
||||
@@ -19,7 +19,7 @@ package sample.tomcat;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -43,7 +43,7 @@ public class SampleTomcatApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
|
||||
@@ -19,7 +19,7 @@ package sample.traditional;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -44,7 +44,7 @@ public class SampleTraditionalApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHomeJsp() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
String body = entity.getBody();
|
||||
@@ -54,7 +54,7 @@ public class SampleTraditionalApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testStaticPage() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/index.html", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
String body = entity.getBody();
|
||||
|
||||
@@ -19,7 +19,7 @@ package sample.jsp;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -44,7 +44,7 @@ public class SampleWebJspApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testJspWithEl() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.regex.Pattern;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -56,7 +56,7 @@ public class SampleMethodSecurityApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
||||
ResponseEntity<String> entity = RestTemplates.get().exchange(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:8080", HttpMethod.GET, new HttpEntity<Void>(headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@@ -72,7 +72,7 @@ public class SampleMethodSecurityApplicationTests {
|
||||
form.set("username", "admin");
|
||||
form.set("password", "admin");
|
||||
getCsrf(form, headers);
|
||||
ResponseEntity<String> entity = RestTemplates.get().exchange(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:8080/login", HttpMethod.POST,
|
||||
new HttpEntity<MultiValueMap<String, String>>(form, headers),
|
||||
String.class);
|
||||
@@ -89,23 +89,23 @@ public class SampleMethodSecurityApplicationTests {
|
||||
form.set("username", "user");
|
||||
form.set("password", "user");
|
||||
getCsrf(form, headers);
|
||||
ResponseEntity<String> entity = RestTemplates.get().exchange(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:8080/login", HttpMethod.POST,
|
||||
new HttpEntity<MultiValueMap<String, String>>(form, headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
String cookie = entity.getHeaders().getFirst("Set-Cookie");
|
||||
headers.set("Cookie", cookie);
|
||||
ResponseEntity<String> page = RestTemplates.get().exchange(
|
||||
entity.getHeaders().getLocation(), HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
ResponseEntity<String> page = new TestRestTemplate().exchange(entity.getHeaders()
|
||||
.getLocation(), HttpMethod.GET, new HttpEntity<Void>(headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FORBIDDEN, page.getStatusCode());
|
||||
assertTrue("Wrong body (message doesn't match):\n" + entity.getBody(), page
|
||||
.getBody().contains("Access denied"));
|
||||
}
|
||||
|
||||
private void getCsrf(MultiValueMap<String, String> form, HttpHeaders headers) {
|
||||
ResponseEntity<String> page = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> page = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/login", String.class);
|
||||
String cookie = page.getHeaders().getFirst("Set-Cookie");
|
||||
headers.set("Cookie", cookie);
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Arrays;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -52,7 +52,7 @@ public class SampleSecureApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
||||
ResponseEntity<String> entity = RestTemplates.get().exchange(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:8080", HttpMethod.GET, new HttpEntity<Void>(headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@@ -62,7 +62,7 @@ public class SampleSecureApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
|
||||
@@ -19,7 +19,7 @@ package sample.ui;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -45,7 +45,7 @@ public class SampleWebStaticApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity
|
||||
@@ -54,7 +54,7 @@ public class SampleWebStaticApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/webjars/bootstrap/3.0.3/css/bootstrap.min.css",
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.net.URI;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.RestTemplates;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -49,7 +49,7 @@ public class SampleWebUiApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity
|
||||
@@ -63,14 +63,15 @@ public class SampleWebUiApplicationTests {
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||
map.set("text", "FOO text");
|
||||
map.set("summary", "FOO");
|
||||
URI location = RestTemplates.get().postForLocation("http://localhost:8080", map);
|
||||
URI location = new TestRestTemplate().postForLocation("http://localhost:8080",
|
||||
map);
|
||||
assertTrue("Wrong location:\n" + location,
|
||||
location.toString().contains("localhost:8080"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
|
||||
Reference in New Issue
Block a user