-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat : 예약 선점 api 구현 및 통합테스트
- Loading branch information
Showing
9 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.prgrms.catchtable.common.base; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
@AutoConfigureMockMvc | ||
public abstract class BaseIntegrationTest { | ||
|
||
@Autowired | ||
public MockMvc mockMvc; | ||
public static ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public static String asJsonString(final Object object) throws Exception { | ||
return objectMapper.writeValueAsString(object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.prgrms.catchtable.reservation.controller; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.prgrms.catchtable.common.base.BaseIntegrationTest; | ||
import com.prgrms.catchtable.common.data.reservation.ReservationData; | ||
import com.prgrms.catchtable.reservation.domain.ReservationTime; | ||
import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; | ||
import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
|
||
class ReservationControllerTest extends BaseIntegrationTest { | ||
|
||
@Autowired | ||
private ReservationTimeRepository reservationTimeRepository; | ||
|
||
@Test | ||
@DisplayName("예약 선점 api 호출에 성공한다.") | ||
void preOccupyReservation() throws Exception { | ||
ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); | ||
ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); | ||
CreateReservationRequest request = ReservationData.getCreateReservationRequest( | ||
savedReservationTime.getId()); | ||
|
||
mockMvc.perform(post("/reservations") | ||
.contentType(APPLICATION_JSON) | ||
.content(asJsonString(request))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.shopName").value(reservationTime.getShop().getName())) | ||
.andExpect(jsonPath("$.date").value(reservationTime.getTime().toString())) | ||
.andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); | ||
} | ||
|
||
@Test | ||
@DisplayName("선점 api 호출 시 선점권이 획득 되었다가 지정 시간 이후에 획득이 풀린다.") | ||
void schedulerTest() throws Exception { | ||
ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); | ||
ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); | ||
CreateReservationRequest request = ReservationData.getCreateReservationRequest( | ||
savedReservationTime.getId()); | ||
|
||
mockMvc.perform(post("/reservations") | ||
.contentType(APPLICATION_JSON) | ||
.content(asJsonString(request))); | ||
|
||
assertThat(reservationTime.isPreOccupied()).isTrue(); | ||
Thread.sleep(3_000); //현재 스케줄러는 2초로 설정되어있어 3초간 대기 후 검증 | ||
assertThat(reservationTime.isPreOccupied()).isFalse(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters