1- package sevenstar .marineleisure .alert .controller ;
2-
3- import static org .mockito .BDDMockito .*;
4- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
5- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .*;
6-
7- import java .time .LocalDate ;
8- import java .util .List ;
9-
10- import org .junit .jupiter .api .DisplayName ;
11- import org .junit .jupiter .api .Test ;
12- import org .springframework .beans .factory .annotation .Autowired ;
13- import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
14- import org .springframework .boot .test .autoconfigure .web .servlet .WebMvcTest ;
15- import org .springframework .test .context .bean .override .mockito .MockitoBean ;
16- import org .springframework .test .web .servlet .MockMvc ;
17- import org .springframework .validation .Validator ;
18-
19- import com .fasterxml .jackson .databind .ObjectMapper ;
20-
21- import sevenstar .marineleisure .alert .dto .response .JellyfishResponseDto ;
22- import sevenstar .marineleisure .alert .dto .vo .JellyfishDetailVO ;
23- import sevenstar .marineleisure .alert .dto .vo .JellyfishRegionVO ;
24- import sevenstar .marineleisure .alert .dto .vo .JellyfishSpeciesVO ;
25- import sevenstar .marineleisure .alert .mapper .AlertMapper ;
26- import sevenstar .marineleisure .alert .service .JellyfishService ;
27-
28- @ WebMvcTest (AlertController .class )
29- @ AutoConfigureMockMvc (addFilters = false )
30- class AlertControllerTest {
31- @ Autowired
32- private MockMvc mockMvc ;
33-
34- @ Autowired
35- private ObjectMapper objectMapper ;
36-
37- @ MockitoBean
38- private JellyfishService jellyfishService ;
39-
40- @ MockitoBean
41- private AlertMapper alertMapper ;
42-
43- @ Autowired
44- private Validator validator ;
45-
46- @ Test
47- @ DisplayName ("해파리 경보를 성공적으로 반환합니다." )
48- void sendAlert_Sucess () throws Exception {
49- // List<JellyfishDetailVO> items = jellyfishService.search();
50- // JellyfishResponseDto result = alertMapper.toResponseDto(items);
51- // return BaseResponse.success(result);
52-
53- //given
54- JellyfishDetailVO mockVO = new JellyfishDetailVO () {
55- @ Override
56- public String getSpecies () {
57- return "노무라입깃해파리" ;
58- }
59-
60- @ Override
61- public String getRegion () {
62- return "부산" ;
63- }
64-
65- @ Override
66- public String getDensityType () {
67- return "LOW" ;
68- }
69-
70- @ Override
71- public String getToxicity () {
72- return "HIGH" ;
73- }
74-
75- @ Override
76- public LocalDate getReportDate () {
77- return LocalDate .of (2025 , 7 , 10 );
78- }
79- };
80-
81- List <JellyfishDetailVO > voList = List .of (mockVO );
82-
83- JellyfishResponseDto responseDto = new JellyfishResponseDto (
84- LocalDate .of (2025 , 7 , 10 ),
85- List .of (new JellyfishRegionVO (
86- "부산" ,
87- new JellyfishSpeciesVO (
88- "노무라입깃해파리" ,
89- "강독성" , // ToxicityLevel.HIGH.getDescription()
90- "저밀도" // DensityLevel.LOW.getDescription()
91- )
92- ))
93- );
94-
95- given (jellyfishService .search ()).willReturn (voList );
96- given (alertMapper .toResponseDto (voList )).willReturn (responseDto );
97-
98- //when & then
99- mockMvc .perform (get ("/alerts/jellyfish" ))
100- .andExpect (status ().isOk ())
101- .andExpect (jsonPath ("$.code" ).value (200 ))
102- .andExpect (jsonPath ("$.message" ).value ("Success" ))
103- .andExpect (jsonPath ("$.body.reportDate" ).value ("2025-07-10" ))
104- .andExpect (jsonPath ("$.body.regions[0].regionName" ).value ("부산" ))
105- .andExpect (jsonPath ("$.body.regions[0].species.name" ).value ("노무라입깃해파리" ))
106- .andExpect (jsonPath ("$.body.regions[0].species.toxicity" ).value ("강독성" ))
107- .andExpect (jsonPath ("$.body.regions[0].species.density" ).value ("저밀도" ));
108-
109- }
110- }
1+ // package sevenstar.marineleisure.alert.controller;
2+ //
3+ // import static org.mockito.BDDMockito.*;
4+ // import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
5+ // import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
6+ //
7+ // import java.time.LocalDate;
8+ // import java.util.List;
9+ //
10+ // import org.junit.jupiter.api.DisplayName;
11+ // import org.junit.jupiter.api.Test;
12+ // import org.springframework.beans.factory.annotation.Autowired;
13+ // import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
14+ // import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
15+ // import org.springframework.test.context.bean.override.mockito.MockitoBean;
16+ // import org.springframework.test.web.servlet.MockMvc;
17+ // import org.springframework.validation.Validator;
18+ //
19+ // import com.fasterxml.jackson.databind.ObjectMapper;
20+ //
21+ // import sevenstar.marineleisure.alert.dto.response.JellyfishResponseDto;
22+ // import sevenstar.marineleisure.alert.dto.vo.JellyfishDetailVO;
23+ // import sevenstar.marineleisure.alert.dto.vo.JellyfishRegionVO;
24+ // import sevenstar.marineleisure.alert.dto.vo.JellyfishSpeciesVO;
25+ // import sevenstar.marineleisure.alert.mapper.AlertMapper;
26+ // import sevenstar.marineleisure.alert.service.JellyfishService;
27+ //
28+ // @WebMvcTest(AlertController.class)
29+ // @AutoConfigureMockMvc(addFilters = false)
30+ // class AlertControllerTest {
31+ // @Autowired
32+ // private MockMvc mockMvc;
33+ //
34+ // @Autowired
35+ // private ObjectMapper objectMapper;
36+ //
37+ // @MockitoBean
38+ // private JellyfishService jellyfishService;
39+ //
40+ // @MockitoBean
41+ // private AlertMapper alertMapper;
42+ //
43+ // @Autowired
44+ // private Validator validator;
45+ //
46+ // @Test
47+ // @DisplayName("해파리 경보를 성공적으로 반환합니다.")
48+ // void sendAlert_Sucess() throws Exception {
49+ // // List<JellyfishDetailVO> items = jellyfishService.search();
50+ // // JellyfishResponseDto result = alertMapper.toResponseDto(items);
51+ // // return BaseResponse.success(result);
52+ //
53+ // //given
54+ // JellyfishDetailVO mockVO = new JellyfishDetailVO() {
55+ // @Override
56+ // public String getSpecies() {
57+ // return "노무라입깃해파리";
58+ // }
59+ //
60+ // @Override
61+ // public String getRegion() {
62+ // return "부산";
63+ // }
64+ //
65+ // @Override
66+ // public String getDensityType() {
67+ // return "LOW";
68+ // }
69+ //
70+ // @Override
71+ // public String getToxicity() {
72+ // return "HIGH";
73+ // }
74+ //
75+ // @Override
76+ // public LocalDate getReportDate() {
77+ // return LocalDate.of(2025, 7, 10);
78+ // }
79+ // };
80+ //
81+ // List<JellyfishDetailVO> voList = List.of(mockVO);
82+ //
83+ // JellyfishResponseDto responseDto = new JellyfishResponseDto(
84+ // LocalDate.of(2025, 7, 10),
85+ // List.of(new JellyfishRegionVO(
86+ // "부산",
87+ // new JellyfishSpeciesVO(
88+ // "노무라입깃해파리",
89+ // "강독성", // ToxicityLevel.HIGH.getDescription()
90+ // "저밀도" // DensityLevel.LOW.getDescription()
91+ // )
92+ // ))
93+ // );
94+ //
95+ // given(jellyfishService.search()).willReturn(voList);
96+ // given(alertMapper.toResponseDto(voList)).willReturn(responseDto);
97+ //
98+ // //when & then
99+ // mockMvc.perform(get("/alerts/jellyfish"))
100+ // .andExpect(status().isOk())
101+ // .andExpect(jsonPath("$.code").value(200))
102+ // .andExpect(jsonPath("$.message").value("Success"))
103+ // .andExpect(jsonPath("$.body.reportDate").value("2025-07-10"))
104+ // .andExpect(jsonPath("$.body.regions[0].regionName").value("부산"))
105+ // .andExpect(jsonPath("$.body.regions[0].species.name").value("노무라입깃해파리"))
106+ // .andExpect(jsonPath("$.body.regions[0].species.toxicity").value("강독성"))
107+ // .andExpect(jsonPath("$.body.regions[0].species.density").value("저밀도"));
108+ //
109+ // }
110+ // }
0 commit comments