Skip to content

Commit 3cdfd34

Browse files
committed
dao 사용
1 parent e288315 commit 3cdfd34

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

src/test/java/roomescape/DAOTest.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import io.restassured.RestAssured;
6-
import java.sql.Connection;
7-
import java.sql.SQLException;
85
import java.time.LocalDate;
96
import java.time.LocalTime;
10-
import java.util.List;
117
import java.util.Optional;
128
import org.junit.jupiter.api.BeforeEach;
139
import org.junit.jupiter.api.Test;
1410
import org.springframework.beans.factory.annotation.Autowired;
1511
import org.springframework.boot.test.context.SpringBootTest;
16-
import org.springframework.jdbc.core.JdbcTemplate;
1712
import roomescape.dao.ReservationDAO;
1813
import roomescape.domain.Reservation;
1914

@@ -22,8 +17,6 @@ public class DAOTest {
2217

2318
@Autowired
2419
private ReservationDAO reservationDAO;
25-
@Autowired
26-
private JdbcTemplate jdbcTemplate;
2720

2821
@BeforeEach
2922
void setUp() {
@@ -74,32 +67,4 @@ void updateReservation() {
7467
assertThat(result.get().getDate()).isEqualTo(date.plusDays(1));
7568
assertThat(result.get().getTime()).isEqualTo(LocalTime.of(14, 0));
7669
}
77-
78-
@Test
79-
void 오단계() {
80-
try (Connection connection = jdbcTemplate.getDataSource().getConnection()) {
81-
assertThat(connection).isNotNull();
82-
assertThat(connection.getCatalog()).isEqualTo("DATABASE");
83-
assertThat(connection.getMetaData().getTables(null, null, "RESERVATION", null).next()).isTrue();
84-
} catch (SQLException e) {
85-
throw new RuntimeException(e);
86-
}
87-
}
88-
89-
@Test
90-
void 육단계() {
91-
LocalDate tomorrow = LocalDate.now().plusDays(1);
92-
93-
jdbcTemplate.update("INSERT INTO reservation (name, date, time) VALUES (?, ?, ?)", "브라운", tomorrow.toString(), "15:40");
94-
95-
List<Reservation> reservations = RestAssured.given().log().all()
96-
.when().get("/reservations")
97-
.then().log().all()
98-
.statusCode(200).extract()
99-
.jsonPath().getList(".", Reservation.class);
100-
101-
Integer count = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class);
102-
103-
assertThat(reservations.size()).isEqualTo(count);
104-
}
10570
}

src/test/java/roomescape/MissionStepTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
package roomescape;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
34
import static org.hamcrest.Matchers.is;
45
import io.restassured.RestAssured;
56
import io.restassured.http.ContentType;
7+
import java.sql.Connection;
8+
import java.sql.SQLException;
9+
import java.time.LocalDate;
610
import java.util.HashMap;
11+
import java.util.List;
712
import java.util.Map;
813
import org.junit.jupiter.api.Test;
14+
import org.springframework.beans.factory.annotation.Autowired;
915
import org.springframework.boot.test.context.SpringBootTest;
16+
import org.springframework.jdbc.core.JdbcTemplate;
1017
import org.springframework.test.annotation.DirtiesContext;
18+
import roomescape.domain.Reservation;
1119

1220
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
1321
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
1422
public class MissionStepTest {
1523

24+
@Autowired
25+
private JdbcTemplate jdbcTemplate;
26+
1627
@Test
1728
void 일단계() {
1829
RestAssured.given().log().all()
@@ -91,4 +102,32 @@ public class MissionStepTest {
91102
.statusCode(404)
92103
.body("error", is("해당 ID가 없습니다."));
93104
}
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+
}
94133
}

0 commit comments

Comments
 (0)