-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from wanniDev/main
테스트 환경 개선
- Loading branch information
Showing
46 changed files
with
531 additions
and
264 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
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
28 changes: 28 additions & 0 deletions
28
app/src/main/kotlin/org/collaborators/paymentslab/config/resilience4j/Resilience4jConfig.kt
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.collaborators.paymentslab.config.resilience4j | ||
|
||
import io.github.resilience4j.common.retry.configuration.RetryConfigCustomizer | ||
import io.github.resilience4j.core.IntervalFunction | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
private const val TOSS_PAYMENTS_APPROVAL = "tossPaymentsApprovalProcessor" | ||
private const val INITIAL_INTERVAL = 1000L | ||
private const val MULTIPLIER = 2.0 | ||
private const val RANDOMIZATION_FACTOR = 0.6 | ||
private const val MAX_RETRIES = 4 | ||
|
||
@Configuration | ||
class Resilience4jConfig { | ||
@Bean | ||
fun retryConfigCustomizer(): RetryConfigCustomizer { | ||
val jitterBackoffFunction | ||
= IntervalFunction.ofExponentialRandomBackoff(INITIAL_INTERVAL, MULTIPLIER, RANDOMIZATION_FACTOR) | ||
|
||
return RetryConfigCustomizer | ||
.of(TOSS_PAYMENTS_APPROVAL) { | ||
it.maxAttempts(MAX_RETRIES) | ||
.intervalFunction(jitterBackoffFunction) | ||
.build() | ||
} | ||
} | ||
} |
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,16 @@ | ||
package org.collaborators.paymentslab.account.presentation | ||
|
||
import org.collaborator.paymentlab.common.* | ||
import org.collaborator.paymentlab.common.error.ErrorCode | ||
import org.collaborator.paymentlab.common.error.ResourceNotFoundException | ||
import org.collaborators.paymentslab.AbstractApiTest | ||
import org.collaborators.paymentslab.account.domain.Account | ||
import org.collaborators.paymentslab.account.domain.AccountRepository | ||
import org.collaborators.paymentslab.account.presentation.request.LoginAccountRequest | ||
import org.collaborators.paymentslab.account.presentation.request.RegisterAccountRequest | ||
import org.collaborators.paymentslab.account.presentation.request.RegisterAdminAccountRequest | ||
import org.collaborators.paymentslab.account.presentation.request.RegisterConfirmRequest | ||
import org.junit.jupiter.api.* | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.given | ||
import org.springframework.http.MediaType | ||
import org.springframework.restdocs.headers.HeaderDocumentation.headerWithName | ||
import org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders | ||
|
@@ -22,15 +23,18 @@ import org.springframework.restdocs.payload.PayloadDocumentation.* | |
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
||
class AuthenticationApiTest @Autowired constructor( | ||
private val accountRepository: AccountRepository | ||
) : AbstractApiTest() { | ||
class AuthenticationApiTest : AbstractApiTest() { | ||
@Test | ||
@DisplayName("회원가입 api 동작") | ||
fun registerTest() { | ||
val requestDto = RegisterAccountRequest("[email protected]", "qwer1234", "helloUsername", "010-1234-5678") | ||
val reqBody = this.objectMapper.writeValueAsString(requestDto) | ||
|
||
val mockMember = MockAuthentication.mockUserAccountFrom(requestDto) | ||
given(accountRepository.existByEmail(mockMember.email)).willReturn(false) | ||
given(accountRepository.save(any())).willReturn(mockMember) | ||
given(accountRepository.findByEmail(any())).willReturn(mockMember) | ||
|
||
this.mockMvc.perform( | ||
RestDocumentationRequestBuilders | ||
.post("$V1_AUTH/$REGISTER") | ||
|
@@ -70,6 +74,11 @@ class AuthenticationApiTest @Autowired constructor( | |
RegisterAdminAccountRequest("[email protected]", "qwer1234", "helloUsername", "010-1234-5678", adminKey) | ||
val reqBody = this.objectMapper.writeValueAsString(requestDto) | ||
|
||
val mockMember = MockAuthentication.mockAdminAccountFrom(requestDto) | ||
given(accountRepository.existByEmail(mockMember.email)).willReturn(false) | ||
given(accountRepository.save(any())).willReturn(mockMember) | ||
given(accountRepository.findByEmail(any())).willReturn(mockMember) | ||
|
||
this.mockMvc.perform( | ||
RestDocumentationRequestBuilders | ||
.post("$V1_AUTH/$REGISTER_ADMIN") | ||
|
@@ -190,9 +199,9 @@ class AuthenticationApiTest @Autowired constructor( | |
@Test | ||
@DisplayName("회원가입 검증 api 동작 테스트") | ||
fun confirmTest() { | ||
val registered = accountRepository.save(Account.register("[email protected]", | ||
encrypt.encode("qqqwww123"), "hello2", "010-1234-1234")) | ||
val account = accountRepository.findByEmail(registered.email) | ||
val account = MockAuthentication.mockUserAccount() | ||
given(accountRepository.save(any())).willReturn(account) | ||
given(accountRepository.findByEmail(any())).willReturn(account) | ||
|
||
val requestDto = RegisterConfirmRequest(account.emailCheckToken!!, account.email) | ||
val reqBody = this.objectMapper.writeValueAsString(requestDto) | ||
|
@@ -224,10 +233,11 @@ class AuthenticationApiTest @Autowired constructor( | |
@Test | ||
@DisplayName("로그인 api 동작 테스트") | ||
fun loginTest() { | ||
val registered = testEntityForRegister("[email protected]") | ||
val account = accountRepository.save(registered) | ||
val account = MockAuthentication.mockUserAccount() | ||
given(accountRepository.save(any())).willReturn(account) | ||
given(accountRepository.findByEmail(any())).willReturn(account) | ||
|
||
val requestDto = LoginAccountRequest(account.email, "qqqwww123") | ||
val requestDto = LoginAccountRequest(account.email, MockAuthentication.testPlainPassword) | ||
val reqBody = this.objectMapper.writeValueAsString(requestDto) | ||
|
||
this.mockMvc.perform( | ||
|
@@ -270,11 +280,10 @@ class AuthenticationApiTest @Autowired constructor( | |
@Test | ||
@DisplayName("잘못된 로그인 api 에러 테스트") | ||
fun loginErrorTest() { | ||
val registered = accountRepository.save(Account.register("[email protected]", | ||
encrypt.encode("qqqwww123"), "hello2", "010-1234-1234")) | ||
val account = accountRepository.findByEmail(registered.email) | ||
val account = MockAuthentication.mockUserAccount() | ||
given(accountRepository.findByEmail(any())).willReturn(account) | ||
|
||
val requestDto = LoginAccountRequest(account.email, "wrongpassword123") | ||
val requestDto = LoginAccountRequest(account.email, MockAuthentication.testWrongPlainPassword) | ||
val reqBody = this.objectMapper.writeValueAsString(requestDto) | ||
|
||
this.mockMvc.perform( | ||
|
@@ -305,10 +314,11 @@ class AuthenticationApiTest @Autowired constructor( | |
@Test | ||
@DisplayName("토큰 재발급 api 테스트") | ||
fun reIssuanceTest() { | ||
val registered = testEntityForRegister("[email protected]") | ||
val account = accountRepository.save(registered) | ||
val account = MockAuthentication.mockUserAccount() | ||
val tokens = tokenGenerator.generate(account.email, account.roles) | ||
|
||
given(accountRepository.findByEmail(any())).willReturn(account) | ||
|
||
this.mockMvc.perform( | ||
RestDocumentationRequestBuilders | ||
.post("$V1_AUTH/$RE_ISSUANCE") | ||
|
@@ -344,8 +354,9 @@ class AuthenticationApiTest @Autowired constructor( | |
@Test | ||
@DisplayName("회원 등록이 안된 사용자의 토큰으로 재발급 실패 api 테스트") | ||
fun notRegisteredReIssuanceTest() { | ||
val registered = testEntityForRegister("[email protected]") | ||
val tokens = tokenGenerator.generate(registered.email, registered.roles) | ||
val account = MockAuthentication.mockUserAccount() | ||
given(accountRepository.findByEmail(MockAuthentication.testWrongReissuerEmail)).willThrow(ResourceNotFoundException(ErrorCode.ACCOUNT_NOT_FOUND)) | ||
val tokens = tokenGenerator.generate(MockAuthentication.testWrongReissuerEmail, account.roles) | ||
|
||
this.mockMvc.perform( | ||
RestDocumentationRequestBuilders | ||
|
Oops, something went wrong.