I want to test that Bad Request Exception will be thrown if it will not find an exam.
private static String BASE_PATH = "http://localhost:8080/exams/";
@Test
public void testQuizStatusException() {
final String url = BASE_PATH + null + "/status/";
try {
ResponseEntity<String> result = restTemplate.getForEntity(url, String.class);
assertThat(result.getStatusCodeValue(), equalTo(HttpStatus.BAD_REQUEST.value()));
} catch (HttpClientErrorException e) {
e.printStackTrace();
}
}
And I get the following message:
org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found: [<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>
The path is right but I do not understand why I get different Http code
.
I checked - Spring error - springframework.web.client.HttpClientErrorException: 404 Not Found but it seems the problem is different.