-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 불필요한 주석 삭제 * refactor: 필드 초기화를 생성자가 아닌 필드에서 바로 초기화하도록 수정 * refactor: 연관관계 편의 메소드 삭제 * refactor: OneToMany인 경우 Lazy fetch 옵션 제거(default가 Lazy) * refactor: User Entity 클래스에 AllArgsConstructor 삭제 * test: 테스트 코드 수정
- Loading branch information
Showing
12 changed files
with
84 additions
and
192 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1,15 +1,12 @@ | ||
package org.ahpuh.surf.common.factory; | ||
|
||
import org.ahpuh.surf.user.domain.Permission; | ||
import org.ahpuh.surf.user.domain.User; | ||
import org.ahpuh.surf.user.dto.request.UserJoinRequestDto; | ||
import org.ahpuh.surf.user.dto.request.UserLoginRequestDto; | ||
import org.ahpuh.surf.user.dto.request.UserUpdateRequestDto; | ||
import org.ahpuh.surf.user.dto.response.UserFindInfoResponseDto; | ||
import org.ahpuh.surf.user.dto.response.UserLoginResponseDto; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class MockUserFactory { | ||
|
||
public static User createMockUser() { | ||
|
@@ -36,46 +33,6 @@ public static User createMockUser(final String email, final String password, fin | |
.build(); | ||
} | ||
|
||
public static User createSavedUser() { | ||
return new User(1L, | ||
"mock", | ||
"[email protected]", | ||
"$2a$10$1dmE40BM1RD2lUg.9ss24eGs.4.iNYq1PwXzqKBfIXNRbKCKliqbG", | ||
null, | ||
null, | ||
null, | ||
true, | ||
Permission.ROLE_USER, | ||
new ArrayList<>(), | ||
new ArrayList<>(), | ||
new ArrayList<>(), | ||
new ArrayList<>(), | ||
new ArrayList<>(), | ||
0, | ||
0 | ||
); | ||
} | ||
|
||
public static User createSavedUserWithProfileImage() { | ||
return new User(1L, | ||
"mock", | ||
"[email protected]", | ||
"$2a$10$1dmE40BM1RD2lUg.9ss24eGs.4.iNYq1PwXzqKBfIXNRbKCKliqbG", | ||
"profilePhoto", | ||
null, | ||
null, | ||
true, | ||
Permission.ROLE_USER, | ||
new ArrayList<>(), | ||
new ArrayList<>(), | ||
new ArrayList<>(), | ||
new ArrayList<>(), | ||
new ArrayList<>(), | ||
0, | ||
0 | ||
); | ||
} | ||
|
||
public static UserJoinRequestDto createUserJoinRequestDto() { | ||
return UserJoinRequestDto.builder() | ||
.email("[email protected]") | ||
|
This file contains 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 |
---|---|---|
|
@@ -153,7 +153,9 @@ class UpdateTest { | |
@Test | ||
void updateUserWithProfileImageSuccess() { | ||
// Given | ||
final User user = userRepository.save(createSavedUser()); | ||
final User user = userRepository.save(createMockUser("[email protected]", | ||
"$2a$10$1dmE40BM1RD2lUg.9ss24eGs.4.iNYq1PwXzqKBfIXNRbKCKliqbG", | ||
"mock")); | ||
assertAll("유저 정보 변경전", | ||
() -> assertThat(user.getUserName()).isEqualTo("mock"), | ||
() -> assertThat(passwordEncoder.matches("testpw", user.getPassword())).isTrue(), | ||
|
@@ -184,7 +186,9 @@ void updateUserWithProfileImageSuccess() { | |
@Test | ||
void updateUserWithNoProfileImageSuccess() { | ||
// Given | ||
final User user = userRepository.save(createSavedUser()); | ||
final User user = userRepository.save(createMockUser("[email protected]", | ||
"$2a$10$1dmE40BM1RD2lUg.9ss24eGs.4.iNYq1PwXzqKBfIXNRbKCKliqbG", | ||
"mock")); | ||
assertAll("유저 정보 변경전", | ||
() -> assertThat(user.getUserName()).isEqualTo("mock"), | ||
() -> assertThat(passwordEncoder.matches("testpw", user.getPassword())).isTrue(), | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import org.ahpuh.surf.jwt.JwtAuthentication; | ||
import org.ahpuh.surf.jwt.JwtAuthenticationProvider; | ||
import org.ahpuh.surf.jwt.JwtAuthenticationToken; | ||
import org.ahpuh.surf.user.domain.Permission; | ||
import org.ahpuh.surf.user.domain.User; | ||
import org.ahpuh.surf.user.service.UserService; | ||
import org.junit.jupiter.api.DisplayName; | ||
|
@@ -14,11 +15,11 @@ | |
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.security.core.Authentication; | ||
|
||
import static org.ahpuh.surf.common.factory.MockUserFactory.createSavedUser; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class JwtAuthenticationProviderTest { | ||
|
@@ -36,11 +37,17 @@ public class JwtAuthenticationProviderTest { | |
@Test | ||
void authenticateTest() { | ||
// Given | ||
final User user = createSavedUser(); | ||
final User user = mock(User.class); | ||
given(userService.login("cse0518", "password")) | ||
.willReturn(user); | ||
given(jwt.sign(any())) | ||
.willReturn("token"); | ||
given(user.getPermission()) | ||
.willReturn(Permission.ROLE_USER); | ||
given(user.getUserId()) | ||
.willReturn(1L); | ||
given(user.getEmail()) | ||
.willReturn("[email protected]"); | ||
|
||
// When | ||
final Authentication authentication | ||
|
Oops, something went wrong.