-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexServletTest.java
More file actions
57 lines (41 loc) · 1.48 KB
/
Copy pathIndexServletTest.java
File metadata and controls
57 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package servlet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.net.http.HttpResponse;
import org.apache.catalina.LifecycleException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import testserver.TestServer;
public class IndexServletTest {
@BeforeAll
public static void startServer() throws LifecycleException {
TestServer.start();
}
@AfterAll
public static void stopServer() throws LifecycleException {
TestServer.stop();
}
@Test
public void frontPageReturnsHttp200() {
HttpResponse<String> response = TestServer.get("/");
assertEquals(200, response.statusCode());
}
@Test
public void frontPageContainsCorrectText() {
HttpResponse<String> response = TestServer.get("/");
assertTrue(response.body().contains("Congratulations"));
}
@Test
public void pagesHaveUtf8Encoding() {
HttpResponse<String> response = TestServer.get("/");
String contentType = response.headers().firstValue("Content-Type").get().toLowerCase();
assertTrue(contentType.contains("utf-8"));
assertTrue(contentType.contains("text/html"));
}
@Test
public void nonexistingPathsReturnHttp404() {
HttpResponse<String> response = TestServer.get("/this-is-not-found");
assertEquals(404, response.statusCode());
}
}