use of org.springframework.http.HttpHeaders in project spring-boot by spring-projects.
the class SampleWebMustacheApplicationTests method testMustacheErrorTemplate.
@Test
public void testMustacheErrorTemplate() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
ResponseEntity<String> responseEntity = this.restTemplate.exchange("/does-not-exist", HttpMethod.GET, requestEntity, String.class);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found");
}
use of org.springframework.http.HttpHeaders in project spring-boot by spring-projects.
the class SampleWebMustacheApplicationTests method test5xxHtmlResource.
@Test
public void test5xxHtmlResource() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
ResponseEntity<String> entity = this.restTemplate.exchange("/bang", HttpMethod.GET, requestEntity, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(entity.getBody()).contains("I'm a 5xx");
}
use of org.springframework.http.HttpHeaders in project spring-boot by spring-projects.
the class SampleWebSecureJdbcApplicationTests method getHeaders.
private HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class);
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK);
String cookie = page.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie);
Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*");
Matcher matcher = pattern.matcher(page.getBody());
assertThat(matcher.matches()).as(page.getBody()).isTrue();
headers.set("X-CSRF-TOKEN", matcher.group(1));
return headers;
}
use of org.springframework.http.HttpHeaders in project spring-boot by spring-projects.
the class SampleSecureApplicationTests method getHeaders.
private HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class);
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK);
String cookie = page.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie);
Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*");
Matcher matcher = pattern.matcher(page.getBody());
assertThat(matcher.matches()).as(page.getBody()).isTrue();
headers.set("X-CSRF-TOKEN", matcher.group(1));
return headers;
}
use of org.springframework.http.HttpHeaders in project spring-boot by spring-projects.
the class SampleSecureApplicationTests method testLoginPage.
@Test
public void testLoginPage() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("_csrf");
}
Aggregations