Merge pull request 'api scene test code' (#125) from feat/dean/api-scene-test into develop
Reviewed-on: https://kamco.gitea.gs.dabeeo.com/dabeeo/kamco-dabeeo-backoffice/pulls/125
This commit is contained in:
@@ -0,0 +1,208 @@
|
|||||||
|
package com.kamco.cd.kamcoback.scene;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.auth.JwtTokenProvider;
|
||||||
|
import com.kamco.cd.kamcoback.common.enums.CommonUseStatus;
|
||||||
|
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
|
||||||
|
import com.kamco.cd.kamcoback.menu.service.MenuService;
|
||||||
|
import com.kamco.cd.kamcoback.postgres.repository.log.AuditLogRepository;
|
||||||
|
import com.kamco.cd.kamcoback.postgres.repository.log.ErrorLogRepository;
|
||||||
|
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto;
|
||||||
|
import com.kamco.cd.kamcoback.scene.service.MapInkxMngService;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
@WebMvcTest(MapInkxMngApiV2Controller.class)
|
||||||
|
@AutoConfigureMockMvc(addFilters = false)
|
||||||
|
class MapInkxMngApiV2ControllerTest {
|
||||||
|
|
||||||
|
@Autowired private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@MockitoBean private MapInkxMngService mapInkxMngService;
|
||||||
|
|
||||||
|
@MockitoBean private JwtTokenProvider jwtTokenProvider;
|
||||||
|
|
||||||
|
@MockitoBean private ErrorLogRepository errorLogRepository;
|
||||||
|
|
||||||
|
@MockitoBean private AuditLogRepository auditLogRepository;
|
||||||
|
|
||||||
|
@MockitoBean private MenuService menuService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("도엽 목록 조회 - 기본 파라미터")
|
||||||
|
void findMapInkxMngList_withDefaultParams() throws Exception {
|
||||||
|
// Given
|
||||||
|
InferenceResultDto.MapSheet scene50k = new InferenceResultDto.MapSheet("36713", "논산");
|
||||||
|
InferenceResultDto.MapSheet scene5k1 = new InferenceResultDto.MapSheet("36713029", "논산");
|
||||||
|
InferenceResultDto.MapSheet scene5k2 = new InferenceResultDto.MapSheet("36713085", "논산");
|
||||||
|
|
||||||
|
MapInkxMngDto.MapListEntity entity1 =
|
||||||
|
MapInkxMngDto.MapListEntity.builder()
|
||||||
|
.scene50k(scene50k)
|
||||||
|
.scene5k(scene5k1)
|
||||||
|
.useInference(CommonUseStatus.USE)
|
||||||
|
.createdDttm(ZonedDateTime.now())
|
||||||
|
.updatedDttm(ZonedDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
MapInkxMngDto.MapListEntity entity2 =
|
||||||
|
MapInkxMngDto.MapListEntity.builder()
|
||||||
|
.scene50k(scene50k)
|
||||||
|
.scene5k(scene5k2)
|
||||||
|
.useInference(CommonUseStatus.USE)
|
||||||
|
.createdDttm(ZonedDateTime.now())
|
||||||
|
.updatedDttm(ZonedDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Page<MapInkxMngDto.MapListEntity> page =
|
||||||
|
new PageImpl<>(List.of(entity1, entity2), PageRequest.of(0, 20), 2);
|
||||||
|
|
||||||
|
when(mapInkxMngService.findMapInkxMngLists(eq(null), eq(null), any())).thenReturn(page);
|
||||||
|
|
||||||
|
// When & Then
|
||||||
|
mockMvc
|
||||||
|
.perform(get("/api/v2/scene"))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data.content").isArray())
|
||||||
|
.andExpect(jsonPath("$.data.content[0].scene5k.number").value("36713029"))
|
||||||
|
.andExpect(jsonPath("$.data.content[0].scene5k.name").value("논산"))
|
||||||
|
.andExpect(jsonPath("$.data.content[1].scene5k.number").value("36713085"))
|
||||||
|
.andExpect(jsonPath("$.data.totalElements").value(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("도엽 목록 조회 - useInference 파라미터 포함")
|
||||||
|
void findMapInkxMngList_withUseInferenceParam() throws Exception {
|
||||||
|
// Given
|
||||||
|
InferenceResultDto.MapSheet scene50k = new InferenceResultDto.MapSheet("36713", "논산");
|
||||||
|
InferenceResultDto.MapSheet scene5k = new InferenceResultDto.MapSheet("36713029", "논산");
|
||||||
|
|
||||||
|
MapInkxMngDto.MapListEntity entity =
|
||||||
|
MapInkxMngDto.MapListEntity.builder()
|
||||||
|
.scene50k(scene50k)
|
||||||
|
.scene5k(scene5k)
|
||||||
|
.useInference(CommonUseStatus.EXCEPT)
|
||||||
|
.createdDttm(ZonedDateTime.now())
|
||||||
|
.updatedDttm(ZonedDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Page<MapInkxMngDto.MapListEntity> page =
|
||||||
|
new PageImpl<>(List.of(entity), PageRequest.of(0, 20), 1);
|
||||||
|
|
||||||
|
when(mapInkxMngService.findMapInkxMngLists(eq(CommonUseStatus.EXCEPT), eq(null), any()))
|
||||||
|
.thenReturn(page);
|
||||||
|
|
||||||
|
// When & Then
|
||||||
|
mockMvc
|
||||||
|
.perform(get("/api/v2/scene").param("useInference", "EXCEPT"))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data.content").isArray())
|
||||||
|
.andExpect(jsonPath("$.data.content[0].useInference.id").value("EXCEPT"))
|
||||||
|
.andExpect(jsonPath("$.data.totalElements").value(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("도엽 목록 조회 - searchVal 파라미터로 검색")
|
||||||
|
void findMapInkxMngList_withSearchVal() throws Exception {
|
||||||
|
// Given
|
||||||
|
InferenceResultDto.MapSheet scene50k = new InferenceResultDto.MapSheet("36713029", "공덕");
|
||||||
|
InferenceResultDto.MapSheet scene5k = new InferenceResultDto.MapSheet("31540687", "공덕");
|
||||||
|
|
||||||
|
MapInkxMngDto.MapListEntity entity =
|
||||||
|
MapInkxMngDto.MapListEntity.builder()
|
||||||
|
.scene50k(scene50k)
|
||||||
|
.scene5k(scene5k)
|
||||||
|
.useInference(CommonUseStatus.USE)
|
||||||
|
.createdDttm(ZonedDateTime.now())
|
||||||
|
.updatedDttm(ZonedDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Page<MapInkxMngDto.MapListEntity> page =
|
||||||
|
new PageImpl<>(List.of(entity), PageRequest.of(0, 20), 1);
|
||||||
|
|
||||||
|
when(mapInkxMngService.findMapInkxMngLists(eq(null), eq("공덕"), any())).thenReturn(page);
|
||||||
|
|
||||||
|
// When & Then
|
||||||
|
mockMvc
|
||||||
|
.perform(get("/api/v2/scene").param("searchVal", "공덕"))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data.content[0].scene5k.name").value("공덕"))
|
||||||
|
.andExpect(jsonPath("$.data.totalElements").value(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("도엽 목록 조회 - 페이징 파라미터")
|
||||||
|
void findMapInkxMngList_withPagingParams() throws Exception {
|
||||||
|
// Given
|
||||||
|
Page<MapInkxMngDto.MapListEntity> page = new PageImpl<>(List.of(), PageRequest.of(1, 10), 0);
|
||||||
|
|
||||||
|
when(mapInkxMngService.findMapInkxMngLists(eq(null), eq(null), any())).thenReturn(page);
|
||||||
|
|
||||||
|
// When & Then
|
||||||
|
mockMvc
|
||||||
|
.perform(get("/api/v2/scene").param("page", "1").param("size", "10"))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data.pageable.pageNumber").value(1))
|
||||||
|
.andExpect(jsonPath("$.data.pageable.pageSize").value(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("도엽 목록 조회 - 모든 파라미터 포함")
|
||||||
|
void findMapInkxMngList_withAllParams() throws Exception {
|
||||||
|
// Given
|
||||||
|
InferenceResultDto.MapSheet scene50k = new InferenceResultDto.MapSheet("31540", "공덕");
|
||||||
|
InferenceResultDto.MapSheet scene5k = new InferenceResultDto.MapSheet("31540687", "공덕");
|
||||||
|
|
||||||
|
MapInkxMngDto.MapListEntity entity =
|
||||||
|
MapInkxMngDto.MapListEntity.builder()
|
||||||
|
.scene50k(scene50k)
|
||||||
|
.scene5k(scene5k)
|
||||||
|
.useInference(CommonUseStatus.USE)
|
||||||
|
.createdDttm(ZonedDateTime.now())
|
||||||
|
.updatedDttm(ZonedDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Page<MapInkxMngDto.MapListEntity> page =
|
||||||
|
new PageImpl<>(List.of(entity), PageRequest.of(0, 5), 1);
|
||||||
|
|
||||||
|
when(mapInkxMngService.findMapInkxMngLists(eq(CommonUseStatus.USE), eq("공덕"), any()))
|
||||||
|
.thenReturn(page);
|
||||||
|
|
||||||
|
// When & Then
|
||||||
|
mockMvc
|
||||||
|
.perform(
|
||||||
|
get("/api/v2/scene")
|
||||||
|
.param("page", "0")
|
||||||
|
.param("size", "5")
|
||||||
|
.param("useInference", "USE")
|
||||||
|
.param("searchVal", "공덕"))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data.content[0].scene5k.number").value("31540687"))
|
||||||
|
.andExpect(jsonPath("$.data.content[0].scene5k.name").value("공덕"))
|
||||||
|
.andExpect(jsonPath("$.data.content[0].useInference.id").value("USE"))
|
||||||
|
.andExpect(jsonPath("$.data.totalElements").value(1))
|
||||||
|
.andExpect(jsonPath("$.data.pageable.pageSize").value(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user