Skip to content
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

Refactor | CAKK-83 | 통합테스트 kt 전환 및 kotest 도입 #211

Merged
merged 11 commits into from
Sep 20, 2024
3 changes: 3 additions & 0 deletions cakk-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-aop:3.3.0")
implementation("org.springframework:spring-tx")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")

// Security & OAuth
Expand All @@ -30,6 +31,8 @@ dependencies {
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:1.0.23")
testImplementation("io.kotest:kotest-runner-junit5:${property("kotestVersion")}")
testImplementation("io.mockk:mockk:${property("mockKVersion")}")

// test container
testImplementation("org.testcontainers:junit-jupiter:1.19.7")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.cakk.api.annotation

import org.springframework.core.annotation.AliasFor
import org.springframework.stereotype.Component

/**
* Indicates that an annotated class is a "ApplicationEventListener" (e.g. an event publish object).
*
*
* This annotation serves as a specialization of [@Component][Component],
* allowing for implementation classes to be autodetected through classpath scanning.
*
* @author komment
* @see Component
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
@Component
annotation class ApplicationEventListener(
/**
* Alias for [Component.value].
*/
@get:AliasFor(annotation = Component::class) val value: String = ""
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cakk.api.dto.event

data class EmailWithVerificationCodeSendEvent(
val email: String,
val code: String
)
10 changes: 0 additions & 10 deletions cakk-api/src/main/java/com/cakk/api/dto/event/ErrorAlertEvent.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.cakk.api.dto.event

import jakarta.servlet.http.HttpServletRequest

data class ErrorAlertEvent(
val exception: Exception,
val request: HttpServletRequest,
val profile: String
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.cakk.api.dto.event

data class IncreaseSearchCountEvent(
val keyword: String
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.cakk.api.listener

import org.springframework.scheduling.annotation.Async
import org.springframework.transaction.event.TransactionPhase
import org.springframework.transaction.event.TransactionalEventListener

import com.cakk.api.annotation.ApplicationEventListener
import com.cakk.api.dto.event.IncreaseSearchCountEvent
import com.cakk.domain.redis.repository.KeywordRedisRepository

@ApplicationEventListener
class SearchEventListener(
private val keywordRedisRepository: KeywordRedisRepository
) {

@Async
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
fun increaseSearchCount(event: IncreaseSearchCountEvent) {
keywordRedisRepository.saveOrIncreaseSearchCount(event.keyword)
}
}
8 changes: 4 additions & 4 deletions cakk-api/src/main/java/com/cakk/api/mapper/EventMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public static CertificationMessage supplyCertificationMessageBy(final Certificat
}

public static VerificationMessage supplyVerificationMessageBy(final EmailWithVerificationCodeSendEvent event) {
return new VerificationMessage(event.email(), event.code());
return new VerificationMessage(event.getEmail(), event.getCode());
}

public static ErrorAlertMessage supplyErrorAlertMessageBy(final ErrorAlertEvent event) {
final String profile = event.profile();
final String stackTrace = Arrays.toString(event.exception().getStackTrace());
final HttpServletRequest request = event.request();
final String profile = event.getProfile();
final String stackTrace = Arrays.toString(event.getException().getStackTrace());
final HttpServletRequest request = event.getRequest();

return new ErrorAlertMessage(
profile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ public CakeImageListResponse findCakeImagesByCursorAndCakeShopId(final CakeSearc
public CakeImageListResponse findCakeImagesByCursorAndSearch(final CakeSearchByLocationRequest dto) {
final List<CakeImageResponseParam> cakeImages
= cakeReadFacade.searchCakeImagesByCursorAndSearchKeyword(dto.toParam());
final IncreaseSearchCountEvent event = new IncreaseSearchCountEvent(dto.keyword());

publisher.publishEvent(event);
if (nonNull(dto.keyword())) {
final IncreaseSearchCountEvent event = new IncreaseSearchCountEvent(dto.keyword());
publisher.publishEvent(event);
}

return CakeMapper.supplyCakeImageListResponse(cakeImages);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ public CakeShopSearchResponse searchShopByKeyword(final CakeShopSearchRequest dt
final List<CakeShopBySearchParam> cakeShopBySearchParams = ShopMapper.supplyCakeShopBySearchParamListBy(result);

final CakeShops<CakeShopBySearchParam> cakeShops = new CakeShops<>(cakeShopBySearchParams, 4, pageSize);
final IncreaseSearchCountEvent event = com.cakk.api.mapper.EventMapper.supplyIncreaseSearchCountEventBy(dto.keyword());

publisher.publishEvent(event);
if (nonNull(dto.keyword())) {
final IncreaseSearchCountEvent event = com.cakk.api.mapper.EventMapper.supplyIncreaseSearchCountEventBy(dto.keyword());
publisher.publishEvent(event);
}

return ShopMapper.supplyCakeShopSearchResponseBy(cakeShops.getCakeShops());
}
Expand Down
107 changes: 0 additions & 107 deletions cakk-api/src/test/java/com/cakk/api/common/base/IntegrationTest.java

This file was deleted.

Loading
Loading