Update the samples to make use of auto-configured TestRestTemplate

Closes gh-6730
This commit is contained in:
Andy Wilkinson
2016-08-24 10:12:37 +01:00
parent 3c5cf02882
commit 07a50bb16c
47 changed files with 375 additions and 421 deletions

View File

@@ -21,6 +21,7 @@ import java.net.URI;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -46,11 +47,12 @@ public class SampleGithubApplicationTests {
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;
@Test
public void everythingIsSecuredByDefault() throws Exception {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<Void> entity = restTemplate
.getForEntity("http://localhost:" + this.port, Void.class);
ResponseEntity<Void> entity = this.restTemplate.getForEntity("/", Void.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation())
.isEqualTo(URI.create("http://localhost:" + this.port + "/login"));
@@ -58,9 +60,8 @@ public class SampleGithubApplicationTests {
@Test
public void loginRedirectsToGithub() throws Exception {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<Void> entity = restTemplate
.getForEntity("http://localhost:" + this.port + "/login", Void.class);
ResponseEntity<Void> entity = this.restTemplate.getForEntity("/login",
Void.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation().toString())
.startsWith("https://github.com/login/oauth");