From e59cf9a962c925f36540f5264468ca6509a59264 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Thu, 25 Jan 2024 22:21:48 +0900 Subject: [PATCH 1/9] =?UTF-8?q?NO-JIRA--chore:=20=EB=88=84=EB=9D=BD?= =?UTF-8?q?=EB=90=9C=20rediss=20config=20=EC=BB=A4=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nabimarketbe/redisson/RedissonConfig.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/redisson/RedissonConfig.java diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/redisson/RedissonConfig.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/redisson/RedissonConfig.java new file mode 100644 index 00000000..42622de8 --- /dev/null +++ b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/redisson/RedissonConfig.java @@ -0,0 +1,30 @@ +package org.prgrms.nabimarketbe.redisson; + +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.config.Config; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import lombok.RequiredArgsConstructor; + +@Configuration +@RequiredArgsConstructor +public class RedissonConfig { + @Value("${spring.redis.host}") + private String redisHost; + + @Value("${spring.redis.port}") + private int redisPort; + + private static final String REDISSON_HOST_PREFIX = "redis://"; + + @Bean + public RedissonClient redissonClient() { + Config config = new Config(); + config.useSingleServer().setAddress(REDISSON_HOST_PREFIX + redisHost + ":" + redisPort); + + return Redisson.create(config); + } +} From cf53083a14cd2bc915de60f39c6b697b8c3f22f8 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Thu, 25 Jan 2024 22:29:14 +0900 Subject: [PATCH 2/9] =?UTF-8?q?NO-JIRA--chore=20:=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=ED=95=B4=EB=91=90=EC=97=88=EB=8D=98=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=ED=8C=8C=EC=9D=BC=20=EC=98=AE?= =?UTF-8?q?=EA=B9=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/card/CardViewServiceTest.java | 89 ++++++++++++++++ .../setup/jwt/TokenResponseDTOBuilder.java | 14 +++ .../src/test/java/setup/user/UserBuilder.java | 16 +++ .../request/SocialUserInfoDTOBuilder.java | 12 +++ .../UserNicknameUpdateRequestDTOBuilder.java | 9 ++ .../UserProfileUpdateRequestDTOBuilder.java | 9 ++ .../user/RandomNicknameGeneratorTest.java | 46 ++++++++ .../src/test/java/user/SignServiceTest.java | 59 +++++++++++ .../src/test/java/user/UserServiceTest.java | 100 ++++++++++++++++++ .../card/service/CardViewServiceTest.java | 88 --------------- .../service/RandomNicknameGeneratorTest.java | 45 -------- .../domain/user/service/SignServiceTest.java | 57 ---------- .../domain/user/service/UserServiceTest.java | 97 ----------------- .../setup/jwt/TokenResponseDTOBuilder.java | 14 --- .../request/SocialUserInfoDTOBuilder.java | 12 --- .../nabimarketbe/setup/user/UserBuilder.java | 16 --- .../UserNicknameUpdateRequestDTOBuilder.java | 9 -- .../UserProfileUpdateRequestDTOBuilder.java | 9 -- src/test/resources/application.yml | 3 - 19 files changed, 354 insertions(+), 350 deletions(-) create mode 100644 nabimarket-application/src/test/java/card/CardViewServiceTest.java create mode 100644 nabimarket-application/src/test/java/setup/jwt/TokenResponseDTOBuilder.java create mode 100644 nabimarket-application/src/test/java/setup/user/UserBuilder.java create mode 100644 nabimarket-application/src/test/java/setup/user/request/SocialUserInfoDTOBuilder.java create mode 100644 nabimarket-application/src/test/java/setup/user/request/UserNicknameUpdateRequestDTOBuilder.java create mode 100644 nabimarket-application/src/test/java/setup/user/request/UserProfileUpdateRequestDTOBuilder.java create mode 100644 nabimarket-application/src/test/java/user/RandomNicknameGeneratorTest.java create mode 100644 nabimarket-application/src/test/java/user/SignServiceTest.java create mode 100644 nabimarket-application/src/test/java/user/UserServiceTest.java delete mode 100644 src/test/java/org/prgrms/nabimarketbe/domain/card/service/CardViewServiceTest.java delete mode 100644 src/test/java/org/prgrms/nabimarketbe/domain/user/service/RandomNicknameGeneratorTest.java delete mode 100644 src/test/java/org/prgrms/nabimarketbe/domain/user/service/SignServiceTest.java delete mode 100644 src/test/java/org/prgrms/nabimarketbe/domain/user/service/UserServiceTest.java delete mode 100644 src/test/java/org/prgrms/nabimarketbe/setup/jwt/TokenResponseDTOBuilder.java delete mode 100644 src/test/java/org/prgrms/nabimarketbe/setup/oauth2/request/SocialUserInfoDTOBuilder.java delete mode 100644 src/test/java/org/prgrms/nabimarketbe/setup/user/UserBuilder.java delete mode 100644 src/test/java/org/prgrms/nabimarketbe/setup/user/request/UserNicknameUpdateRequestDTOBuilder.java delete mode 100644 src/test/java/org/prgrms/nabimarketbe/setup/user/request/UserProfileUpdateRequestDTOBuilder.java delete mode 100644 src/test/resources/application.yml diff --git a/nabimarket-application/src/test/java/card/CardViewServiceTest.java b/nabimarket-application/src/test/java/card/CardViewServiceTest.java new file mode 100644 index 00000000..72f4a22c --- /dev/null +++ b/nabimarket-application/src/test/java/card/CardViewServiceTest.java @@ -0,0 +1,89 @@ +package card; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.prgrms.nabimarketbe.card.service.CardViewCountService; +import org.prgrms.nabimarketbe.redisson.RedisDAO; +import org.prgrms.nabimarketbe.util.KeyGenerator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +@SpringBootTest +public class CardViewServiceTest { + @Autowired + private ThreadPoolTaskExecutor taskExecutor; + + @Autowired + private RedisDAO redisDAO; + + @Autowired + private CardViewCountService cardViewCountService; + + private List userIdList = new ArrayList<>(); + + private Long cardId; + + private String cardViewCacheKey; + + @BeforeEach + void setKeys() { + cardId = 1L; + + for (Long i = 1L; i <= 10L; i++) { + userIdList.add(i); + } + cardViewCacheKey = KeyGenerator.generateCardViewCacheKey(cardId); + } + + @AfterEach + void deleteValues() { + redisDAO.deleteValues(cardViewCacheKey); + + for (Long i = 1L; i <= 10; i++) { + redisDAO.deleteValues(KeyGenerator.generateCardReaderCacheKey(i)); + } + } + + @Test + @DisplayName("10명의 다른 사용자가 같은 카드에 대해 단건 조회를 요청 했을 경우 조회수 증가") + void increaseViewCountTest() throws InterruptedException { + // given + Integer expectedViewCountCacheValue = 10; + + int numberOfThreads = 10; + ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads); + CountDownLatch latch = new CountDownLatch(numberOfThreads); + + // when + for (int i = 0; i < numberOfThreads; i++) { + int index = i; + + executorService.submit(() -> { + try { + cardViewCountService.increaseViewCount(userIdList.get(index), cardId); + } finally { + latch.countDown(); + } + }); + } + + latch.await(); + + taskExecutor.getThreadPoolExecutor().awaitTermination(1, TimeUnit.SECONDS); + + // then + assertThat(redisDAO.getValue(cardViewCacheKey)).isEqualTo(expectedViewCountCacheValue.toString()); + } +} diff --git a/nabimarket-application/src/test/java/setup/jwt/TokenResponseDTOBuilder.java b/nabimarket-application/src/test/java/setup/jwt/TokenResponseDTOBuilder.java new file mode 100644 index 00000000..f45430f5 --- /dev/null +++ b/nabimarket-application/src/test/java/setup/jwt/TokenResponseDTOBuilder.java @@ -0,0 +1,14 @@ +package setup.jwt; + +import org.prgrms.nabimarketbe.jwt.dto.TokenResponseDTO; + +public class TokenResponseDTOBuilder { + public static TokenResponseDTO createTestDTO() { + return TokenResponseDTO.builder() + .grantType("Bearer") + .accessToken("testAccessToken") + .refreshToken("testRefreshToken") + .accessTokenExpireDate(60 * 60 * 1000L) + .build(); + } +} diff --git a/nabimarket-application/src/test/java/setup/user/UserBuilder.java b/nabimarket-application/src/test/java/setup/user/UserBuilder.java new file mode 100644 index 00000000..4d38caad --- /dev/null +++ b/nabimarket-application/src/test/java/setup/user/UserBuilder.java @@ -0,0 +1,16 @@ +package setup.user; + +import org.prgrms.nabimarketbe.user.entity.Role; +import org.prgrms.nabimarketbe.user.entity.User; + +public class UserBuilder { + public static User createTestEntity() { + return User.builder() + .accountId("testAccountId") + .nickname("testNickname") + .role(Role.USER.getKey()) + .imageUrl("testImageUrl") + .provider("KAKAO") + .build(); + } +} diff --git a/nabimarket-application/src/test/java/setup/user/request/SocialUserInfoDTOBuilder.java b/nabimarket-application/src/test/java/setup/user/request/SocialUserInfoDTOBuilder.java new file mode 100644 index 00000000..1f22a4c1 --- /dev/null +++ b/nabimarket-application/src/test/java/setup/user/request/SocialUserInfoDTOBuilder.java @@ -0,0 +1,12 @@ +package setup.user.request; + +import org.prgrms.nabimarketbe.user.dto.request.SocialUserInfoDTO; + +public class SocialUserInfoDTOBuilder { + public static SocialUserInfoDTO createTestDTO() { + return SocialUserInfoDTO.builder() + .accountId("testAccount") + .provider("KAKAO") + .build(); + } +} diff --git a/nabimarket-application/src/test/java/setup/user/request/UserNicknameUpdateRequestDTOBuilder.java b/nabimarket-application/src/test/java/setup/user/request/UserNicknameUpdateRequestDTOBuilder.java new file mode 100644 index 00000000..dee8620c --- /dev/null +++ b/nabimarket-application/src/test/java/setup/user/request/UserNicknameUpdateRequestDTOBuilder.java @@ -0,0 +1,9 @@ +package setup.user.request; + +import org.prgrms.nabimarketbe.user.dto.request.UserNicknameUpdateRequestDTO; + +public class UserNicknameUpdateRequestDTOBuilder { + public static UserNicknameUpdateRequestDTO createTestDTO() { + return new UserNicknameUpdateRequestDTO("testUpdateNickname"); + } +} diff --git a/nabimarket-application/src/test/java/setup/user/request/UserProfileUpdateRequestDTOBuilder.java b/nabimarket-application/src/test/java/setup/user/request/UserProfileUpdateRequestDTOBuilder.java new file mode 100644 index 00000000..1eccae1c --- /dev/null +++ b/nabimarket-application/src/test/java/setup/user/request/UserProfileUpdateRequestDTOBuilder.java @@ -0,0 +1,9 @@ +package setup.user.request; + +import org.prgrms.nabimarketbe.user.dto.request.UserProfileUpdateRequestDTO; + +public class UserProfileUpdateRequestDTOBuilder { + public static UserProfileUpdateRequestDTO createTestDTO() { + return new UserProfileUpdateRequestDTO("testImageUrl"); + } +} diff --git a/nabimarket-application/src/test/java/user/RandomNicknameGeneratorTest.java b/nabimarket-application/src/test/java/user/RandomNicknameGeneratorTest.java new file mode 100644 index 00000000..0ba980aa --- /dev/null +++ b/nabimarket-application/src/test/java/user/RandomNicknameGeneratorTest.java @@ -0,0 +1,46 @@ +package user; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.prgrms.nabimarketbe.user.service.RandomNicknameGenerator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.retry.annotation.EnableRetry; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.web.client.RestTemplate; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@ExtendWith(SpringExtension.class) +@Import({RandomNicknameGenerator.class, ObjectMapper.class}) +@EnableRetry +class RandomNicknameGeneratorTest { + @Autowired + RandomNicknameGenerator randomNicknameGenerator; + + @MockBean + RestTemplate restTemplate; + + @DisplayName("랜덤닉네임 생성 시에 RuntimeException 발생시 2번까지 재시도한다.") + @Test + void testGenerateRandomNicknameWithRetry() { + // given + doThrow(new RuntimeException("Intended Retry Error")).when(restTemplate) + .getForObject(anyString(), eq(String.class)); + + // then + assertThrows(RuntimeException.class, () -> { + randomNicknameGenerator.generateRandomNickname(); + }); + verify(restTemplate, times(2)).getForObject(anyString(), eq(String.class)); + } +} diff --git a/nabimarket-application/src/test/java/user/SignServiceTest.java b/nabimarket-application/src/test/java/user/SignServiceTest.java new file mode 100644 index 00000000..51748621 --- /dev/null +++ b/nabimarket-application/src/test/java/user/SignServiceTest.java @@ -0,0 +1,59 @@ +package user; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; + +import java.util.Optional; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.prgrms.nabimarketbe.jwt.dto.TokenResponseDTO; +import org.prgrms.nabimarketbe.jwt.provider.JwtProvider; +import org.prgrms.nabimarketbe.user.dto.request.SocialUserInfoDTO; +import org.prgrms.nabimarketbe.user.dto.response.UserGetResponseDTO; +import org.prgrms.nabimarketbe.user.dto.response.UserLoginResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.user.repository.UserRepository; +import org.prgrms.nabimarketbe.user.service.SignService; + +import setup.jwt.TokenResponseDTOBuilder; +import setup.user.UserBuilder; +import setup.user.request.SocialUserInfoDTOBuilder; + +@ExtendWith(MockitoExtension.class) +class SignServiceTest { + @InjectMocks + SignService signService; + + @Mock + UserRepository userRepository; + + @Mock + JwtProvider jwtProvider; + + @DisplayName("사용자는 소셜로그인 이후 받아온 정보로 나비장터에 로그인을 할 수 있다.") + @Test + void UserSignInTest() { + // given + SocialUserInfoDTO socialUserInfoDTO = SocialUserInfoDTOBuilder.createTestDTO(); + User user = UserBuilder.createTestEntity(); + TokenResponseDTO tokenResponseDTO = TokenResponseDTOBuilder.createTestDTO(); + UserGetResponseDTO userGetResponseDTO = UserGetResponseDTO.from(user); + + given(userRepository.findByAccountId(any())).willReturn(Optional.ofNullable(user)); + given(jwtProvider.createTokenDTO(any(), anyString())).willReturn(tokenResponseDTO); + + // when + UserLoginResponseDTO loginResponseDTO = signService.signIn(socialUserInfoDTO); + + // then + assertThat(loginResponseDTO.userInfo()).usingRecursiveComparison().isEqualTo(userGetResponseDTO); + assertThat(loginResponseDTO.token()).usingRecursiveComparison().isEqualTo(tokenResponseDTO); + } +} diff --git a/nabimarket-application/src/test/java/user/UserServiceTest.java b/nabimarket-application/src/test/java/user/UserServiceTest.java new file mode 100644 index 00000000..8d7f0900 --- /dev/null +++ b/nabimarket-application/src/test/java/user/UserServiceTest.java @@ -0,0 +1,100 @@ +package org.prgrms.nabimarketbe.domain.user.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willDoNothing; + +import java.util.Optional; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.prgrms.nabimarketbe.aws.service.S3FileUploadService; +import org.prgrms.nabimarketbe.user.dto.request.UserNicknameUpdateRequestDTO; +import org.prgrms.nabimarketbe.user.dto.request.UserProfileUpdateRequestDTO; +import org.prgrms.nabimarketbe.user.dto.response.UserGetResponseDTO; +import org.prgrms.nabimarketbe.user.dto.response.UserResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.user.repository.UserRepository; +import org.prgrms.nabimarketbe.user.service.CheckService; +import org.prgrms.nabimarketbe.user.service.UserService; + +import setup.user.UserBuilder; +import setup.user.request.UserNicknameUpdateRequestDTOBuilder; +import setup.user.request.UserProfileUpdateRequestDTOBuilder; + +@ExtendWith(MockitoExtension.class) +class UserServiceTest { + @InjectMocks + UserService userService; + + @Mock + UserRepository userRepository; + + @Mock + S3FileUploadService s3FileUploadService; + + @Mock + CheckService checkService; + + static final String TEST_TOKEN = "testToken"; + + @DisplayName("유저를 토큰으로 조회할 수 있다.") + @Test + void GetUserByTokenTest() { + // given + User user = UserBuilder.createTestEntity(); + UserResponseDTO expectedResponseDTO = new UserResponseDTO<>(UserGetResponseDTO.from(user)); + + given(checkService.parseToken(TEST_TOKEN)).willReturn(1L); + given(userRepository.findById(anyLong())).willReturn(Optional.ofNullable(user)); + + // when + UserResponseDTO actualResponseDTO = userService.getUserByToken(TEST_TOKEN); + + // then + assertThat(actualResponseDTO.userInfo()).usingRecursiveComparison() + .ignoringFields("userId", "imageUrl") + .isEqualTo(expectedResponseDTO.userInfo()); + } + + @DisplayName("유저 이미지를 업데이트 할 수 있다.") + @Test + void UpdateUserImageTest() { + // given + UserProfileUpdateRequestDTO requestDTO = UserProfileUpdateRequestDTOBuilder.createTestDTO(); + User user = UserBuilder.createTestEntity(); + + given(checkService.parseToken(TEST_TOKEN)).willReturn(1L); + given(userRepository.findById(anyLong())).willReturn(Optional.ofNullable(user)); + willDoNothing().given(s3FileUploadService).deleteImage(anyString()); + + // when + userService.updateUserImageUrl(TEST_TOKEN, requestDTO); + + // then + assertThat(user.getImageUrl()).isEqualTo(requestDTO.imageUrl()); + } + + @DisplayName("유저 닉네임을 업데이트 할 수 있다.") + @Test + void UpdateUserNicknameTest() { + // given + UserNicknameUpdateRequestDTO requestDTO = UserNicknameUpdateRequestDTOBuilder.createTestDTO(); + User user = UserBuilder.createTestEntity(); + + given(checkService.parseToken(TEST_TOKEN)).willReturn(1L); + given(userRepository.findById(anyLong())).willReturn(Optional.ofNullable(user)); + + // when + userService.updateUserNickname(TEST_TOKEN, requestDTO); + + // then + assertThat(user.getNickname()).isEqualTo(requestDTO.nickname()); + } +} diff --git a/src/test/java/org/prgrms/nabimarketbe/domain/card/service/CardViewServiceTest.java b/src/test/java/org/prgrms/nabimarketbe/domain/card/service/CardViewServiceTest.java deleted file mode 100644 index 7d4b63ba..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/domain/card/service/CardViewServiceTest.java +++ /dev/null @@ -1,88 +0,0 @@ -// package org.prgrms.nabimarketbe.domain.card.service; -// -// import org.junit.jupiter.api.AfterEach; -// import org.junit.jupiter.api.BeforeEach; -// import org.junit.jupiter.api.DisplayName; -// import org.junit.jupiter.api.Test; -// import org.prgrms.nabimarketbe.global.redisson.RedisDAO; -// import org.prgrms.nabimarketbe.global.util.KeyGenerator; -// import org.springframework.beans.factory.annotation.Autowired; -// import org.springframework.boot.test.context.SpringBootTest; -// import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -// -// import java.util.ArrayList; -// import java.util.List; -// import java.util.concurrent.CountDownLatch; -// import java.util.concurrent.ExecutorService; -// import java.util.concurrent.Executors; -// import java.util.concurrent.TimeUnit; -// -// import static org.assertj.core.api.Assertions.assertThat; -// -// @SpringBootTest -// public class CardViewServiceTest { -// @Autowired -// private ThreadPoolTaskExecutor taskExecutor; -// -// @Autowired -// private RedisDAO redisDAO; -// -// @Autowired -// private CardViewCountService cardViewCountService; -// -// private List userIdList = new ArrayList<>(); -// -// private Long cardId; -// -// private String cardViewCacheKey; -// -// @BeforeEach -// void setKeys() { -// cardId = 1L; -// -// for (Long i = 1L; i <= 10L; i++) { -// userIdList.add(i); -// } -// cardViewCacheKey = KeyGenerator.generateCardViewCacheKey(cardId); -// } -// -// @AfterEach -// void deleteValues() { -// redisDAO.deleteValues(cardViewCacheKey); -// -// for (Long i = 1L; i <= 10; i++) { -// redisDAO.deleteValues(KeyGenerator.generateCardReaderCacheKey(i)); -// } -// } -// -// @Test -// @DisplayName("10명의 다른 사용자가 같은 카드에 대해 단건 조회를 요청 했을 경우 조회수 증가") -// void increaseViewCountTest() throws InterruptedException { -// // given -// Integer expectedViewCountCacheValue = 10; -// -// int numberOfThreads = 10; -// ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads); -// CountDownLatch latch = new CountDownLatch(numberOfThreads); -// -// // when -// for (int i = 0; i < numberOfThreads; i++) { -// int index = i; -// -// executorService.submit(() -> { -// try { -// cardViewCountService.increaseViewCount(userIdList.get(index), cardId); -// } finally { -// latch.countDown(); -// } -// }); -// } -// -// latch.await(); -// -// taskExecutor.getThreadPoolExecutor().awaitTermination(1, TimeUnit.SECONDS); -// -// // then -// assertThat(redisDAO.getValue(cardViewCacheKey)).isEqualTo(expectedViewCountCacheValue.toString()); -// } -// } diff --git a/src/test/java/org/prgrms/nabimarketbe/domain/user/service/RandomNicknameGeneratorTest.java b/src/test/java/org/prgrms/nabimarketbe/domain/user/service/RandomNicknameGeneratorTest.java deleted file mode 100644 index 85f9492b..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/domain/user/service/RandomNicknameGeneratorTest.java +++ /dev/null @@ -1,45 +0,0 @@ -// package org.prgrms.nabimarketbe.domain.user.service; -// -// import static org.junit.jupiter.api.Assertions.assertThrows; -// import static org.mockito.ArgumentMatchers.anyString; -// import static org.mockito.ArgumentMatchers.eq; -// import static org.mockito.Mockito.doThrow; -// import static org.mockito.Mockito.times; -// import static org.mockito.Mockito.verify; -// -// import org.junit.jupiter.api.DisplayName; -// import org.junit.jupiter.api.Test; -// import org.junit.jupiter.api.extension.ExtendWith; -// import org.springframework.beans.factory.annotation.Autowired; -// import org.springframework.boot.test.mock.mockito.MockBean; -// import org.springframework.context.annotation.Import; -// import org.springframework.retry.annotation.EnableRetry; -// import org.springframework.test.context.junit.jupiter.SpringExtension; -// import org.springframework.web.client.RestTemplate; -// -// import com.fasterxml.jackson.databind.ObjectMapper; -// -// @ExtendWith(SpringExtension.class) -// @Import({RandomNicknameGenerator.class, ObjectMapper.class}) -// @EnableRetry -// class RandomNicknameGeneratorTest { -// @Autowired -// RandomNicknameGenerator randomNicknameGenerator; -// -// @MockBean -// RestTemplate restTemplate; -// -// @DisplayName("랜덤닉네임 생성 시에 RuntimeException 발생시 2번까지 재시도한다.") -// @Test -// void testGenerateRandomNicknameWithRetry() { -// // given -// doThrow(new RuntimeException("Intended Retry Error")).when(restTemplate) -// .getForObject(anyString(), eq(String.class)); -// -// // then -// assertThrows(RuntimeException.class, () -> { -// randomNicknameGenerator.generateRandomNickname(); -// }); -// verify(restTemplate, times(2)).getForObject(anyString(), eq(String.class)); -// } -// } diff --git a/src/test/java/org/prgrms/nabimarketbe/domain/user/service/SignServiceTest.java b/src/test/java/org/prgrms/nabimarketbe/domain/user/service/SignServiceTest.java deleted file mode 100644 index 1f702285..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/domain/user/service/SignServiceTest.java +++ /dev/null @@ -1,57 +0,0 @@ -// package org.prgrms.nabimarketbe.domain.user.service; -// -// import static org.assertj.core.api.Assertions.assertThat; -// import static org.mockito.ArgumentMatchers.any; -// import static org.mockito.ArgumentMatchers.anyString; -// import static org.mockito.BDDMockito.given; -// -// import java.util.Optional; -// -// import org.junit.jupiter.api.DisplayName; -// import org.junit.jupiter.api.Test; -// import org.junit.jupiter.api.extension.ExtendWith; -// import org.mockito.InjectMocks; -// import org.mockito.Mock; -// import org.mockito.junit.jupiter.MockitoExtension; -// import org.prgrms.nabimarketbe.domain.user.dto.request.SocialUserInfoDTO; -// import org.prgrms.nabimarketbe.domain.user.dto.response.UserGetResponseDTO; -// import org.prgrms.nabimarketbe.domain.user.dto.response.UserLoginResponseDTO; -// import org.prgrms.nabimarketbe.domain.user.entity.User; -// import org.prgrms.nabimarketbe.domain.user.repository.UserRepository; -// import org.prgrms.nabimarketbe.global.security.jwt.dto.TokenResponseDTO; -// import org.prgrms.nabimarketbe.global.security.jwt.provider.JwtProvider; -// import org.prgrms.nabimarketbe.setup.jwt.TokenResponseDTOBuilder; -// import org.prgrms.nabimarketbe.setup.oauth2.request.SocialUserInfoDTOBuilder; -// import org.prgrms.nabimarketbe.setup.user.UserBuilder; -// -// @ExtendWith(MockitoExtension.class) -// class SignServiceTest { -// @InjectMocks -// SignService signService; -// -// @Mock -// UserRepository userRepository; -// -// @Mock -// JwtProvider jwtProvider; -// -// @DisplayName("사용자는 소셜로그인 이후 받아온 정보로 나비장터에 로그인을 할 수 있다.") -// @Test -// void UserSignInTest() { -// // given -// SocialUserInfoDTO socialUserInfoDTO = SocialUserInfoDTOBuilder.createTestDTO(); -// User user = UserBuilder.createTestEntity(); -// TokenResponseDTO tokenResponseDTO = TokenResponseDTOBuilder.createTestDTO(); -// UserGetResponseDTO userGetResponseDTO = UserGetResponseDTO.from(user); -// -// given(userRepository.findByAccountId(any())).willReturn(Optional.ofNullable(user)); -// given(jwtProvider.createTokenDTO(any(), anyString())).willReturn(tokenResponseDTO); -// -// // when -// UserLoginResponseDTO loginResponseDTO = signService.signIn(socialUserInfoDTO); -// -// // then -// assertThat(loginResponseDTO.userInfo()).usingRecursiveComparison().isEqualTo(userGetResponseDTO); -// assertThat(loginResponseDTO.token()).usingRecursiveComparison().isEqualTo(tokenResponseDTO); -// } -// } diff --git a/src/test/java/org/prgrms/nabimarketbe/domain/user/service/UserServiceTest.java b/src/test/java/org/prgrms/nabimarketbe/domain/user/service/UserServiceTest.java deleted file mode 100644 index 426ef36b..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/domain/user/service/UserServiceTest.java +++ /dev/null @@ -1,97 +0,0 @@ -// package org.prgrms.nabimarketbe.domain.user.service; -// -// import static org.assertj.core.api.Assertions.assertThat; -// import static org.mockito.ArgumentMatchers.anyLong; -// import static org.mockito.ArgumentMatchers.anyString; -// import static org.mockito.BDDMockito.given; -// import static org.mockito.BDDMockito.willDoNothing; -// -// import java.util.Optional; -// -// import org.junit.jupiter.api.DisplayName; -// import org.junit.jupiter.api.Test; -// import org.junit.jupiter.api.extension.ExtendWith; -// import org.mockito.InjectMocks; -// import org.mockito.Mock; -// import org.mockito.junit.jupiter.MockitoExtension; -// import org.prgrms.nabimarketbe.domain.user.dto.request.UserNicknameUpdateRequestDTO; -// import org.prgrms.nabimarketbe.domain.user.dto.request.UserProfileUpdateRequestDTO; -// import org.prgrms.nabimarketbe.domain.user.dto.response.UserGetResponseDTO; -// import org.prgrms.nabimarketbe.domain.user.dto.response.UserResponseDTO; -// import org.prgrms.nabimarketbe.domain.user.entity.User; -// import org.prgrms.nabimarketbe.domain.user.repository.UserRepository; -// import org.prgrms.nabimarketbe.global.aws.service.S3FileUploadService; -// import org.prgrms.nabimarketbe.setup.user.UserBuilder; -// import org.prgrms.nabimarketbe.setup.user.request.UserNicknameUpdateRequestDTOBuilder; -// import org.prgrms.nabimarketbe.setup.user.request.UserProfileUpdateRequestDTOBuilder; -// -// @ExtendWith(MockitoExtension.class) -// class UserServiceTest { -// @InjectMocks -// UserService userService; -// -// @Mock -// UserRepository userRepository; -// -// @Mock -// S3FileUploadService s3FileUploadService; -// -// @Mock -// CheckService checkService; -// -// static final String TEST_TOKEN = "testToken"; -// -// @DisplayName("유저를 토큰으로 조회할 수 있다.") -// @Test -// void GetUserByTokenTest() { -// // given -// User user = UserBuilder.createTestEntity(); -// UserResponseDTO expectedResponseDTO = new UserResponseDTO<>(UserGetResponseDTO.from(user)); -// -// given(checkService.parseToken(TEST_TOKEN)).willReturn(1L); -// given(userRepository.findById(anyLong())).willReturn(Optional.ofNullable(user)); -// -// // when -// UserResponseDTO actualResponseDTO = userService.getUserByToken(TEST_TOKEN); -// -// // then -// assertThat(actualResponseDTO.userInfo()).usingRecursiveComparison() -// .ignoringFields("userId", "imageUrl") -// .isEqualTo(expectedResponseDTO.userInfo()); -// } -// -// @DisplayName("유저 이미지를 업데이트 할 수 있다.") -// @Test -// void UpdateUserImageTest() { -// // given -// UserProfileUpdateRequestDTO requestDTO = UserProfileUpdateRequestDTOBuilder.createTestDTO(); -// User user = UserBuilder.createTestEntity(); -// -// given(checkService.parseToken(TEST_TOKEN)).willReturn(1L); -// given(userRepository.findById(anyLong())).willReturn(Optional.ofNullable(user)); -// willDoNothing().given(s3FileUploadService).deleteImage(anyString()); -// -// // when -// userService.updateUserImageUrl(TEST_TOKEN, requestDTO); -// -// // then -// assertThat(user.getImageUrl()).isEqualTo(requestDTO.imageUrl()); -// } -// -// @DisplayName("유저 닉네임을 업데이트 할 수 있다.") -// @Test -// void UpdateUserNicknameTest() { -// // given -// UserNicknameUpdateRequestDTO requestDTO = UserNicknameUpdateRequestDTOBuilder.createTestDTO(); -// User user = UserBuilder.createTestEntity(); -// -// given(checkService.parseToken(TEST_TOKEN)).willReturn(1L); -// given(userRepository.findById(anyLong())).willReturn(Optional.ofNullable(user)); -// -// // when -// userService.updateUserNickname(TEST_TOKEN, requestDTO); -// -// // then -// assertThat(user.getNickname()).isEqualTo(requestDTO.nickname()); -// } -// } diff --git a/src/test/java/org/prgrms/nabimarketbe/setup/jwt/TokenResponseDTOBuilder.java b/src/test/java/org/prgrms/nabimarketbe/setup/jwt/TokenResponseDTOBuilder.java deleted file mode 100644 index 9b8d60b9..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/setup/jwt/TokenResponseDTOBuilder.java +++ /dev/null @@ -1,14 +0,0 @@ -// package org.prgrms.nabimarketbe.setup.jwt; -// -// import org.prgrms.nabimarketbe.global.security.jwt.dto.TokenResponseDTO; -// -// public class TokenResponseDTOBuilder { -// public static TokenResponseDTO createTestDTO() { -// return TokenResponseDTO.builder() -// .grantType("Bearer") -// .accessToken("testAccessToken") -// .refreshToken("testRefreshToken") -// .accessTokenExpireDate(60 * 60 * 1000L) -// .build(); -// } -// } diff --git a/src/test/java/org/prgrms/nabimarketbe/setup/oauth2/request/SocialUserInfoDTOBuilder.java b/src/test/java/org/prgrms/nabimarketbe/setup/oauth2/request/SocialUserInfoDTOBuilder.java deleted file mode 100644 index 8c88ad4c..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/setup/oauth2/request/SocialUserInfoDTOBuilder.java +++ /dev/null @@ -1,12 +0,0 @@ -// package org.prgrms.nabimarketbe.setup.oauth2.request; -// -// import org.prgrms.nabimarketbe.domain.user.dto.request.SocialUserInfoDTO; -// -// public class SocialUserInfoDTOBuilder { -// public static SocialUserInfoDTO createTestDTO() { -// return SocialUserInfoDTO.builder() -// .accountId("testAccount") -// .provider("KAKAO") -// .build(); -// } -// } diff --git a/src/test/java/org/prgrms/nabimarketbe/setup/user/UserBuilder.java b/src/test/java/org/prgrms/nabimarketbe/setup/user/UserBuilder.java deleted file mode 100644 index 5076229b..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/setup/user/UserBuilder.java +++ /dev/null @@ -1,16 +0,0 @@ -// package org.prgrms.nabimarketbe.setup.user; -// -// import org.prgrms.nabimarketbe.domain.user.entity.Role; -// import org.prgrms.nabimarketbe.domain.user.entity.User; -// -// public class UserBuilder { -// public static User createTestEntity() { -// return User.builder() -// .accountId("testAccountId") -// .nickname("testNickname") -// .role(Role.USER.getKey()) -// .imageUrl("testImageUrl") -// .provider("KAKAO") -// .build(); -// } -// } diff --git a/src/test/java/org/prgrms/nabimarketbe/setup/user/request/UserNicknameUpdateRequestDTOBuilder.java b/src/test/java/org/prgrms/nabimarketbe/setup/user/request/UserNicknameUpdateRequestDTOBuilder.java deleted file mode 100644 index d0064e42..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/setup/user/request/UserNicknameUpdateRequestDTOBuilder.java +++ /dev/null @@ -1,9 +0,0 @@ -// package org.prgrms.nabimarketbe.setup.user.request; -// -// import org.prgrms.nabimarketbe.domain.user.dto.request.UserNicknameUpdateRequestDTO; -// -// public class UserNicknameUpdateRequestDTOBuilder { -// public static UserNicknameUpdateRequestDTO createTestDTO() { -// return new UserNicknameUpdateRequestDTO("testUpdateNickname"); -// } -// } diff --git a/src/test/java/org/prgrms/nabimarketbe/setup/user/request/UserProfileUpdateRequestDTOBuilder.java b/src/test/java/org/prgrms/nabimarketbe/setup/user/request/UserProfileUpdateRequestDTOBuilder.java deleted file mode 100644 index e88adfe9..00000000 --- a/src/test/java/org/prgrms/nabimarketbe/setup/user/request/UserProfileUpdateRequestDTOBuilder.java +++ /dev/null @@ -1,9 +0,0 @@ -// package org.prgrms.nabimarketbe.setup.user.request; -// -// import org.prgrms.nabimarketbe.domain.user.dto.request.UserProfileUpdateRequestDTO; -// -// public class UserProfileUpdateRequestDTOBuilder { -// public static UserProfileUpdateRequestDTO createTestDTO() { -// return new UserProfileUpdateRequestDTO("testImageUrl"); -// } -// } diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml deleted file mode 100644 index ef46c2ad..00000000 --- a/src/test/resources/application.yml +++ /dev/null @@ -1,3 +0,0 @@ -spring: - profiles: - active: local \ No newline at end of file From 7db5c4a7f79d333ed9e956d59873a40f10bd5304 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Thu, 25 Jan 2024 22:48:06 +0900 Subject: [PATCH 3/9] =?UTF-8?q?NO-JIRA--chore=20:=20gitignore=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 --- .gitignore | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 0c2eb72d..5acdb389 100644 --- a/.gitignore +++ b/.gitignore @@ -204,14 +204,8 @@ gradle-app.setting # Java heap dump *.hprof -nabimarket-api/src/main/resources/application-test.yml -nabimarket-api/src/main/resources/application-prod.yml -nabimarket-api/src/main/resources/application-local.yml -nabimarket-api/src/main/resources/application-jwt.yml -nabimarket-api/src/main/resources/application-dev.yml -nabimarket-api/src/main/resources/firebase/* - *.yml !nabimarket-api/src/main/resources/application.yml +nabimarket-api/src/main/resources/firebase/* # End of https://www.toptal.com/developers/gitignore/api/macos,java,gradle,intellij From 71ac02db5829fc5c0958831945c81c5ea404fa47 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Thu, 25 Jan 2024 22:48:23 +0900 Subject: [PATCH 4/9] =?UTF-8?q?NO-JIRA--chore=20:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EC=9C=84=ED=95=9C=20build=20gradle=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index d94eb85b..82de65a4 100644 --- a/build.gradle +++ b/build.gradle @@ -35,9 +35,9 @@ subprojects { // web implementation 'org.springframework.boot:spring-boot-starter-web' - -// testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' -// testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' + testImplementation 'org.springframework.boot:spring-boot-starter-test' } // gradle 빌드시에는 각 프로젝트를 실행가능한 jar형태로 만들게 되는데, module-common 프로젝트의 경우 main메소드가 없음 From 56b8d98bab659108458595eab0cc83c3b8983670 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:45:31 +0900 Subject: [PATCH 5/9] =?UTF-8?q?NO-JIRA--rename=20:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=A9=94=EC=86=8C=EB=93=9C=EB=AA=85=20snake=20case?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/user/RandomNicknameGeneratorTest.java | 2 +- nabimarket-application/src/test/java/user/SignServiceTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nabimarket-application/src/test/java/user/RandomNicknameGeneratorTest.java b/nabimarket-application/src/test/java/user/RandomNicknameGeneratorTest.java index 0ba980aa..f058296c 100644 --- a/nabimarket-application/src/test/java/user/RandomNicknameGeneratorTest.java +++ b/nabimarket-application/src/test/java/user/RandomNicknameGeneratorTest.java @@ -32,7 +32,7 @@ class RandomNicknameGeneratorTest { @DisplayName("랜덤닉네임 생성 시에 RuntimeException 발생시 2번까지 재시도한다.") @Test - void testGenerateRandomNicknameWithRetry() { + void generateRandomNickname_with_retry() { // given doThrow(new RuntimeException("Intended Retry Error")).when(restTemplate) .getForObject(anyString(), eq(String.class)); diff --git a/nabimarket-application/src/test/java/user/SignServiceTest.java b/nabimarket-application/src/test/java/user/SignServiceTest.java index 51748621..d3682ecc 100644 --- a/nabimarket-application/src/test/java/user/SignServiceTest.java +++ b/nabimarket-application/src/test/java/user/SignServiceTest.java @@ -39,7 +39,7 @@ class SignServiceTest { @DisplayName("사용자는 소셜로그인 이후 받아온 정보로 나비장터에 로그인을 할 수 있다.") @Test - void UserSignInTest() { + void signIn_test() { // given SocialUserInfoDTO socialUserInfoDTO = SocialUserInfoDTOBuilder.createTestDTO(); User user = UserBuilder.createTestEntity(); From 2c693bb088ee0907184a0a633f6216960159d8dc Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:45:48 +0900 Subject: [PATCH 6/9] =?UTF-8?q?NO-JIRA--test=20:=20checkService=20test=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/user/CheckServiceTest.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 nabimarket-application/src/test/java/user/CheckServiceTest.java diff --git a/nabimarket-application/src/test/java/user/CheckServiceTest.java b/nabimarket-application/src/test/java/user/CheckServiceTest.java new file mode 100644 index 00000000..3476c362 --- /dev/null +++ b/nabimarket-application/src/test/java/user/CheckServiceTest.java @@ -0,0 +1,71 @@ +package user; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.prgrms.nabimarketbe.jwt.provider.JwtProvider; +import org.prgrms.nabimarketbe.user.service.CheckService; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.impl.DefaultClaims; + +@ExtendWith(MockitoExtension.class) +class CheckServiceTest { + @InjectMocks + CheckService checkService; + + @Mock + JwtProvider jwtProvider; + + @DisplayName("parseToken 메소드를 호출하면 유저의 Id가 파싱된다.") + @Test + void parseToken_test() { + // given + Long expectedUserId = 1L; + String token = "1L"; + Claims claims = new DefaultClaims(); + claims.put("sub", expectedUserId); + + given(jwtProvider.parseClaims(any())).willReturn(claims); + + // when + Long userId = checkService.parseToken(token); + + // then + assertThat(userId).isEqualTo(expectedUserId); + } + + @DisplayName("String(유저토큰)과 Long(유저Id)이 같은지 비교한다.") + @Test + void isEqual_String_Long_test() { + // given + Long expectedUserId = 1L; + String token = "1L"; + Claims claims = new DefaultClaims(); + claims.put("sub", expectedUserId); + + given(jwtProvider.parseClaims(any())).willReturn(claims); + + // when & then + assertThat(checkService.isEqual(token, expectedUserId)).isTrue(); + } + + @DisplayName("Long(유저1 Id)과 Long(유저2 Id)이 같은지 비교한다.") + @Test + void isEqual_Long_Long_test() { + // given + Long userOneId = 1L; + Long userOneId2 = 1L; + + // when & then + assertThat(checkService.isEqual(userOneId, userOneId2)).isTrue(); + } + +} From 43be97485698d03b83a46cb767455043f3a9d1da Mon Sep 17 00:00:00 2001 From: BeommoKoo <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:51:44 +0900 Subject: [PATCH 7/9] =?UTF-8?q?NO-JIRA--chore=20:=20=EB=AA=A8=EB=93=88=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=EC=97=90=20=EB=94=B0=EB=A5=B8=20CICD=20scrip?= =?UTF-8?q?t=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index f1968255..bd81b1f1 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -38,7 +38,7 @@ jobs: # application.properties를 프로젝트에 포함 - name: Make application.properties run: | - cd ./src/main/resources + cd nabimarket-api/src/main/resources touch ./application.properties echo "${{ secrets.DATABASE_PROPERTIES }}" >> ./application.properties From 7abda5b9f4ca63c370ec651a0af7c29f6ebd1bd2 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:18:11 +0900 Subject: [PATCH 8/9] =?UTF-8?q?NO-JIRA--remove=20:=20CardViewServiceTest?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/card/CardViewServiceTest.java | 89 ------------------- 1 file changed, 89 deletions(-) delete mode 100644 nabimarket-application/src/test/java/card/CardViewServiceTest.java diff --git a/nabimarket-application/src/test/java/card/CardViewServiceTest.java b/nabimarket-application/src/test/java/card/CardViewServiceTest.java deleted file mode 100644 index 72f4a22c..00000000 --- a/nabimarket-application/src/test/java/card/CardViewServiceTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package card; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.prgrms.nabimarketbe.card.service.CardViewCountService; -import org.prgrms.nabimarketbe.redisson.RedisDAO; -import org.prgrms.nabimarketbe.util.KeyGenerator; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - -@SpringBootTest -public class CardViewServiceTest { - @Autowired - private ThreadPoolTaskExecutor taskExecutor; - - @Autowired - private RedisDAO redisDAO; - - @Autowired - private CardViewCountService cardViewCountService; - - private List userIdList = new ArrayList<>(); - - private Long cardId; - - private String cardViewCacheKey; - - @BeforeEach - void setKeys() { - cardId = 1L; - - for (Long i = 1L; i <= 10L; i++) { - userIdList.add(i); - } - cardViewCacheKey = KeyGenerator.generateCardViewCacheKey(cardId); - } - - @AfterEach - void deleteValues() { - redisDAO.deleteValues(cardViewCacheKey); - - for (Long i = 1L; i <= 10; i++) { - redisDAO.deleteValues(KeyGenerator.generateCardReaderCacheKey(i)); - } - } - - @Test - @DisplayName("10명의 다른 사용자가 같은 카드에 대해 단건 조회를 요청 했을 경우 조회수 증가") - void increaseViewCountTest() throws InterruptedException { - // given - Integer expectedViewCountCacheValue = 10; - - int numberOfThreads = 10; - ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads); - CountDownLatch latch = new CountDownLatch(numberOfThreads); - - // when - for (int i = 0; i < numberOfThreads; i++) { - int index = i; - - executorService.submit(() -> { - try { - cardViewCountService.increaseViewCount(userIdList.get(index), cardId); - } finally { - latch.countDown(); - } - }); - } - - latch.await(); - - taskExecutor.getThreadPoolExecutor().awaitTermination(1, TimeUnit.SECONDS); - - // then - assertThat(redisDAO.getValue(cardViewCacheKey)).isEqualTo(expectedViewCountCacheValue.toString()); - } -} From 2319c2ec8a63a34b6f5e31259322acbf33af96c1 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:18:34 +0900 Subject: [PATCH 9/9] =?UTF-8?q?NO-JIRA--chore=20:=20CI=EC=8B=A4=ED=8C=A8?= =?UTF-8?q?=20=EC=9D=B4=EC=8A=88=20=ED=95=B4=EA=B2=B0=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20build=20gradle=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 11 +++++++++-- nabimarket-api/build.gradle | 8 ++++++++ nabimarket-application/build.gradle | 11 ++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 82de65a4..e562880a 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,13 @@ repositories { mavenCentral() } +bootJar { + enabled = false +} +jar { + enabled = true +} + // 각 모듈에 적용할 공통 설정 subprojects { group = 'org.prgrms' @@ -40,8 +47,8 @@ subprojects { testImplementation 'org.springframework.boot:spring-boot-starter-test' } - // gradle 빌드시에는 각 프로젝트를 실행가능한 jar형태로 만들게 되는데, module-common 프로젝트의 경우 main메소드가 없음 - // 단순히 참조용 클래스들만 있는 프로젝트를 위해 아래와 같은 설정(bootJar, jar)들을 추가함 +// // gradle 빌드시에는 각 프로젝트를 실행가능한 jar형태로 만들게 되는데, module-common 프로젝트의 경우 main메소드가 없음 +// // 단순히 참조용 클래스들만 있는 프로젝트를 위해 아래와 같은 설정(bootJar, jar)들을 추가함 bootJar { enabled = false } diff --git a/nabimarket-api/build.gradle b/nabimarket-api/build.gradle index cfdd9d7a..69f6e2aa 100644 --- a/nabimarket-api/build.gradle +++ b/nabimarket-api/build.gradle @@ -11,3 +11,11 @@ dependencies { // security implementation 'org.springframework.boot:spring-boot-starter-security' } + + +bootJar { + enabled = true +} +jar { + enabled = true +} diff --git a/nabimarket-application/build.gradle b/nabimarket-application/build.gradle index a4e0ee9f..c42d17c8 100644 --- a/nabimarket-application/build.gradle +++ b/nabimarket-application/build.gradle @@ -1,5 +1,5 @@ dependencies { - testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation platform('org.junit:junit-bom:5.9.2') testImplementation 'org.junit.jupiter:junit-jupiter' // swagger implementation 'org.springdoc:springdoc-openapi-ui:1.6.15' @@ -21,8 +21,13 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' } +bootJar { + enabled = false +} +jar { + enabled = true +} + task wrapper(type: Wrapper) { gradleVersion = '8.3' } - -tasks.register("prepareKotlinBuildScriptModel") {}