|
1 |
| -// package io.hexlet; |
2 |
| -// |
3 |
| -// import org.junit.jupiter.api.BeforeAll; |
4 |
| -// import org.junit.jupiter.api.AfterAll; |
5 |
| -// import org.junit.jupiter.api.Test; |
6 |
| -// |
7 |
| -// import static org.assertj.core.api.Assertions.assertThat; |
8 |
| -// |
9 |
| -// import org.apache.catalina.startup.Tomcat; |
10 |
| -// import org.apache.catalina.LifecycleException; |
11 |
| -// import kong.unirest.HttpResponse; |
12 |
| -// import kong.unirest.Unirest; |
13 |
| -// |
14 |
| -// class AppTest { |
15 |
| -// |
16 |
| -// private static Tomcat app; |
17 |
| -// private static String baseUrl; |
18 |
| -// |
19 |
| -// @BeforeAll |
20 |
| -// public static void beforeAll() throws LifecycleException { |
21 |
| -// app = App.getApp(0); |
22 |
| -// app.start(); |
23 |
| -// int port = app.getConnector().getLocalPort(); |
24 |
| -// String hostname = app.getHost().getName(); |
25 |
| -// String scheme = app.getConnector().getScheme(); |
26 |
| -// baseUrl = scheme + "://" + hostname + ":" + port; |
27 |
| -// } |
28 |
| -// |
29 |
| -// @AfterAll |
30 |
| -// public static void afterAll() throws LifecycleException { |
31 |
| -// app.stop(); |
32 |
| -// } |
33 |
| -// |
34 |
| -// @Test |
35 |
| -// void testHelloWorld() { |
36 |
| -// HttpResponse<String> response = Unirest |
37 |
| -// .get(baseUrl) |
38 |
| -// .asString(); |
39 |
| -// assertThat(response.getStatus()).isEqualTo(200); |
40 |
| -// assertThat(response.getBody()).contains("Hello World"); |
41 |
| -// } |
42 |
| -// |
43 |
| -// @Test |
44 |
| -// void testGreetingWithoutName() { |
45 |
| -// HttpResponse<String> response = Unirest |
46 |
| -// .get(baseUrl + "/greeting") |
47 |
| -// .asString(); |
48 |
| -// assertThat(response.getStatus()).isEqualTo(200); |
49 |
| -// assertThat(response.getBody()).contains("What is your name?"); |
50 |
| -// } |
51 |
| -// |
52 |
| -// @Test |
53 |
| -// void testGreetingWithName() { |
54 |
| -// HttpResponse<String> response = Unirest |
55 |
| -// .get(baseUrl + "/greeting") |
56 |
| -// .queryString("name", "Tirion") |
57 |
| -// .asString(); |
58 |
| -// assertThat(response.getStatus()).isEqualTo(200); |
59 |
| -// assertThat(response.getBody()).contains("Your name is Tirion"); |
60 |
| -// } |
61 |
| -// } |
| 1 | +package io.hexlet; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.BeforeAll; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +import kong.unirest.core.Unirest; |
| 9 | + |
| 10 | +class AppTest { |
| 11 | + static String baseUrl; |
| 12 | + |
| 13 | + @BeforeAll |
| 14 | + static void setup() { |
| 15 | + baseUrl = System.getProperty("gretty.httpBaseURI"); |
| 16 | + } |
| 17 | + |
| 18 | + @Test |
| 19 | + void testMainPage() { |
| 20 | + var response = Unirest.get(baseUrl).asString(); |
| 21 | + assertThat(response.getStatus()).isEqualTo(200); |
| 22 | + assertThat(response.getBody()).contains("users"); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + void testAboutPage() { |
| 27 | + var response = Unirest.get(baseUrl + "/about").asString(); |
| 28 | + assertThat(response.getStatus()).isEqualTo(200); |
| 29 | + assertThat(response.getBody()).contains("Jakarta"); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + void testUsersPage() { |
| 34 | + var response = Unirest.get(baseUrl + "/users").asString(); |
| 35 | + assertThat(response.getStatus()).isEqualTo(200); |
| 36 | + assertThat(response.getBody()).contains("Nina"); |
| 37 | + } |
| 38 | +} |
0 commit comments