diff --git a/resource-server/src/main/java/com/inhabas/api/domain/scholarship/usecase/ScholarshipBoardServiceImpl.java b/resource-server/src/main/java/com/inhabas/api/domain/scholarship/usecase/ScholarshipBoardServiceImpl.java index 7a8516ef..38bdb91a 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/scholarship/usecase/ScholarshipBoardServiceImpl.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/scholarship/usecase/ScholarshipBoardServiceImpl.java @@ -33,7 +33,6 @@ public class ScholarshipBoardServiceImpl implements ScholarshipBoardService { private final BoardFileRepository boardFileRepository; - private final ScholarshipBoardRepository scholarshipBoardRepository; private final MenuRepository menuRepository; private final MemberRepository memberRepository; diff --git a/resource-server/src/main/java/com/inhabas/api/web/ScholarshipController.java b/resource-server/src/main/java/com/inhabas/api/web/ScholarshipController.java index 9ba04027..0b1d69c3 100644 --- a/resource-server/src/main/java/com/inhabas/api/web/ScholarshipController.java +++ b/resource-server/src/main/java/com/inhabas/api/web/ScholarshipController.java @@ -99,17 +99,17 @@ public ResponseEntity> getBoardList( @ApiResponses({ @ApiResponse( responseCode = "200", - content = {@Content(schema = @Schema(implementation = ScholarshipBoardDto.class))}), + content = {@Content(schema = @Schema(implementation = ScholarshipBoardDetailDto.class))}), @ApiResponse( - responseCode = "404", - description = "데이터가 존재하지 않습니다.", + responseCode = "400", + description = "입력값이 없거나, 타입이 유효하지 않습니다.", content = @Content( schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject( value = - "{\"status\": 404, \"code\": \"G004\", \"message\": \"데이터가 존재하지 않습니다.\"}"))) + "{\"status\": 400, \"code\": \"G003\", \"message\": \"입력값이 없거나, 타입이 유효하지 않습니다.\"}"))) }) public ResponseEntity getBoard( @PathVariable Long boardId, diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contest/domain/ContestBoardTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contest/domain/ContestBoardTest.java index 29f6d84a..6db3cdbb 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/contest/domain/ContestBoardTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/contest/domain/ContestBoardTest.java @@ -9,6 +9,7 @@ import org.springframework.test.util.ReflectionTestUtils; +import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; import com.inhabas.api.domain.file.domain.BoardFile; import com.inhabas.api.domain.menu.domain.Menu; import org.mockito.Mock; @@ -21,7 +22,7 @@ class ContestBoardTest { @Mock private Menu menu; - + @Mock private Member writer; @Mock private ContestField contestField; private ContestBoard contestBoard; @@ -109,8 +110,8 @@ void updateFilesTest() { // Given List files = new ArrayList<>(); - files.add(new BoardFile("file1.jpg", "/url1", contestBoard)); - files.add(new BoardFile("file2.pdf", "/url2", contestBoard)); + files.add(new BoardFile("random", "file1.jpg", "/url1", writer, 10L, "image/jpeg")); + files.add(new BoardFile("random", "file2.pdf", "/url2", writer, 10L, "image/jpeg")); // When contestBoard.updateFiles(files); diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDetailDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDetailDtoTest.java index 8dc9d2b1..cf17b5cb 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDetailDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDetailDtoTest.java @@ -52,7 +52,8 @@ public void createContestBoardDetailDto() { .dateContestEnd(LocalDate.now().plusDays(10)) .dateCreated(LocalDateTime.now()) .dateUpdated(LocalDateTime.now()) - .thumbnail(new FileDownloadDto("thumbnail.jpg", "thumbnailUrl")) + .thumbnail( + new FileDownloadDto("random", "thumbnail.jpg", "/thumbnailUrl", 10L, "image/jpeg")) .images(new ArrayList<>()) .otherFiles(new ArrayList<>()) .build(); @@ -82,7 +83,8 @@ public void nullTitleTest() { .dateContestEnd(LocalDate.now().plusDays(10)) .dateCreated(LocalDateTime.now()) .dateUpdated(LocalDateTime.now()) - .thumbnail(new FileDownloadDto("thumbnail.jpg", "thumbnailUrl")) + .thumbnail( + new FileDownloadDto("random", "thumbnail.jpg", "/thumbnailUrl", 10L, "image/jpeg")) .images(new ArrayList<>()) .otherFiles(new ArrayList<>()) .build(); diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDtoTest.java index f1bc51bb..227f6fe9 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/ContestBoardDtoTest.java @@ -23,7 +23,8 @@ public void createContestBoardDto() { String association = "테스트 협회"; LocalDate dateContestStart = LocalDate.of(2024, 1, 1); LocalDate dateContestEnd = LocalDate.of(2024, 3, 1); - FileDownloadDto thumbnail = new FileDownloadDto("thumbnail.jpg", "thumbnailUrl"); + FileDownloadDto thumbnail = + new FileDownloadDto("random", "thumbnail.jpg", "/thumbnailUrl", 10L, "image/jpeg"); // when ContestBoardDto contestBoardDto = diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImplTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImplTest.java index 1f22e899..c34643bf 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImplTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImplTest.java @@ -8,12 +8,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.times; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -31,7 +33,7 @@ import com.inhabas.api.domain.contest.repository.ContestBoardRepository; import com.inhabas.api.domain.contest.repository.ContestFieldRepository; import com.inhabas.api.domain.file.dto.FileDownloadDto; -import com.inhabas.api.domain.file.usecase.S3Service; +import com.inhabas.api.domain.file.repository.BoardFileRepository; import com.inhabas.api.domain.member.domain.entity.MemberTest; import com.inhabas.api.domain.menu.domain.Menu; import com.inhabas.api.domain.menu.repository.MenuRepository; @@ -57,7 +59,7 @@ public class ContestBoardServiceImplTest { @Mock private MenuRepository menuRepository; - @Mock private S3Service s3Service; + @Mock private BoardFileRepository boardFileRepository; @DisplayName("Contest board 게시글 목록을 조회한다.") @Transactional(readOnly = true) @@ -73,7 +75,8 @@ void getContestBoards() { .topic("테스트 주제") .dateContestStart(LocalDate.now()) .dateContestEnd(LocalDate.now().plusDays(10)) - .thumbnail(new FileDownloadDto("thumbnail.jpg", "thumbnailUrl")) + .thumbnail( + new FileDownloadDto("random", "thumbnail.jpg", "/thumbnailUrl", 10L, "image/jpeg")) .build(); given( @@ -211,16 +214,22 @@ void updateContestBoard() { ReflectionTestUtils.setField(contestBoard, "id", 1L); + Member writer = MemberTest.chiefMember(); + + given(memberRepository.findById(any())).willReturn(Optional.of(writer)); given(contestFieldRepository.findById(any())).willReturn(Optional.of(contestField)); given(contestBoardRepository.findById(any())).willReturn(Optional.of(contestBoard)); - given(contestBoardRepository.save(any())).willReturn(contestBoard); + given(boardFileRepository.getAllByIdInAndUploader(anyList(), any())) + .willReturn(new ArrayList<>()); // when - contestBoardService.updateContestBoard(contestBoard.getId(), CONTEST, saveContestBoardDto); + contestBoardService.updateContestBoard(contestBoard.getId(), CONTEST, saveContestBoardDto, 1L); // then + then(memberRepository).should(times(1)).findById(any()); then(contestBoardRepository).should(times(1)).findById(any()); - then(contestBoardRepository).should(times(1)).save(any()); + then(contestBoardRepository).should(times(1)).findById(any()); + then(boardFileRepository).should(times(1)).getAllByIdInAndUploader(anyList(), any()); } @DisplayName("Contest board 게시글을 삭제한다.") diff --git a/resource-server/src/test/java/com/inhabas/api/domain/file/domain/BoardFileTest.java b/resource-server/src/test/java/com/inhabas/api/domain/file/domain/BoardFileTest.java index d1d13f5a..bb6d4aeb 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/file/domain/BoardFileTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/file/domain/BoardFileTest.java @@ -2,24 +2,25 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.inhabas.api.domain.board.domain.BaseBoard; -import org.mockito.Mockito; +import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; +import org.mockito.Mock; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; public class BoardFileTest { + @Mock private Member uploader; + @DisplayName("Board 에 첨부되는 File 을 생성한다.") @Test void constructorTest() { // given String name = "fileName"; String url = "fileUrl"; - BaseBoard baseBoard = Mockito.mock(BaseBoard.class); // when - BoardFile boardFile = new BoardFile(name, url, baseBoard); + BoardFile boardFile = new BoardFile("random", name, url, uploader, 10L, "image/jpeg"); // then assertThat(boardFile.getName()).isEqualTo(name); diff --git a/resource-server/src/test/java/com/inhabas/api/domain/file/dto/FileDownloadDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/file/dto/FileDownloadDtoTest.java index 51dc1263..fbe61dbf 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/file/dto/FileDownloadDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/file/dto/FileDownloadDtoTest.java @@ -35,7 +35,13 @@ public static void close() { public void validationTest() { // given FileDownloadDto fileDownloadDto = - FileDownloadDto.builder().name("fileName").url("http://localhost/upload").build(); + FileDownloadDto.builder() + .id("random") + .name("fileName") + .url("http://localhost/upload") + .size(10L) + .type("image/jpeg") + .build(); // when Set> violations = validator.validate(fileDownloadDto); diff --git a/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/domain/NormalBoardTest.java b/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/domain/NormalBoardTest.java index fd404d3a..89a4159f 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/domain/NormalBoardTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/domain/NormalBoardTest.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; import com.inhabas.api.domain.file.domain.BoardFile; import com.inhabas.api.domain.menu.domain.Menu; import org.assertj.core.api.Assertions; @@ -16,6 +17,7 @@ public class NormalBoardTest { @Mock private Menu menu; + @Mock private Member writer; private NormalBoard normalBoard; @@ -57,7 +59,8 @@ public void updateTextTest() { public void updateFilesTest() { // given List files = new ArrayList<>(); - BoardFile file = new BoardFile("fileName", "/hello", normalBoard); + BoardFile file = + new BoardFile("random", "thumbnail.jpg", "/thumbnailUrl", writer, 10L, "image/jpeg"); files.add(file); // when diff --git a/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/dto/SaveNormalBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/dto/SaveNormalBoardDtoTest.java index 10ec963b..91dbc315 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/dto/SaveNormalBoardDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/dto/SaveNormalBoardDtoTest.java @@ -39,8 +39,7 @@ public static void close() { @Test public void SaveNormalBoardDto_is_OK() { // given - SaveNormalBoardDto saveNormalBoardDto = - new SaveNormalBoardDto("title", "content", emptyList, 2); + SaveNormalBoardDto saveNormalBoardDto = new SaveNormalBoardDto("title", "content", null, 2); // when Set> violations = @@ -54,7 +53,7 @@ public void SaveNormalBoardDto_is_OK() { @Test public void Content_is_null() { // given - SaveNormalBoardDto saveNormalBoardDto = new SaveNormalBoardDto("title", null, emptyList, 2); + SaveNormalBoardDto saveNormalBoardDto = new SaveNormalBoardDto("title", null, null, 2); // when Set> violations = diff --git a/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/usecase/NormalBoardServiceImplTest.java b/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/usecase/NormalBoardServiceImplTest.java index 80aed529..a205016c 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/usecase/NormalBoardServiceImplTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/normalBoard/usecase/NormalBoardServiceImplTest.java @@ -6,12 +6,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.times; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -20,7 +22,7 @@ import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository; -import com.inhabas.api.domain.file.usecase.S3Service; +import com.inhabas.api.domain.file.repository.BoardFileRepository; import com.inhabas.api.domain.member.domain.entity.MemberTest; import com.inhabas.api.domain.menu.domain.Menu; import com.inhabas.api.domain.menu.repository.MenuRepository; @@ -45,7 +47,7 @@ public class NormalBoardServiceImplTest { @Mock MemberRepository memberRepository; @Mock NormalBoardRepository normalBoardRepository; @Mock MenuRepository menuRepository; - @Mock S3Service s3Service; + @Mock BoardFileRepository boardFileRepository; @DisplayName("normal board 게시글 목록을 조회한다.") @Transactional(readOnly = true) @@ -125,16 +127,20 @@ void update() { Menu menu = getNormalNoticeMenu(getNormalMenuGroup()); NormalBoard normalBoard = new NormalBoard("title", menu, "content", false, LocalDateTime.now()); ReflectionTestUtils.setField(normalBoard, "id", 1L); + Member writer = MemberTest.chiefMember(); + given(memberRepository.findById(any())).willReturn(Optional.of(writer)); given(normalBoardRepository.findById(any())).willReturn(Optional.of(normalBoard)); - given(normalBoardRepository.save(any())).willReturn(normalBoard); + given(boardFileRepository.getAllByIdInAndUploader(anyList(), any())) + .willReturn(new ArrayList<>()); // when - normalBoardService.update(normalBoard.getId(), NOTICE, saveNormalBoardDto); + normalBoardService.update(normalBoard.getId(), NOTICE, saveNormalBoardDto, 1L); // then + then(memberRepository).should(times(1)).findById(any()); then(normalBoardRepository).should(times(1)).findById(any()); - then(normalBoardRepository).should(times(1)).save(any()); + then(boardFileRepository).should(times(1)).getAllByIdInAndUploader(anyList(), any()); } @DisplayName("normal board 게시글을 삭제한다.") diff --git a/resource-server/src/test/java/com/inhabas/api/domain/project/domain/ProjectBoardTest.java b/resource-server/src/test/java/com/inhabas/api/domain/project/domain/ProjectBoardTest.java index 89a737c6..9c82fd3b 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/project/domain/ProjectBoardTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/project/domain/ProjectBoardTest.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; import com.inhabas.api.domain.file.domain.BoardFile; import com.inhabas.api.domain.menu.domain.Menu; import org.assertj.core.api.Assertions; @@ -16,6 +17,7 @@ public class ProjectBoardTest { @Mock private Menu menu; + @Mock private Member writer; private ProjectBoard projectBoard; @@ -57,7 +59,7 @@ public void updateTextTest() { public void updateFilesTest() { // given List files = new ArrayList<>(); - BoardFile file = new BoardFile("fileName", "/hello", projectBoard); + BoardFile file = new BoardFile("random", "fileName", "/hello", writer, 10L, "image/jpeg"); files.add(file); // when diff --git a/resource-server/src/test/java/com/inhabas/api/domain/project/dto/SaveProjectBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/project/dto/SaveProjectBoardDtoTest.java index a476572e..9be4561b 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/project/dto/SaveProjectBoardDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/project/dto/SaveProjectBoardDtoTest.java @@ -39,8 +39,7 @@ public static void close() { @Test public void SaveProjectBoardDto_is_OK() { // given - SaveProjectBoardDto saveProjectBoardDto = - new SaveProjectBoardDto("title", "content", emptyList, 2); + SaveProjectBoardDto saveProjectBoardDto = new SaveProjectBoardDto("title", "content", null, 2); // when Set> violations = @@ -54,7 +53,7 @@ public void SaveProjectBoardDto_is_OK() { @Test public void Content_is_null() { // given - SaveProjectBoardDto saveProjectBoardDto = new SaveProjectBoardDto("title", null, emptyList, 2); + SaveProjectBoardDto saveProjectBoardDto = new SaveProjectBoardDto("title", null, null, 2); // when Set> violations = diff --git a/resource-server/src/test/java/com/inhabas/api/domain/project/usecase/ProjectBoardServiceImplTest.java b/resource-server/src/test/java/com/inhabas/api/domain/project/usecase/ProjectBoardServiceImplTest.java index 699d8340..34f89ba2 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/project/usecase/ProjectBoardServiceImplTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/project/usecase/ProjectBoardServiceImplTest.java @@ -6,12 +6,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.times; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -20,7 +22,7 @@ import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository; -import com.inhabas.api.domain.file.usecase.S3Service; +import com.inhabas.api.domain.file.repository.BoardFileRepository; import com.inhabas.api.domain.member.domain.entity.MemberTest; import com.inhabas.api.domain.menu.domain.Menu; import com.inhabas.api.domain.menu.repository.MenuRepository; @@ -45,7 +47,7 @@ public class ProjectBoardServiceImplTest { @Mock MemberRepository memberRepository; @Mock ProjectBoardRepository projectBoardRepository; @Mock MenuRepository menuRepository; - @Mock S3Service s3Service; + @Mock BoardFileRepository boardFileRepository; @DisplayName("project board 게시글 목록을 조회한다.") @Transactional(readOnly = true) @@ -127,16 +129,20 @@ void update() { ProjectBoard projectBoard = new ProjectBoard("title", menu, "content", false, LocalDateTime.now()); ReflectionTestUtils.setField(projectBoard, "id", 1L); + Member writer = MemberTest.chiefMember(); + given(memberRepository.findById(any())).willReturn(Optional.of(writer)); given(projectBoardRepository.findById(any())).willReturn(Optional.of(projectBoard)); - given(projectBoardRepository.save(any())).willReturn(projectBoard); + given(boardFileRepository.getAllByIdInAndUploader(anyList(), any())) + .willReturn(new ArrayList<>()); // when - projectBoardService.update(projectBoard.getId(), ALPHA, saveProjectBoardDto); + projectBoardService.update(projectBoard.getId(), ALPHA, saveProjectBoardDto, 1L); // then + then(memberRepository).should(times(1)).findById(any()); then(projectBoardRepository).should(times(1)).findById(any()); - then(projectBoardRepository).should(times(1)).save(any()); + then(boardFileRepository).should(times(1)).getAllByIdInAndUploader(anyList(), any()); } @DisplayName("project board 게시글을 삭제한다.") diff --git a/resource-server/src/test/java/com/inhabas/api/domain/scholarship/dto/SaveScholarshipBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/scholarship/dto/SaveScholarshipBoardDtoTest.java index 0180eede..fcff6642 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/scholarship/dto/SaveScholarshipBoardDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/scholarship/dto/SaveScholarshipBoardDtoTest.java @@ -35,7 +35,7 @@ public static void close() { public void SaveProjectBoardDto_is_OK() { // given SaveScholarshipBoardDto saveScholarshipBoardDto = - new SaveScholarshipBoardDto("title", "content", LocalDateTime.now(), null); + new SaveScholarshipBoardDto("title", "content", LocalDateTime.now().minusDays(1L), null); // when Set> violations = diff --git a/resource-server/src/test/java/com/inhabas/api/domain/scholarship/dto/ScholarshipBoardDetailDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/scholarship/dto/ScholarshipBoardDetailDtoTest.java index d67c67e9..b2db7e47 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/scholarship/dto/ScholarshipBoardDetailDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/scholarship/dto/ScholarshipBoardDetailDtoTest.java @@ -77,6 +77,6 @@ public void Content_is_null() { validator.validate(scholarshipBoardDetailDto); // then - assertThat(violations).hasSize(9); + assertThat(violations).hasSize(8); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/scholarship/repository/ScholarshipHistoryRepositoryTest.java b/resource-server/src/test/java/com/inhabas/api/domain/scholarship/repository/ScholarshipHistoryRepositoryTest.java index 2d31a275..936c3be2 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/scholarship/repository/ScholarshipHistoryRepositoryTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/scholarship/repository/ScholarshipHistoryRepositoryTest.java @@ -28,9 +28,7 @@ public class ScholarshipHistoryRepositoryTest { @Test void getYearlyData() { // given - Member writer = MemberTest.chiefMember(); - ReflectionTestUtils.setField(writer, "id", 1L); - memberRepository.save(writer); + Member writer = memberRepository.save(MemberTest.chiefMember()); ScholarshipHistory scholarshipHistory = new ScholarshipHistory(writer, "title", LocalDateTime.now()); ReflectionTestUtils.setField(scholarshipHistory, "id", 1L); diff --git a/resource-server/src/test/java/com/inhabas/api/web/ContestBoardControllerTest.java b/resource-server/src/test/java/com/inhabas/api/web/ContestBoardControllerTest.java index b3fabd2c..ea93d64b 100644 --- a/resource-server/src/test/java/com/inhabas/api/web/ContestBoardControllerTest.java +++ b/resource-server/src/test/java/com/inhabas/api/web/ContestBoardControllerTest.java @@ -10,6 +10,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.nio.charset.StandardCharsets; @@ -20,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MockMvc; import com.fasterxml.jackson.core.JsonProcessingException; @@ -89,7 +89,8 @@ void getBoardList_Success() throws Exception { .association("테스트 협회") .dateContestStart(LocalDate.of(2024, 1, 1)) .dateContestEnd(LocalDate.of(2024, 3, 1)) - .thumbnail(new FileDownloadDto("thumbnail.jpg", "thumbnailUrl")) + .thumbnail( + new FileDownloadDto("random", "thumbnail.jpg", "/thumbnailUrl", 10L, "image/jpeg")) .build(); List dtoList = List.of(contestBoardDto); given(contestBoardService.getContestBoards(any(), any(), any(), any())).willReturn(dtoList); @@ -145,7 +146,8 @@ void getBoard() throws Exception { .dateContestEnd(LocalDate.of(2024, 3, 1)) .dateCreated(LocalDateTime.now()) .dateUpdated(LocalDateTime.now()) - .thumbnail(new FileDownloadDto("thumbnail.jpg", "thumbnailUrl")) + .thumbnail( + new FileDownloadDto("random", "thumbnail.jpg", "/thumbnailUrl", 10L, "image/jpeg")) .images(null) .otherFiles(null) .build(); @@ -213,20 +215,12 @@ void addBoard() throws Exception { .dateContestEnd(LocalDate.now().plusDays(10)) .build(); - String saveContestBoardDtoJson = objectMapper.writeValueAsString(saveContestBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveContestBoardDtoJson.getBytes()); - - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String header = mvc.perform( multipart("/contest/activity") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveContestBoardDto))) .andExpect(status().isCreated()) .andReturn() .getResponse() @@ -254,19 +248,13 @@ void addBoard_Invalid_Input() throws Exception { .build(); String saveContestBoardDtoJson = objectMapper.writeValueAsString(saveContestBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveContestBoardDtoJson.getBytes()); - - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); // when String response = mvc.perform( - multipart("/contest/contest") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/contest/contest") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveContestBoardDtoJson))) .andExpect(status().isBadRequest()) .andReturn() .getResponse() @@ -281,7 +269,7 @@ void addBoard_Invalid_Input() throws Exception { void updateBoard() throws Exception { // given - doNothing().when(contestBoardService).updateContestBoard(any(), any(), any()); + doNothing().when(contestBoardService).updateContestBoard(any(), any(), any(), any()); SaveContestBoardDto saveContestBoardDto = SaveContestBoardDto.builder() @@ -294,19 +282,11 @@ void updateBoard() throws Exception { .dateContestEnd(LocalDate.now().plusDays(10)) .build(); - String saveContestBoardDtoJson = objectMapper.writeValueAsString(saveContestBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveContestBoardDtoJson.getBytes()); - - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when then mvc.perform( - multipart("/contest/contest/1") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/contest/contest/1") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveContestBoardDto))) .andExpect(status().isNoContent()); } @@ -317,7 +297,7 @@ void updateBoard_Invalid_Input() throws Exception { doThrow(InvalidInputException.class) .when(contestBoardService) - .updateContestBoard(any(), any(), any()); + .updateContestBoard(any(), any(), any(), any()); SaveContestBoardDto saveContestBoardDto = SaveContestBoardDto.builder() @@ -330,19 +310,12 @@ void updateBoard_Invalid_Input() throws Exception { .dateContestEnd(LocalDate.now().plusDays(10)) .build(); - String saveContestBoardDtoJson = objectMapper.writeValueAsString(saveContestBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveContestBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String response = mvc.perform( - multipart("/contest/contest/") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/contest/contest/") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveContestBoardDto))) .andExpect(status().isBadRequest()) .andReturn() .getResponse() @@ -358,7 +331,7 @@ void updateBoard_Not_Found() throws Exception { // given doThrow(NotFoundException.class) .when(contestBoardService) - .updateContestBoard(any(), any(), any()); + .updateContestBoard(any(), any(), any(), any()); SaveContestBoardDto saveContestBoardDto = SaveContestBoardDto.builder() @@ -371,20 +344,12 @@ void updateBoard_Not_Found() throws Exception { .dateContestEnd(LocalDate.now().plusDays(10)) .build(); - String saveContestBoardDtoJson = objectMapper.writeValueAsString(saveContestBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveContestBoardDtoJson.getBytes()); - - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String response = mvc.perform( - multipart("/contest/contest/1") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/contest/contest/1") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveContestBoardDto))) .andExpect(status().isNotFound()) .andReturn() .getResponse() diff --git a/resource-server/src/test/java/com/inhabas/api/web/NormalBoardControllerTest.java b/resource-server/src/test/java/com/inhabas/api/web/NormalBoardControllerTest.java index d17ca304..c1a5fcd0 100644 --- a/resource-server/src/test/java/com/inhabas/api/web/NormalBoardControllerTest.java +++ b/resource-server/src/test/java/com/inhabas/api/web/NormalBoardControllerTest.java @@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MockMvc; import com.fasterxml.jackson.core.JsonProcessingException; @@ -192,19 +191,12 @@ void addBoard() throws Exception { .pinOption(1) .build(); - String saveNormalBoardDtoJson = objectMapper.writeValueAsString(saveNormalBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveNormalBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String header = mvc.perform( - multipart("/board/notice") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/board/notice") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveNormalBoardDto))) .andExpect(status().isCreated()) .andReturn() .getResponse() @@ -222,19 +214,12 @@ void addBoard_Invalid_Input() throws Exception { SaveNormalBoardDto saveNormalBoardDto = SaveNormalBoardDto.builder().title("").content("good content").pinOption(1).build(); - String saveNormalBoardDtoJson = objectMapper.writeValueAsString(saveNormalBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveNormalBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String response = mvc.perform( - multipart("/board/notice") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/board/notice") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveNormalBoardDto))) .andExpect(status().isBadRequest()) .andReturn() .getResponse() @@ -249,7 +234,7 @@ void addBoard_Invalid_Input() throws Exception { void updateBoard() throws Exception { // given - doNothing().when(normalBoardService).update(any(), any(), any()); + doNothing().when(normalBoardService).update(any(), any(), any(), any()); SaveNormalBoardDto saveNormalBoardDto = SaveNormalBoardDto.builder() @@ -258,18 +243,11 @@ void updateBoard() throws Exception { .pinOption(1) .build(); - String saveNormalBoardDtoJson = objectMapper.writeValueAsString(saveNormalBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveNormalBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when then mvc.perform( - multipart("/board/notice/1") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/board/notice/1") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveNormalBoardDto))) .andExpect(status().isNoContent()); } @@ -277,25 +255,19 @@ void updateBoard() throws Exception { @Test void updateBoard_Invalid_Input() throws Exception { // given - - doThrow(InvalidInputException.class).when(normalBoardService).update(any(), any(), any()); + doThrow(InvalidInputException.class) + .when(normalBoardService) + .update(any(), any(), any(), any()); SaveNormalBoardDto saveNormalBoardDto = SaveNormalBoardDto.builder().title("").content("good content").pinOption(1).build(); - String saveNormalBoardDtoJson = objectMapper.writeValueAsString(saveNormalBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveNormalBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String response = mvc.perform( - multipart("/board/notice") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/board/notice") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveNormalBoardDto))) .andExpect(status().isBadRequest()) .andReturn() .getResponse() @@ -309,28 +281,17 @@ void updateBoard_Invalid_Input() throws Exception { @Test void updateBoard_Not_Found() throws Exception { // given - doThrow(NotFoundException.class).when(normalBoardService).update(any(), any(), any()); + doThrow(NotFoundException.class).when(normalBoardService).update(any(), any(), any(), any()); SaveNormalBoardDto saveNormalBoardDto = - SaveNormalBoardDto.builder() - .title("good title") - .content("good content") - .pinOption(1) - .build(); - - String saveNormalBoardDtoJson = objectMapper.writeValueAsString(saveNormalBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveNormalBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); + SaveNormalBoardDto.builder().title("title").content("good content").pinOption(1).build(); // when String response = mvc.perform( - multipart("/board/notice/1") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/board/notice/1") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveNormalBoardDto))) .andExpect(status().isNotFound()) .andReturn() .getResponse() diff --git a/resource-server/src/test/java/com/inhabas/api/web/ProjectBoardControllerTest.java b/resource-server/src/test/java/com/inhabas/api/web/ProjectBoardControllerTest.java index da0448f1..1f67045c 100644 --- a/resource-server/src/test/java/com/inhabas/api/web/ProjectBoardControllerTest.java +++ b/resource-server/src/test/java/com/inhabas/api/web/ProjectBoardControllerTest.java @@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MockMvc; import com.fasterxml.jackson.core.JsonProcessingException; @@ -192,19 +191,12 @@ void addBoard() throws Exception { .pinOption(1) .build(); - String saveProjectBoardDtoJson = objectMapper.writeValueAsString(saveProjectBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveProjectBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String header = mvc.perform( multipart("/project/alpha") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveProjectBoardDto))) .andExpect(status().isCreated()) .andReturn() .getResponse() @@ -218,23 +210,15 @@ void addBoard() throws Exception { @Test void addBoard_Invalid_Input() throws Exception { // given - SaveProjectBoardDto saveProjectBoardDto = SaveProjectBoardDto.builder().title("").content("good content").pinOption(1).build(); - String saveProjectBoardDtoJson = objectMapper.writeValueAsString(saveProjectBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveProjectBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String response = mvc.perform( - multipart("/project/alpha") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + post("/project/alpha") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveProjectBoardDto))) .andExpect(status().isBadRequest()) .andReturn() .getResponse() @@ -248,8 +232,7 @@ void addBoard_Invalid_Input() throws Exception { @Test void updateBoard() throws Exception { // given - - doNothing().when(projectBoardService).update(any(), any(), any()); + doNothing().when(projectBoardService).update(any(), any(), any(), any()); SaveProjectBoardDto saveProjectBoardDto = SaveProjectBoardDto.builder() @@ -258,18 +241,11 @@ void updateBoard() throws Exception { .pinOption(1) .build(); - String saveProjectBoardDtoJson = objectMapper.writeValueAsString(saveProjectBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveProjectBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when then mvc.perform( multipart("/project/alpha/1") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveProjectBoardDto))) .andExpect(status().isNoContent()); } @@ -277,25 +253,19 @@ void updateBoard() throws Exception { @Test void updateBoard_Invalid_Input() throws Exception { // given - - doThrow(InvalidInputException.class).when(projectBoardService).update(any(), any(), any()); + doThrow(InvalidInputException.class) + .when(projectBoardService) + .update(any(), any(), any(), any()); SaveProjectBoardDto saveProjectBoardDto = SaveProjectBoardDto.builder().title("").content("good content").pinOption(1).build(); - String saveProjectBoardDtoJson = objectMapper.writeValueAsString(saveProjectBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveProjectBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String response = mvc.perform( multipart("/project/alpha") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveProjectBoardDto))) .andExpect(status().isBadRequest()) .andReturn() .getResponse() @@ -309,7 +279,7 @@ void updateBoard_Invalid_Input() throws Exception { @Test void updateBoard_Not_Found() throws Exception { // given - doThrow(NotFoundException.class).when(projectBoardService).update(any(), any(), any()); + doThrow(NotFoundException.class).when(projectBoardService).update(any(), any(), any(), any()); SaveProjectBoardDto saveProjectBoardDto = SaveProjectBoardDto.builder() @@ -318,19 +288,12 @@ void updateBoard_Not_Found() throws Exception { .pinOption(1) .build(); - String saveProjectBoardDtoJson = objectMapper.writeValueAsString(saveProjectBoardDto); - MockMultipartFile formPart = - new MockMultipartFile("form", "", "application/json", saveProjectBoardDtoJson.getBytes()); - MockMultipartFile filePart = - new MockMultipartFile("files", "filename.txt", "text/plain", "file content".getBytes()); - // when String response = mvc.perform( multipart("/project/alpha/1") - .file(formPart) - .file(filePart) - .contentType(MediaType.MULTIPART_FORM_DATA)) + .contentType(MediaType.APPLICATION_JSON) + .content(jsonOf(saveProjectBoardDto))) .andExpect(status().isNotFound()) .andReturn() .getResponse()