1515import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
1616import org .springframework .boot .test .context .SpringBootTest ;
1717import org .springframework .boot .test .mock .mockito .MockBean ;
18+ import org .springframework .data .domain .Page ;
19+ import org .springframework .data .domain .PageImpl ;
20+ import org .springframework .data .domain .PageRequest ;
1821import org .springframework .http .MediaType ;
1922import org .springframework .test .context .ActiveProfiles ;
2023import org .springframework .test .web .servlet .MockMvc ;
2326import java .time .LocalDateTime ;
2427import java .util .List ;
2528
26- import static org .mockito .ArgumentMatchers .*;
29+ import static org .mockito .ArgumentMatchers .any ;
30+ import static org .mockito .ArgumentMatchers .eq ;
2731import static org .mockito .BDDMockito .given ;
28- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
32+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
33+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
2934import static org .springframework .test .web .servlet .result .MockMvcResultHandlers .print ;
30- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .*;
35+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
36+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
3137
3238/**
3339 * ScenarioController 통합 테스트.
34- * 인증/인가가 구현되지 않은 상태에서 Service를 모킹하여 테스트합니다.
40+ * 세션 기반 인증이 구현되었지만 테스트에서는 필터를 비활성화하고
41+ * Service를 모킹하여 테스트합니다.
3542 */
3643@ SpringBootTest
37- @ AutoConfigureMockMvc (addFilters = false )
44+ @ AutoConfigureMockMvc (addFilters = false ) // 인증 필터 비활성화로 테스트 단순화
3845@ ActiveProfiles ("test" )
3946@ Transactional
4047@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
@@ -75,11 +82,10 @@ class CreateScenario {
7582 .contentType (MediaType .APPLICATION_JSON )
7683 .content (objectMapper .writeValueAsString (request )))
7784 .andDo (print ())
78- .andExpect (status ().isOk ()) // ApiResponse는 실제 HTTP 상태를 설정하지 않음
79- .andExpect (jsonPath ("$.data.scenarioId" ).value (1001 ))
80- .andExpect (jsonPath ("$.data.status" ).value ("PENDING" ))
81- .andExpect (jsonPath ("$.message" ).value ("시나리오 생성 요청이 접수되었습니다." ))
82- .andExpect (jsonPath ("$.status" ).value (201 )); // 응답 본문의 status 필드 검증
85+ .andExpect (status ().isCreated ())
86+ .andExpect (jsonPath ("$.scenarioId" ).value (1001 ))
87+ .andExpect (jsonPath ("$.status" ).value ("PENDING" ))
88+ .andExpect (jsonPath ("$.message" ).value ("시나리오 생성이 시작되었습니다." ));
8389 }
8490
8591 @ Test
@@ -136,9 +142,9 @@ class GetScenarioStatus {
136142 mockMvc .perform (get ("/api/v1/scenarios/{scenarioId}/status" , scenarioId ))
137143 .andDo (print ())
138144 .andExpect (status ().isOk ())
139- .andExpect (jsonPath ("$.data. scenarioId" ).value (scenarioId ))
140- .andExpect (jsonPath ("$.data. status" ).value ("COMPLETED" ))
141- .andExpect (jsonPath ("$.message" ).value ("상태를 성공적으로 조회했습니다 ." ));
145+ .andExpect (jsonPath ("$.scenarioId" ).value (scenarioId ))
146+ .andExpect (jsonPath ("$.status" ).value ("COMPLETED" ))
147+ .andExpect (jsonPath ("$.message" ).value ("시나리오 생성이 완료되었습니다 ." ));
142148 }
143149
144150 @ Test
@@ -194,11 +200,11 @@ class GetScenarioDetail {
194200 mockMvc .perform (get ("/api/v1/scenarios/info/{scenarioId}" , scenarioId ))
195201 .andDo (print ())
196202 .andExpect (status ().isOk ())
197- .andExpect (jsonPath ("$.data. scenarioId" ).value (scenarioId ))
198- .andExpect (jsonPath ("$.data. job" ).value ("스타트업 CEO" ))
199- .andExpect (jsonPath ("$.data. total" ).value (85 ))
200- .andExpect (jsonPath ("$.data. indicators" ).isArray ())
201- .andExpect (jsonPath ("$.data. indicators.length()" ).value (5 ));
203+ .andExpect (jsonPath ("$.scenarioId" ).value (scenarioId ))
204+ .andExpect (jsonPath ("$.job" ).value ("스타트업 CEO" ))
205+ .andExpect (jsonPath ("$.total" ).value (85 ))
206+ .andExpect (jsonPath ("$.indicators" ).isArray ())
207+ .andExpect (jsonPath ("$.indicators.length()" ).value (5 ));
202208 }
203209 }
204210
@@ -227,10 +233,10 @@ class GetScenarioTimeline {
227233 mockMvc .perform (get ("/api/v1/scenarios/{scenarioId}/timeline" , scenarioId ))
228234 .andDo (print ())
229235 .andExpect (status ().isOk ())
230- .andExpect (jsonPath ("$.data. scenarioId" ).value (scenarioId ))
231- .andExpect (jsonPath ("$.data. events" ).isArray ())
232- .andExpect (jsonPath ("$.data. events[0].year" ).value (2025 ))
233- .andExpect (jsonPath ("$.data. events[0].title" ).value ("창업 시작" ));
236+ .andExpect (jsonPath ("$.scenarioId" ).value (scenarioId ))
237+ .andExpect (jsonPath ("$.events" ).isArray ())
238+ .andExpect (jsonPath ("$.events[0].year" ).value (2025 ))
239+ .andExpect (jsonPath ("$.events[0].title" ).value ("창업 시작" ));
234240 }
235241 }
236242
@@ -242,7 +248,7 @@ class GetBaselines {
242248 @ DisplayName ("성공 - 사용자 베이스라인 목록 조회" )
243249 void getBaselines_성공 () throws Exception {
244250 // Given
245- List <BaselineListResponse > mockResponse = List .of (
251+ List <BaselineListResponse > content = List .of (
246252 new BaselineListResponse (
247253 200L ,
248254 "대학 졸업 이후" ,
@@ -257,16 +263,22 @@ class GetBaselines {
257263 )
258264 );
259265
260- given (scenarioService .getBaselines (1L ))
261- .willReturn (mockResponse );
266+ Page <BaselineListResponse > mockPageResponse = new PageImpl <>(content , PageRequest .of (0 , 10 ), content .size ());
267+
268+ given (scenarioService .getBaselines (eq (1L ), any ()))
269+ .willReturn (mockPageResponse );
262270
263271 // When & Then
264- mockMvc .perform (get ("/api/v1/scenarios/baselines" ))
272+ mockMvc .perform (get ("/api/v1/scenarios/baselines" )
273+ .param ("page" , "0" )
274+ .param ("size" , "10" ))
265275 .andDo (print ())
266276 .andExpect (status ().isOk ())
267- .andExpect (jsonPath ("$.data" ).isArray ())
268- .andExpect (jsonPath ("$.data[0].baselineId" ).value (200 ))
269- .andExpect (jsonPath ("$.data[0].title" ).value ("대학 졸업 이후" ));
277+ .andExpect (jsonPath ("$.content" ).isArray ())
278+ .andExpect (jsonPath ("$.content[0].baselineId" ).value (200 ))
279+ .andExpect (jsonPath ("$.content[0].title" ).value ("대학 졸업 이후" ))
280+ .andExpect (jsonPath ("$.totalElements" ).value (2 ))
281+ .andExpect (jsonPath ("$.totalPages" ).value (1 ));
270282 }
271283 }
272284
@@ -303,10 +315,10 @@ class CompareScenarios {
303315 mockMvc .perform (get ("/api/v1/scenarios/compare/{baseId}/{compareId}" , baseId , compareId ))
304316 .andDo (print ())
305317 .andExpect (status ().isOk ())
306- .andExpect (jsonPath ("$.data. baseScenarioId" ).value (baseId ))
307- .andExpect (jsonPath ("$.data. compareScenarioId" ).value (compareId ))
308- .andExpect (jsonPath ("$.data. overallAnalysis" ).exists ())
309- .andExpect (jsonPath ("$.data. indicators" ).isArray ());
318+ .andExpect (jsonPath ("$.baseScenarioId" ).value (baseId ))
319+ .andExpect (jsonPath ("$.compareScenarioId" ).value (compareId ))
320+ .andExpect (jsonPath ("$.overallAnalysis" ).exists ())
321+ .andExpect (jsonPath ("$.indicators" ).isArray ());
310322 }
311323 }
312324}
0 commit comments