diff --git a/src/test/java/roomescape/CoreStepTest.java b/src/test/java/roomescape/CoreStepTest.java index 87bf9261..886f2c91 100644 --- a/src/test/java/roomescape/CoreStepTest.java +++ b/src/test/java/roomescape/CoreStepTest.java @@ -33,13 +33,13 @@ public class CoreStepTest { .when().post("/times") .then().log().all() .statusCode(201) - .header("Location", "/times/3"); + .header("Location", "/times/6"); RestAssured.given().log().all() .when().get("/times") .then().log().all() .statusCode(200) - .body("size()", is(3)); + .body("size()", is(6)); RestAssured.given().log().all() .when().delete("/times/3") @@ -51,7 +51,7 @@ public class CoreStepTest { void 구단계() { Map reservation = new HashMap<>(); reservation.put("name", "브라운"); - reservation.put("date", "2023-08-05"); + reservation.put("date", "2025-10-27"); reservation.put("time", "10:00"); RestAssured.given().log().all() diff --git a/src/test/java/roomescape/JDBCStepTest.java b/src/test/java/roomescape/JDBCStepTest.java deleted file mode 100644 index 1d3df787..00000000 --- a/src/test/java/roomescape/JDBCStepTest.java +++ /dev/null @@ -1,123 +0,0 @@ -package roomescape; - -import io.restassured.RestAssured; -import io.restassured.http.ContentType; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpStatus; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.annotation.DirtiesContext; -import roomescape.api.dto.ReservationResponseDto; -import roomescape.util.LoggerUtils; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) -@SuppressWarnings("NonAsciiCharacters") -public class JDBCStepTest { - - private static final Logger log = LoggerUtils.logger(JDBCStepTest.class); - @Autowired - private JdbcTemplate jdbcTemplate; - - @Test - void 오단계() { - try (Connection connection = jdbcTemplate.getDataSource().getConnection()) { - assertThat(connection).isNotNull(); - assertThat(connection.getCatalog()).isEqualTo("DATABASE"); - assertThat(connection.getMetaData().getTables(null, null, "RESERVATION", null).next()).isTrue(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - @Test - void 육단계() { - jdbcTemplate.update("INSERT INTO reservation (name, date, time) VALUES (?, ?, ?)", "브라운", "2023-08-05", "15:40"); - - List reservations = RestAssured.given().log().all() - .when().get("/reservations") - .then().log().all() - .statusCode(200).extract() - .jsonPath().getList(".", ReservationResponseDto.class); - - Integer count = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class); - - assertThat(reservations.size()).isEqualTo(count); - } - - @Test - void 칠단계() { - Map params = new HashMap<>(); - params.put("name", "브라운"); - params.put("date", "2023-08-05"); - params.put("time", "10:00"); - - RestAssured.given().log().all() - .contentType(ContentType.JSON) - .body(params) - .when().post("/reservations") - .then().log().all() - .statusCode(201) - .header("Location", "/reservations/1"); - - Integer count = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class); - assertThat(count).isEqualTo(1); - - RestAssured.given().log().all() - .when().delete("/reservations/1") - .then().log().all() - .statusCode(204); - - Integer countAfterDelete = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class); - assertThat(countAfterDelete).isEqualTo(0); - } - - @Test - void 칠단계_삭제_예외처리() { - Map params = new HashMap<>(); - params.put("name", "브라운"); - params.put("date", "2023-08-05"); - params.put("time", "10:00"); - - RestAssured.given().log().all() - .contentType(ContentType.JSON) - .body(params) - .when().post("/reservations") - .then().log().all() - .statusCode(201) - .header("Location", "/reservations/1"); - - Integer count = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class); - assertThat(count).isEqualTo(1); - - var response = RestAssured.given().log().all() - .when().delete("/reservations/3") - .then().log().all().extract().response(); - - assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); - } - - @Test - void 특정_예약_테스트() { - var response = RestAssured.given().log().all() - .contentType(ContentType.JSON) - .when().get("/reservations/1") - .then().log().all() - .statusCode(200) - .extract().response(); - - log.warn("Reservation {}", response); - String responseBody = response.getBody().asString(); - assertThat(responseBody).isEmpty(); - } -} diff --git a/src/test/java/roomescape/MissionStepTest.java b/src/test/java/roomescape/MissionStepTest.java deleted file mode 100644 index eac94f83..00000000 --- a/src/test/java/roomescape/MissionStepTest.java +++ /dev/null @@ -1,130 +0,0 @@ -package roomescape; - -import io.restassured.RestAssured; -import io.restassured.http.ContentType; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; - -import java.util.HashMap; -import java.util.Map; - -import static org.hamcrest.core.Is.is; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) -@SuppressWarnings("NonAsciiCharacters") -public class MissionStepTest { - - @Test - void 일단계() { - RestAssured.given().log().all() - .when().get("/") - .then().log().all() - .statusCode(200); - } - - @Nested - class 이단계 { - @Test - void 예약_페이지_요청() { - RestAssured.given().log().all() - .when().get("/reservation") - .then().log().all() - .statusCode(200); - } - - @Test - void 전체_예약_가져오기_요청() { - RestAssured.given().log().all() - .when().get("/reservations") - .then().log().all() - .statusCode(200) - .body("size()", is(0)); - } - } - - @Nested - class 삼단계 { - Map requestBody = new HashMap<>(); -// "hwang", -// "2024-11-06", -// "10:11" - - - @Test - void 예약_추가_요청() { - requestBody.put("name", "hwang"); - requestBody.put("date", "2024-11-06"); - requestBody.put("time_id", "1"); - requestBody.put("time", "10:11"); - - - RestAssured.given().log().all() - .contentType(ContentType.JSON) - .body(requestBody) - .when().post("/reservations") - .then().log().all() - .statusCode(201) - .header("Location", "/reservations/1") - .body("id", is(1)); - - RestAssured.given().log().all() - .when().get("/reservations") - .then().log().all() - .statusCode(200) - .body("size()", is(1)); - } - - @Test - void 예약_삭제_요청() { - RestAssured.given().log().all() - .contentType(ContentType.JSON) - .body(requestBody) - .when().post("/reservations") - .then().log().all() - .statusCode(201) - .header("Location", "/reservations/1") - .body("id", is(1)); - - RestAssured.given().log().all() - .when().delete("/reservations/1") - .then().log().all() - .statusCode(204); - - RestAssured.given().log().all() - .when().get("/reservations") - .then().log().all() - .statusCode(200) - .body("size()", is(0)); - } - } - - @Nested - class 사단계 { - - @Test - void 예약_요청_인자_테스트() { - Map requestBody = new HashMap<>(); - requestBody.put("name", "hwang"); - requestBody.put("date", ""); - requestBody.put("time", ""); - - RestAssured.given().log().all() - .contentType(ContentType.JSON) - .body(requestBody) - .when().post("/reservations") - .then().log().all() - .statusCode(400); - } - - @Test - void 없는_예약_삭제_테스트() { - RestAssured.given().log().all() - .when().delete("/reservations/10") - .then().log().all() - .statusCode(400); - } - } -}