-
Notifications
You must be signed in to change notification settings - Fork 1
test: JaCoCo 테스트 설정 점검 및 커버리지 검증 #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dfbb29e
fix : 오류 해결
jaehoon0321 013c160
Merge branch 'develop' into dev/LJH
jaehoon0321 5c5bbac
Merge branch 'develop' into dev/LJH
jaehoon0321 4c4d6ce
feat : Jacoco테스트
jaehoon0321 c6b4c9b
merge: origin/develop 머지 (사용자 변경 사항 우선 적용)
jaehoon0321 ecb3e53
fix : 커버리지 70% 미달성 수정
jaehoon0321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,3 +38,4 @@ out/ | |
|
|
||
| # 환경변수 파일 | ||
| .env | ||
| setup-env.ps1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/test/java/com/sparta/delivhub/DelivhubApplicationTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/com/sparta/delivhub/common/BaseControllerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.sparta.delivhub.common; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
| import com.sparta.delivhub.domain.user.entity.User; | ||
| import com.sparta.delivhub.domain.user.entity.UserRole; | ||
| import com.sparta.delivhub.security.UserDetailsImpl; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
| import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
| import org.springframework.web.context.WebApplicationContext; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; | ||
|
|
||
| @SpringBootTest | ||
| @ActiveProfiles("test") | ||
| @Transactional | ||
| public abstract class BaseControllerTest { | ||
|
|
||
| protected MockMvc mockMvc; | ||
|
|
||
| @Autowired | ||
| protected WebApplicationContext context; | ||
|
|
||
| // 스프링이 못 찾으면 우리가 직접 생성 (안전장치) | ||
| protected ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()); | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
| this.mockMvc = MockMvcBuilders | ||
| .webAppContextSetup(context) | ||
| .apply(springSecurity()) | ||
| .build(); | ||
| } | ||
|
|
||
| protected void mockUserSetup(String username, UserRole role) { | ||
| User user = User.builder() | ||
| .username(username) | ||
| .userRole(role) | ||
| .build(); | ||
|
|
||
| UserDetailsImpl userDetails = new UserDetailsImpl(user); | ||
| UsernamePasswordAuthenticationToken authentication = | ||
| new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); | ||
|
|
||
| SecurityContextHolder.getContext().setAuthentication(authentication); | ||
| } | ||
| } |
100 changes: 100 additions & 0 deletions
100
src/test/java/com/sparta/delivhub/common/util/AuthorizationUtilsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package com.sparta.delivhub.common.util; | ||
|
|
||
| import com.sparta.delivhub.common.dto.BusinessException; | ||
| import com.sparta.delivhub.common.dto.ErrorCode; | ||
| import com.sparta.delivhub.domain.user.entity.User; | ||
| import com.sparta.delivhub.domain.user.entity.UserRole; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.lang.reflect.Constructor; | ||
| import java.lang.reflect.InvocationTargetException; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| class AuthorizationUtilsTest { | ||
|
|
||
| @Test | ||
| @DisplayName("유틸리티 클래스 생성자 호출 시 예외 발생") | ||
| void constructor_Test() throws NoSuchMethodException { | ||
| Constructor<AuthorizationUtils> constructor = AuthorizationUtils.class.getDeclaredConstructor(); | ||
| constructor.setAccessible(true); | ||
| assertThatThrownBy(constructor::newInstance) | ||
| .isInstanceOf(InvocationTargetException.class) | ||
| .hasCauseInstanceOf(IllegalStateException.class); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("OWNER/ADMIN 권한 체크 - CUSTOMER는 거부됨") | ||
| void checkOwnerOrAdminPermission_Customer_Fail() { | ||
| User user = mock(User.class); | ||
| when(user.getUserRole()).thenReturn(UserRole.CUSTOMER); | ||
|
|
||
| assertThatThrownBy(() -> AuthorizationUtils.checkOwnerOrAdminPermission(user, "owner")) | ||
| .isInstanceOf(BusinessException.class) | ||
| .hasMessageContaining(ErrorCode.ACCESS_DENIED.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("OWNER/ADMIN 권한 체크 - 타인 소유 OWNER는 거부됨") | ||
| void checkOwnerOrAdminPermission_OtherOwner_Fail() { | ||
| User user = mock(User.class); | ||
| when(user.getUserRole()).thenReturn(UserRole.OWNER); | ||
| when(user.getUsername()).thenReturn("other"); | ||
|
|
||
| assertThatThrownBy(() -> AuthorizationUtils.checkOwnerOrAdminPermission(user, "owner")) | ||
| .isInstanceOf(BusinessException.class) | ||
| .hasMessageContaining(ErrorCode.NOT_STORE_OWNER.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("OWNER/ADMIN 권한 체크 - 본인 소유 OWNER는 허용") | ||
| void checkOwnerOrAdminPermission_MyOwner_Success() { | ||
| User user = mock(User.class); | ||
| when(user.getUserRole()).thenReturn(UserRole.OWNER); | ||
| when(user.getUsername()).thenReturn("owner"); | ||
|
|
||
| AuthorizationUtils.checkOwnerOrAdminPermission(user, "owner"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("OWNER/ADMIN 권한 체크 - MANAGER/MASTER는 허용") | ||
| void checkOwnerOrAdminPermission_Admin_Success() { | ||
| User manager = mock(User.class); | ||
| when(manager.getUserRole()).thenReturn(UserRole.MANAGER); | ||
| AuthorizationUtils.checkOwnerOrAdminPermission(manager, "any"); | ||
|
|
||
| User master = mock(User.class); | ||
| when(master.getUserRole()).thenReturn(UserRole.MASTER); | ||
| AuthorizationUtils.checkOwnerOrAdminPermission(master, "any"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("ADMIN 권한 체크 - MANAGER/MASTER 성공") | ||
| void checkAdminPermission_Success() { | ||
| User manager = mock(User.class); | ||
| when(manager.getUserRole()).thenReturn(UserRole.MANAGER); | ||
| AuthorizationUtils.checkAdminPermission(manager); | ||
|
|
||
| User master = mock(User.class); | ||
| when(master.getUserRole()).thenReturn(UserRole.MASTER); | ||
| AuthorizationUtils.checkAdminPermission(master); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("ADMIN 권한 체크 - 일반 유저는 실패") | ||
| void checkAdminPermission_Fail() { | ||
| User customer = mock(User.class); | ||
| when(customer.getUserRole()).thenReturn(UserRole.CUSTOMER); | ||
| assertThatThrownBy(() -> AuthorizationUtils.checkAdminPermission(customer)) | ||
| .isInstanceOf(BusinessException.class); | ||
|
|
||
| User owner = mock(User.class); | ||
| when(owner.getUserRole()).thenReturn(UserRole.OWNER); | ||
| assertThatThrownBy(() -> AuthorizationUtils.checkAdminPermission(owner)) | ||
| .isInstanceOf(BusinessException.class); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AiService는 프로젝트의 핵심 기능인 AI 연동 로직을 담당하는 서비스입니다. 테스트 커버리지 검증 대상에서 제외할 경우, 핵심 비즈니스 로직의 테스트 누락을 파악하기 어려워집니다. 해당 제외 설정을 제거하여 커버리지 측정에 포함시키는 것을 권장합니다.