-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunDAOTest.java
47 lines (39 loc) · 1.38 KB
/
RunDAOTest.java
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
import org.jdbi.v3.core.Jdbi;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import static org.assertj.core.api.Assertions.assertThat;
@Testcontainers
public class RunDAOTest {
@Container
private static PostgreSQLContainer container = new PostgreSQLContainer<>("postgres:11.5");
private static Jdbi jdbi;
@BeforeAll
public static void setupDatabase() throws Exception {
jdbi = Database.initDatabase(container.getJdbcUrl(), container.getUsername(), container.getPassword());
}
@AfterEach
public void cleanDatabase() {
jdbi.useHandle(handle -> handle.execute("TRUNCATE run"));
}
@Test
@DisplayName("No runs are selected when no runs exist")
void t1() {
jdbi.useExtension(RunDAO.class, dao ->
assertThat(dao.selectRuns()).isEmpty()
);
}
@Test
@DisplayName("A single run is selected when it is inserted")
void t2() {
jdbi.useExtension(RunDAO.class, dao -> {
var id = dao.createRun();
assertThat(dao.selectRuns())
.containsExactly(new Run(id, "RUNNING"));
});
}
}