|
1 | 1 | package roomescape;
|
2 | 2 |
|
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
3 | 4 | import static org.hamcrest.Matchers.is;
|
4 | 5 | import io.restassured.RestAssured;
|
5 | 6 | import io.restassured.http.ContentType;
|
| 7 | +import java.sql.Connection; |
| 8 | +import java.sql.SQLException; |
| 9 | +import java.time.LocalDate; |
6 | 10 | import java.util.HashMap;
|
| 11 | +import java.util.List; |
7 | 12 | import java.util.Map;
|
8 | 13 | import org.junit.jupiter.api.Test;
|
| 14 | +import org.springframework.beans.factory.annotation.Autowired; |
9 | 15 | import org.springframework.boot.test.context.SpringBootTest;
|
| 16 | +import org.springframework.jdbc.core.JdbcTemplate; |
10 | 17 | import org.springframework.test.annotation.DirtiesContext;
|
| 18 | +import roomescape.domain.Reservation; |
11 | 19 |
|
12 | 20 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
13 | 21 | @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
|
14 | 22 | public class MissionStepTest {
|
15 | 23 |
|
| 24 | + @Autowired |
| 25 | + private JdbcTemplate jdbcTemplate; |
| 26 | + |
16 | 27 | @Test
|
17 | 28 | void 일단계() {
|
18 | 29 | RestAssured.given().log().all()
|
@@ -91,4 +102,32 @@ public class MissionStepTest {
|
91 | 102 | .statusCode(404)
|
92 | 103 | .body("error", is("해당 ID가 없습니다."));
|
93 | 104 | }
|
| 105 | + |
| 106 | + @Test |
| 107 | + void 오단계() { |
| 108 | + try (Connection connection = jdbcTemplate.getDataSource().getConnection()) { |
| 109 | + assertThat(connection).isNotNull(); |
| 110 | + assertThat(connection.getCatalog()).isEqualTo("DATABASE"); |
| 111 | + assertThat(connection.getMetaData().getTables(null, null, "RESERVATION", null).next()).isTrue(); |
| 112 | + } catch (SQLException e) { |
| 113 | + throw new RuntimeException(e); |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + void 육단계() { |
| 119 | + LocalDate tomorrow = LocalDate.now().plusDays(1); |
| 120 | + |
| 121 | + jdbcTemplate.update("INSERT INTO reservation (name, date, time) VALUES (?, ?, ?)", "브라운", tomorrow.toString(), "15:40"); |
| 122 | + |
| 123 | + List<Reservation> reservations = RestAssured.given().log().all() |
| 124 | + .when().get("/reservations") |
| 125 | + .then().log().all() |
| 126 | + .statusCode(200).extract() |
| 127 | + .jsonPath().getList(".", Reservation.class); |
| 128 | + |
| 129 | + Integer count = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class); |
| 130 | + |
| 131 | + assertThat(reservations.size()).isEqualTo(count); |
| 132 | + } |
94 | 133 | }
|
0 commit comments