From ff6818c81d84d831dd9163ec0467f8567891a61c Mon Sep 17 00:00:00 2001 From: ShimFFF Date: Fri, 9 Feb 2024 01:41:31 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A7=80=EB=B6=80=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../branch/service/BranchServiceTest.java | 30 ++++++++----------- .../support/ServiceIntegrationTestConfig.java | 21 +++++++++++++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/test/java/com/umc/networkingService/domain/branch/service/BranchServiceTest.java b/src/test/java/com/umc/networkingService/domain/branch/service/BranchServiceTest.java index 7c01f872..79e671bc 100644 --- a/src/test/java/com/umc/networkingService/domain/branch/service/BranchServiceTest.java +++ b/src/test/java/com/umc/networkingService/domain/branch/service/BranchServiceTest.java @@ -5,10 +5,10 @@ import com.umc.networkingService.domain.branch.dto.response.BranchResponse; import com.umc.networkingService.domain.branch.entity.Branch; import com.umc.networkingService.domain.branch.entity.BranchUniversity; -import com.umc.networkingService.domain.branch.execption.BranchHandler; import com.umc.networkingService.domain.branch.repository.BranchRepository; import com.umc.networkingService.domain.university.entity.University; import com.umc.networkingService.global.common.enums.Semester; +import com.umc.networkingService.global.common.exception.RestApiException; import com.umc.networkingService.global.utils.S3FileComponent; import com.umc.networkingService.support.ServiceIntegrationTestConfig; import org.junit.jupiter.api.DisplayName; @@ -28,7 +28,6 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; @DisplayName("Branch 서비스의 ") @SpringBootTest @@ -50,7 +49,7 @@ class BranchServiceTest extends ServiceIntegrationTestConfig { @Transactional void postBranch_Success() { // given - BranchRequest.PostBranchDTO request = BranchRequest.PostBranchDTO.builder() + BranchRequest.BranchInfoDTO request = BranchRequest.BranchInfoDTO.builder() .name("branchTestPost") .semester(Semester.FIRST) .image(null) @@ -58,17 +57,17 @@ void postBranch_Success() { .build(); // when - UUID id = branchService.postBranch(request); + BranchResponse.BranchId id = branchService.postBranch(request); // then - Optional optionalBranch = branchRepository.findById(id); + Optional optionalBranch = branchRepository.findById(id.getBranchId()); assertTrue(optionalBranch.isPresent()); Branch newBranch=optionalBranch.get(); assertEquals(request.getName(), newBranch.getName()); assertEquals(request.getDescription(), newBranch.getDescription()); - branchRepository.deleteById(id); + branchRepository.deleteById(id.getBranchId()); } @Test @@ -83,8 +82,7 @@ void patchBranch_Success_img() { "이미지 데이터".getBytes() ); - BranchRequest.PatchBranchDTO request =BranchRequest.PatchBranchDTO.builder() - .branchId(branch.getId()) + BranchRequest.BranchInfoDTO request =BranchRequest.BranchInfoDTO.builder() .name("Updated Branch") .description("Updated Description") .image(image) @@ -95,7 +93,7 @@ void patchBranch_Success_img() { given(s3FileComponent.uploadFile(any(), any())).willReturn("s3 url", "s3 url"); // when - branchService.patchBranch(request); + branchService.patchBranch(request, branch.getId()); // then Optional optionalBranch = branchRepository.findById(branch.getId()); @@ -113,8 +111,7 @@ void patchBranch_Success_img() { @Transactional void patchBranch_Success() { // given - BranchRequest.PatchBranchDTO request =BranchRequest.PatchBranchDTO.builder() - .branchId(branch.getId()) + BranchRequest.BranchInfoDTO request =BranchRequest.BranchInfoDTO.builder() .name("Updated Branch") .description("Updated Description") .image(null) @@ -122,7 +119,7 @@ void patchBranch_Success() { .build(); // when - branchService.patchBranch(request); + branchService.patchBranch(request, branch.getId()); // then Optional optionalBranch = branchRepository.findById(branch.getId()); @@ -139,14 +136,13 @@ void patchBranch_Success() { @Transactional void patchBranch_NonExisting_Failure() { // given - BranchRequest.PatchBranchDTO request = BranchRequest.PatchBranchDTO.builder() - .branchId(UUID.randomUUID()) + BranchRequest.BranchInfoDTO request = BranchRequest.BranchInfoDTO.builder() .name("Updated Branch") .image(null) .build(); // when & then - assertThrows(BranchHandler.class, () -> branchService.patchBranch(request)); + assertThrows(RestApiException.class, () -> branchService.patchBranch(request, UUID.randomUUID())); } @@ -236,7 +232,7 @@ void joinBranchDetail_NonExistingBranch_Failure() { UUID nonExistingBranchId = UUID.randomUUID(); // when & then - assertThrows(BranchHandler.class, () -> branchService.joinBranchDetail(nonExistingBranchId)); + assertThrows(RestApiException.class, () -> branchService.joinBranchDetail(nonExistingBranchId)); } @Test @@ -261,7 +257,7 @@ void deleteBranch_NonExisting_Failure() { // when & then - assertThrows(BranchHandler.class, () -> branchService.deleteBranch(nonExistingBranchId)); + assertThrows(RestApiException.class, () -> branchService.deleteBranch(nonExistingBranchId)); } } diff --git a/src/test/java/com/umc/networkingService/support/ServiceIntegrationTestConfig.java b/src/test/java/com/umc/networkingService/support/ServiceIntegrationTestConfig.java index fd6d3a90..4d21e45e 100644 --- a/src/test/java/com/umc/networkingService/support/ServiceIntegrationTestConfig.java +++ b/src/test/java/com/umc/networkingService/support/ServiceIntegrationTestConfig.java @@ -145,4 +145,25 @@ protected BranchUniversity createBranchUniversity() { .build() ); } + + //새로운 브랜치 생성용 + protected Branch createBranch( String name ) { + return branchRepository.save( + Branch.builder() + .name(name) + .semester(Semester.FIFTH) + .build() + ); + } + + //새로운 대학 생성용 + protected University createUniversity( String name ) { + return universityRepository.save( + University.builder() + .name(name) + .totalPoint(0L) + .mascot(mascot) + .build() + ); + } }