From ce4024ee3d28f84c1b2ed22afe290e0d631b56e6 Mon Sep 17 00:00:00 2001 From: Wonjeong Kim Date: Thu, 21 Mar 2024 16:29:56 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20GroupControllerTest=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/service/boardService/BoardService.java | 1 + .../impl/IntroBoardServiceImpl.java | 2 +- .../kr/controller/GroupControllerTest.java | 106 +++++++++--------- 3 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/main/java/server/inuappcenter/kr/service/boardService/BoardService.java b/src/main/java/server/inuappcenter/kr/service/boardService/BoardService.java index 21f7b5d..e146ad8 100644 --- a/src/main/java/server/inuappcenter/kr/service/boardService/BoardService.java +++ b/src/main/java/server/inuappcenter/kr/service/boardService/BoardService.java @@ -42,6 +42,7 @@ public BoardResponseDto findBoard(Long id) { ); } + @Transactional public CommonResponseDto saveBoard(BoardRequestDto boardRequestDto) { Board savedBoard = boardRepository.save(boardRequestDto.createBoard()); diff --git a/src/main/java/server/inuappcenter/kr/service/boardService/impl/IntroBoardServiceImpl.java b/src/main/java/server/inuappcenter/kr/service/boardService/impl/IntroBoardServiceImpl.java index 6fb97cb..a2d08ef 100644 --- a/src/main/java/server/inuappcenter/kr/service/boardService/impl/IntroBoardServiceImpl.java +++ b/src/main/java/server/inuappcenter/kr/service/boardService/impl/IntroBoardServiceImpl.java @@ -21,7 +21,7 @@ public class IntroBoardServiceImpl implements AdditionalBoardService { @Override @Transactional(readOnly = true) public List findBoardList(String topic) { - List responseDtoList= new ArrayList<>(); + List responseDtoList = new ArrayList<>(); for (Board board : introBoardRepository.findAll()) { responseDtoList.add(board.createResponse(request)); } diff --git a/src/test/java/server/inuappcenter/kr/controller/GroupControllerTest.java b/src/test/java/server/inuappcenter/kr/controller/GroupControllerTest.java index 4c4d9c3..e4961ce 100644 --- a/src/test/java/server/inuappcenter/kr/controller/GroupControllerTest.java +++ b/src/test/java/server/inuappcenter/kr/controller/GroupControllerTest.java @@ -77,34 +77,34 @@ public void getGroupTest() throws Exception { verify(groupService).getGroup(givenId); } -// @WithMockUser -// @DisplayName("그룹 멤버 전체 조회 테스트") -// @Test -// public void findAllGroup() throws Exception { -// // given -// List expectedDtoList = new ArrayList<>(); -// for (int i = 0; i < 10; i++) { -// expectedDtoList.add(expectedDto); -// } -// given(groupService.findAllGroup()).willReturn(expectedDtoList); -// // when -// mockMvc.perform(get("/groups/public/all-groups-members")) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$..group_id").exists()) -// .andExpect(jsonPath("$..member").exists()) -// .andExpect(jsonPath("$..profileImage").exists()) -// .andExpect(jsonPath("$..email").exists()) -// .andExpect(jsonPath("$..blogLink").exists()) -// .andExpect(jsonPath("$..gitRepositoryLink").exists()) -// .andExpect(jsonPath("$..role").exists()) -// .andExpect(jsonPath("$..part").exists()) -// .andExpect(jsonPath("$..year").exists()) -// .andExpect(jsonPath("$..createdDate").exists()) -// .andExpect(jsonPath("$..lastModifiedDate").exists()) -// .andDo(print()); -// // then -// verify(groupService).findAllGroup(); -// } + @WithMockUser + @DisplayName("그룹 멤버 전체 조회 테스트") + @Test + public void findAllGroup() throws Exception { + // given + List expectedDtoList = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + expectedDtoList.add(expectedDto); + } + given(groupService.findAllGroup(14.5, "Android")).willReturn(expectedDtoList); + // when + mockMvc.perform(get("/groups/public/all-groups-members?year=14.5&part=Android")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$..group_id").exists()) + .andExpect(jsonPath("$..member").exists()) + .andExpect(jsonPath("$..profileImage").exists()) + .andExpect(jsonPath("$..email").exists()) + .andExpect(jsonPath("$..blogLink").exists()) + .andExpect(jsonPath("$..gitRepositoryLink").exists()) + .andExpect(jsonPath("$..role").exists()) + .andExpect(jsonPath("$..part").exists()) + .andExpect(jsonPath("$..year").exists()) + .andExpect(jsonPath("$..createdDate").exists()) + .andExpect(jsonPath("$..lastModifiedDate").exists()) + .andDo(print()); + // then + verify(groupService).findAllGroup(14.5, "Android"); + } @WithMockUser @DisplayName("그룹 멤버 한 명 편성 테스트") @@ -132,31 +132,31 @@ public void assignGroupTest() throws Exception { verify(groupService).assignGroup(eq(givenId), eq(givenId), any(GroupRequestDto.class)); } -// @WithMockUser -// @DisplayName("그룹 멤버 한 명 수정 테스트") -// @Test -// public void updateGroupTest() throws Exception { -// // given -// given(groupService.updateGroup(any(GroupRequestDto.class), eq(givenId))).willReturn(expectedDto); -// String objectToJson = objectMapper.writeValueAsString(givenDto); -// // when -// mockMvc.perform(patch("/groups?id="+givenId).content(objectToJson).contentType(MediaType.APPLICATION_JSON).with(csrf())) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$..group_id").exists()) -// .andExpect(jsonPath("$.member").exists()) -// .andExpect(jsonPath("$.profileImage").exists()) -// .andExpect(jsonPath("$.email").exists()) -// .andExpect(jsonPath("$.blogLink").exists()) -// .andExpect(jsonPath("$.gitRepositoryLink").exists()) -// .andExpect(jsonPath("$.role").exists()) -// .andExpect(jsonPath("$.part").exists()) -// .andExpect(jsonPath("$.year").exists()) -// .andExpect(jsonPath("$..createdDate").exists()) -// .andExpect(jsonPath("$..lastModifiedDate").exists()) -// .andDo(print()); -// // then -// verify(groupService).updateGroup(any(GroupRequestDto.class), eq(givenId)); -// } + @WithMockUser + @DisplayName("그룹 멤버 한 명 수정 테스트") + @Test + public void updateGroupTest() throws Exception { + // given + given(groupService.updateGroup(any(GroupRequestDto.class), eq(givenId), eq(givenId))).willReturn(expectedDto); + String objectToJson = objectMapper.writeValueAsString(givenDto); + // when + mockMvc.perform(patch("/groups?groupId=1&roleId=1").content(objectToJson).contentType(MediaType.APPLICATION_JSON).with(csrf())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$..group_id").exists()) + .andExpect(jsonPath("$.member").exists()) + .andExpect(jsonPath("$.profileImage").exists()) + .andExpect(jsonPath("$.email").exists()) + .andExpect(jsonPath("$.blogLink").exists()) + .andExpect(jsonPath("$.gitRepositoryLink").exists()) + .andExpect(jsonPath("$.role").exists()) + .andExpect(jsonPath("$.part").exists()) + .andExpect(jsonPath("$.year").exists()) + .andExpect(jsonPath("$..createdDate").exists()) + .andExpect(jsonPath("$..lastModifiedDate").exists()) + .andDo(print()); + // then + verify(groupService).updateGroup(any(GroupRequestDto.class), eq(givenId), eq(givenId)); + } @WithMockUser @DisplayName("그룹 멤버 한 명 삭제 테스트")