44import com .fasterxml .jackson .databind .ObjectMapper ;
55import konkuk .thip .book .adapter .out .jpa .BookJpaEntity ;
66import konkuk .thip .book .adapter .out .persistence .repository .BookJpaRepository ;
7+ import konkuk .thip .book .application .port .out .BookApiQueryPort ;
8+ import konkuk .thip .book .domain .Book ;
79import konkuk .thip .common .util .TestEntityFactory ;
810import konkuk .thip .room .adapter .out .jpa .RoomJpaEntity ;
911import konkuk .thip .room .adapter .out .jpa .RoomParticipantJpaEntity ;
2123import org .springframework .boot .test .context .SpringBootTest ;
2224import org .springframework .http .MediaType ;
2325import org .springframework .test .context .ActiveProfiles ;
26+ import org .springframework .test .context .bean .override .mockito .MockitoBean ;
2427import org .springframework .test .web .servlet .MockMvc ;
2528import org .springframework .test .web .servlet .ResultActions ;
2629import org .springframework .transaction .annotation .Transactional ;
3134import java .util .Map ;
3235
3336import static org .assertj .core .api .Assertions .assertThat ;
37+ import static org .mockito .ArgumentMatchers .anyString ;
38+ import static org .mockito .Mockito .when ;
3439import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
3540import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
3641import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
@@ -49,6 +54,7 @@ class RoomCreateApiTest {
4954 @ Autowired private BookJpaRepository bookJpaRepository ;
5055 @ Autowired private RoomJpaRepository roomJpaRepository ;
5156 @ Autowired private RoomParticipantJpaRepository roomParticipantJpaRepository ;
57+ @ MockitoBean private BookApiQueryPort mockBookApiQueryPort ;
5258
5359 private void saveUserAndLiteratureCategory () {
5460 Alias alias = TestEntityFactory .createLiteratureAlias ();
@@ -158,6 +164,8 @@ void room_create_book_without_page_exist() throws Exception {
158164
159165 Map <String , Object > request = buildRoomCreateRequest ();
160166
167+ when (mockBookApiQueryPort .findPageCountByIsbn (anyString ())).thenReturn (296 );
168+
161169 //when
162170 ResultActions result = mockMvc .perform (post ("/rooms" )
163171 .requestAttr ("userId" , userId )
@@ -204,6 +212,17 @@ void room_create_book_not_exist() throws Exception {
204212
205213 Map <String , Object > request = buildRoomCreateRequest ();
206214
215+ Book mockBook = Book .withoutId (
216+ "작별하지 않는다" ,
217+ "9791168342941" ,
218+ "박곰희" ,
219+ false ,
220+ "문학동네" ,
221+ "https://image1.jpg" ,
222+ 296 ,
223+ "한강의 소설" );
224+ when (mockBookApiQueryPort .loadBookWithPageByIsbn (anyString ())).thenReturn (mockBook );
225+
207226 //when
208227 ResultActions result = mockMvc .perform (post ("/rooms" )
209228 .requestAttr ("userId" , userId )
0 commit comments