-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppTest.java
More file actions
67 lines (57 loc) · 2.11 KB
/
AppTest.java
File metadata and controls
67 lines (57 loc) · 2.11 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
58
59
60
61
62
63
64
65
66
67
package hexlet.code;
import hexlet.code.model.Url;
import hexlet.code.repository.UrlRepository;
import io.javalin.Javalin;
import io.javalin.testtools.JavalinTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.sql.SQLException;
import java.time.LocalDateTime;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
class AppTest {
Javalin app;
@BeforeEach
public final void setUp() throws SQLException, IOException {
app = App.getApp();
// Очистка базы данных перед каждым тестом
UrlRepository.clear();
}
@Test
public void testMainPage() {
JavalinTest.test(app, (server, client) -> {
var response = client.get("/");
assertThat(response.code()).isEqualTo(200);
assertThat(response.body().string()).contains("Анализатор страниц");
});
}
//save URL in BD
@Test
public void testUrlSave() throws SQLException {
var url = new Url("https://mail.ru/", LocalDateTime.now());
UrlRepository.save(url);
JavalinTest.test(app, (server, client) -> {
var response = client.get("/urls/" + url.getId());
assertThat(response.code()).isEqualTo(200);
});
}
@Test
public void testCreateUrl() {
JavalinTest.test(app, (server, client) -> {
String requestedBody = "url=https://ya.ru/";
var response = client.post("/urls", requestedBody);
// var response = client.post(NamedRoutes.urlsPath(), requestBody);
var url = UrlRepository.findByName("https://ya.ru");
assertThat(url.get().getName()).isEqualTo("https://ya.ru");
assertThat(response.code()).isEqualTo(200);
assertThat(response.body().string()).contains("https://ya.ru");
});
}
@Test
public void testAllUrls() {
JavalinTest.test(app, (server, client) -> {
var response = client.get("/urls");
assertThat(response.code()).isEqualTo(200);
});
}
}