-
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.
- Loading branch information
Showing
5 changed files
with
130 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
package com.van1164.user.config | ||
|
||
import com.van1164.user.UserRepository | ||
import com.van1164.user.subscribe.repository.SubscribeRepository | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories | ||
|
||
|
||
@Configuration | ||
@EnableR2dbcRepositories(basePackageClasses = [SubscribeRepository::class,UserRepository::class]) | ||
class UserConfig { | ||
} |
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
29 changes: 28 additions & 1 deletion
29
util/src/main/kotlin/com/van1164/common/config/R2dbcConfig.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 |
---|---|---|
@@ -1,4 +1,31 @@ | ||
package com.van1164.common.config | ||
|
||
class R2dbcConfig { | ||
import io.r2dbc.spi.ConnectionFactory | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories | ||
import org.springframework.r2dbc.connection.R2dbcTransactionManager | ||
import org.springframework.transaction.ReactiveTransactionManager | ||
import org.springframework.transaction.annotation.EnableTransactionManagement | ||
import org.springframework.transaction.annotation.TransactionManagementConfigurer | ||
import org.springframework.transaction.reactive.TransactionalOperator | ||
|
||
|
||
@Configuration | ||
@EnableR2dbcRepositories | ||
@EnableTransactionManagement | ||
class R2dbcConfig(private val connectionFactory: ConnectionFactory) : TransactionManagementConfigurer { | ||
@Bean | ||
fun transactionManager(): ReactiveTransactionManager { | ||
return R2dbcTransactionManager(connectionFactory) | ||
} | ||
|
||
@Bean | ||
fun transactionalOperator(transactionManager: ReactiveTransactionManager): TransactionalOperator { | ||
return TransactionalOperator.create(transactionManager) | ||
} | ||
|
||
override fun annotationDrivenTransactionManager(): ReactiveTransactionManager { | ||
return transactionManager() | ||
} | ||
} |
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,14 +1,20 @@ | ||
package service | ||
|
||
import com.van1164.common.redis.RedisRepository | ||
import com.van1164.common.test.Transaction | ||
import com.van1164.user.subscribe.service.SubscribeService | ||
import com.van1164.util.SUBSCRIBE_PREFIX | ||
import com.van1164.video.VideoApplication | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.test.annotation.Rollback | ||
import reactor.core.publisher.Mono | ||
import reactor.test.StepVerifier | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
|
@@ -17,14 +23,27 @@ import kotlin.test.assertNotNull | |
@SpringBootTest(classes = [VideoApplication::class]) | ||
class SubscribeServiceTest @Autowired constructor( | ||
val subscribeService: SubscribeService, | ||
val transaction: Transaction | ||
val transaction: Transaction, | ||
val redisRepository: RedisRepository, | ||
) { | ||
|
||
val testEmail = "[email protected]" | ||
|
||
@BeforeEach | ||
fun beforeEach(){ | ||
redisRepository.remove(SUBSCRIBE_PREFIX + testEmail).block() | ||
} | ||
|
||
@AfterEach | ||
fun afterEach(){ | ||
redisRepository.remove(SUBSCRIBE_PREFIX + testEmail).block() | ||
} | ||
|
||
@Test | ||
@DisplayName("구독 성공 테스트") | ||
@Rollback(value = true) | ||
fun successTest(){ | ||
subscribeService.subscribe("[email protected]","[email protected]") | ||
subscribeService.subscribe(testEmail,testEmail) | ||
.`as`(transaction::withRollback) | ||
.`as`(StepVerifier::create) | ||
.assertNext{response-> | ||
|
@@ -33,14 +52,23 @@ class SubscribeServiceTest @Autowired constructor( | |
assertNotNull(response.body) | ||
assertEquals(response.body,"success") | ||
} | ||
.verifyComplete() | ||
|
||
redisRepository.load(SUBSCRIBE_PREFIX+testEmail) | ||
.defaultIfEmpty("X") | ||
.`as`(StepVerifier::create) | ||
.assertNext{ | ||
assertEquals(it,"1") | ||
} | ||
.verifyComplete() | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName("없는 아이디로 인한 구독 실패 테스트") | ||
@Rollback(value = true) | ||
fun noUserIdFailTest(){ | ||
subscribeService.subscribe("[email protected]","[email protected]") | ||
subscribeService.subscribe("[email protected]",testEmail) | ||
.`as`(transaction::withRollback) | ||
.`as`(StepVerifier::create) | ||
.assertNext{response-> | ||
|
@@ -49,14 +77,25 @@ class SubscribeServiceTest @Autowired constructor( | |
assertNotNull(response.body) | ||
assertEquals(response.body ,"존재하지 않는 User") | ||
} | ||
.verifyComplete() | ||
|
||
redisRepository.load(SUBSCRIBE_PREFIX+testEmail) | ||
.defaultIfEmpty("X") | ||
.`as`(StepVerifier::create) | ||
.assertNext{ | ||
assertEquals(it,"X") | ||
} | ||
.verifyComplete() | ||
} | ||
|
||
@Test | ||
@DisplayName("이미 구독한 사용자 실패 테스트") | ||
@Rollback(value = true) | ||
fun duplicatedSubscribeFailTest(){ | ||
subscribeService.subscribe("[email protected]","[email protected]").`as`(transaction::withRollback).block() | ||
subscribeService.subscribe("[email protected]","[email protected]") | ||
subscribeService.subscribe(testEmail,testEmail) | ||
.flatMap { | ||
subscribeService.subscribe(testEmail,testEmail) | ||
} | ||
.`as`(transaction::withRollback) | ||
.`as`(StepVerifier::create) | ||
.assertNext{response-> | ||
|
@@ -65,24 +104,31 @@ class SubscribeServiceTest @Autowired constructor( | |
assertNotNull(response.body) | ||
assertEquals(response.body ,"이미 구독 중") | ||
} | ||
.verifyComplete() | ||
|
||
redisRepository.load(SUBSCRIBE_PREFIX+testEmail) | ||
.defaultIfEmpty("X") | ||
.`as`(StepVerifier::create) | ||
.assertNext{ | ||
assertEquals(it,"1") | ||
} | ||
.verifyComplete() | ||
} | ||
|
||
@Test | ||
@DisplayName("구독 취소 성공 테스트") | ||
@Rollback(value = true) | ||
fun subscribeCancel(){ | ||
subscribeService.subscribe("[email protected]","[email protected]") | ||
.`as`(transaction::withRollback) | ||
.`as`(StepVerifier::create) | ||
.assertNext { response -> | ||
subscribeService.subscribe(testEmail,testEmail) | ||
.doOnNext{ response -> | ||
assertNotNull(response) | ||
assertEquals(response.statusCode, HttpStatus.OK) | ||
assertNotNull(response.body) | ||
assertEquals(response.body, "success") | ||
} | ||
|
||
|
||
subscribeService.subscribeCancel("[email protected]","[email protected]") | ||
.flatMap { | ||
subscribeService.subscribeCancel(testEmail,testEmail) | ||
} | ||
.`as`(transaction::withRollback) | ||
.`as`(StepVerifier::create) | ||
.assertNext{cancel-> | ||
|
@@ -91,6 +137,16 @@ class SubscribeServiceTest @Autowired constructor( | |
assertNotNull(cancel.body) | ||
assertEquals(cancel.body ,"success") | ||
} | ||
.verifyComplete() | ||
|
||
|
||
redisRepository.load(SUBSCRIBE_PREFIX+testEmail) | ||
.`as`(StepVerifier::create) | ||
.assertNext{ | ||
assertEquals(it,"0") | ||
} | ||
.verifyComplete() | ||
|
||
} | ||
|
||
} |