From 3cd5daf8e5da7cf676723f8f38cac75a7e663141 Mon Sep 17 00:00:00 2001 From: ChoiSeungeon Date: Wed, 18 Mar 2026 16:14:31 +0900 Subject: [PATCH 1/3] =?UTF-8?q?DABOM-495=20chore:=20lib-kafka=20v1.0.1=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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e669425..101a4f3 100644 --- a/build.gradle +++ b/build.gradle @@ -77,7 +77,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-redis' runtimeOnly 'com.mysql:mysql-connector-j' implementation 'org.springframework.kafka:spring-kafka' - implementation 'com.github.da-bom:lib-kafka:v1.0.0' + implementation 'com.github.da-bom:lib-kafka:v1.0.1' // QueryDSL implementation 'com.querydsl:querydsl-jpa:5.1.0:jakarta' From 2c3e9b153b2d20083f31efa2ea868372d5c2a4f6 Mon Sep 17 00:00:00 2001 From: ChoiSeungeon Date: Wed, 18 Mar 2026 16:14:56 +0900 Subject: [PATCH 2/3] =?UTF-8?q?DABOM-495=20refactor:=20lib-kafka=20v1.0.1?= =?UTF-8?q?=EC=97=90=20=EB=B3=80=EA=B2=BD=EB=90=9C=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9C=BC=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 --- .../usage/service/helper/UsageNotificationPayloadMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/project/domain/usage/service/helper/UsageNotificationPayloadMapper.java b/src/main/java/com/project/domain/usage/service/helper/UsageNotificationPayloadMapper.java index 6348fa2..ce152bd 100644 --- a/src/main/java/com/project/domain/usage/service/helper/UsageNotificationPayloadMapper.java +++ b/src/main/java/com/project/domain/usage/service/helper/UsageNotificationPayloadMapper.java @@ -84,7 +84,7 @@ private NotificationPayload buildBlockedAlert( return new NotificationPayload( usagePayload.familyId(), usagePayload.customerId(), - NotificationType.BLOCKED, + NotificationType.CUSTOMER_BLOCKED, "데이터 사용 차단", message, data); From 9fbd8afb17c64d25767dd72fa7a25df435b5a893 Mon Sep 17 00:00:00 2001 From: ChoiSeungeon Date: Wed, 18 Mar 2026 17:28:55 +0900 Subject: [PATCH 3/3] =?UTF-8?q?DABOM-495=20refactor:=20UsageEventOutbo?= =?UTF-8?q?=EC=97=90=EC=84=9C=20EventOutbox=EB=A1=9C=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/EventOutbox.java} | 12 ++--- .../eventoutbox/enums/EventOutboxStatus.java | 7 +++ .../repository/EventOutboxRepository.java} | 18 +++---- .../service/EventOutboxService.java} | 24 ++++----- .../domain/usage/enums/UsageOutboxStatus.java | 7 --- .../usage/service/UsageSyncServiceImpl.java | 12 ++--- .../service/UsageSyncServiceImplTest.java | 30 +++++------ ...eTest.java => EventOutboxServiceTest.java} | 53 ++++++++++--------- 8 files changed, 82 insertions(+), 81 deletions(-) rename src/main/java/com/project/domain/{usage/entity/UsageEventOutbox.java => eventoutbox/entity/EventOutbox.java} (89%) create mode 100644 src/main/java/com/project/domain/eventoutbox/enums/EventOutboxStatus.java rename src/main/java/com/project/domain/{usage/repository/UsageEventOutboxRepository.java => eventoutbox/repository/EventOutboxRepository.java} (71%) rename src/main/java/com/project/domain/{usage/service/helper/UsageEventOutboxService.java => eventoutbox/service/EventOutboxService.java} (81%) delete mode 100644 src/main/java/com/project/domain/usage/enums/UsageOutboxStatus.java rename src/test/java/com/project/domain/usage/service/helper/{UsageEventOutboxServiceTest.java => EventOutboxServiceTest.java} (65%) diff --git a/src/main/java/com/project/domain/usage/entity/UsageEventOutbox.java b/src/main/java/com/project/domain/eventoutbox/entity/EventOutbox.java similarity index 89% rename from src/main/java/com/project/domain/usage/entity/UsageEventOutbox.java rename to src/main/java/com/project/domain/eventoutbox/entity/EventOutbox.java index 53544e4..eaab250 100644 --- a/src/main/java/com/project/domain/usage/entity/UsageEventOutbox.java +++ b/src/main/java/com/project/domain/eventoutbox/entity/EventOutbox.java @@ -1,4 +1,4 @@ -package com.project.domain.usage.entity; +package com.project.domain.eventoutbox.entity; import java.time.LocalDateTime; @@ -14,7 +14,7 @@ import jakarta.persistence.UniqueConstraint; import com.project.common.util.BaseEntity; -import com.project.domain.usage.enums.UsageOutboxStatus; +import com.project.domain.eventoutbox.enums.EventOutboxStatus; import lombok.AccessLevel; import lombok.Builder; @@ -32,7 +32,7 @@ indexes = { @Index(name = "idx_usage_outbox_status_retry", columnList = "status, next_retry_at") }) -public class UsageEventOutbox extends BaseEntity { +public class EventOutbox extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -49,7 +49,7 @@ public class UsageEventOutbox extends BaseEntity { @Enumerated(EnumType.STRING) @Column(name = "status", nullable = false, length = 30) - private UsageOutboxStatus status; + private EventOutboxStatus status; @Column(name = "payload_json", columnDefinition = "TEXT") private String payloadJson; @@ -64,12 +64,12 @@ public class UsageEventOutbox extends BaseEntity { private String lastError; @Builder - private UsageEventOutbox( + private EventOutbox( Long id, String eventId, Long familyId, Long customerId, - UsageOutboxStatus status, + EventOutboxStatus status, String payloadJson, int retryCount, LocalDateTime nextRetryAt, diff --git a/src/main/java/com/project/domain/eventoutbox/enums/EventOutboxStatus.java b/src/main/java/com/project/domain/eventoutbox/enums/EventOutboxStatus.java new file mode 100644 index 0000000..f8f240c --- /dev/null +++ b/src/main/java/com/project/domain/eventoutbox/enums/EventOutboxStatus.java @@ -0,0 +1,7 @@ +package com.project.domain.eventoutbox.enums; + +public enum EventOutboxStatus { + PUBLISH_PENDING, + SENT, + FAILED +} diff --git a/src/main/java/com/project/domain/usage/repository/UsageEventOutboxRepository.java b/src/main/java/com/project/domain/eventoutbox/repository/EventOutboxRepository.java similarity index 71% rename from src/main/java/com/project/domain/usage/repository/UsageEventOutboxRepository.java rename to src/main/java/com/project/domain/eventoutbox/repository/EventOutboxRepository.java index f614720..6bfbfe8 100644 --- a/src/main/java/com/project/domain/usage/repository/UsageEventOutboxRepository.java +++ b/src/main/java/com/project/domain/eventoutbox/repository/EventOutboxRepository.java @@ -1,4 +1,4 @@ -package com.project.domain.usage.repository; +package com.project.domain.eventoutbox.repository; import java.util.Optional; @@ -7,11 +7,11 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import com.project.domain.usage.entity.UsageEventOutbox; +import com.project.domain.eventoutbox.entity.EventOutbox; -public interface UsageEventOutboxRepository extends JpaRepository { +public interface EventOutboxRepository extends JpaRepository { - Optional findByEventId(String eventId); + Optional findByEventId(String eventId); @Modifying @Query( @@ -31,12 +31,12 @@ int insertPublishPendingIgnore( @Modifying @Query( """ - update UsageEventOutbox o + update EventOutbox o set o.payloadJson = :payloadJson, o.nextRetryAt = null, o.lastError = null where o.eventId = :eventId - and o.status = com.project.domain.usage.enums.UsageOutboxStatus.PUBLISH_PENDING + and o.status = com.project.domain.eventoutbox.enums.EventOutboxStatus.PUBLISH_PENDING """) int refreshPendingPayload( @Param("eventId") String eventId, @Param("payloadJson") String payloadJson); @@ -44,12 +44,12 @@ int refreshPendingPayload( @Modifying @Query( """ - update UsageEventOutbox o - set o.status = com.project.domain.usage.enums.UsageOutboxStatus.SENT, + update EventOutbox o + set o.status = com.project.domain.eventoutbox.enums.EventOutboxStatus.SENT, o.nextRetryAt = null, o.lastError = null where o.id = :outboxId - and o.status = com.project.domain.usage.enums.UsageOutboxStatus.PUBLISH_PENDING + and o.status = com.project.domain.eventoutbox.enums.EventOutboxStatus.PUBLISH_PENDING """) int markSentIfPending(@Param("outboxId") Long outboxId); } diff --git a/src/main/java/com/project/domain/usage/service/helper/UsageEventOutboxService.java b/src/main/java/com/project/domain/eventoutbox/service/EventOutboxService.java similarity index 81% rename from src/main/java/com/project/domain/usage/service/helper/UsageEventOutboxService.java rename to src/main/java/com/project/domain/eventoutbox/service/EventOutboxService.java index 362b93e..9701458 100644 --- a/src/main/java/com/project/domain/usage/service/helper/UsageEventOutboxService.java +++ b/src/main/java/com/project/domain/eventoutbox/service/EventOutboxService.java @@ -1,4 +1,4 @@ -package com.project.domain.usage.service.helper; +package com.project.domain.eventoutbox.service; import java.util.Optional; @@ -9,8 +9,8 @@ import com.dabom.messaging.kafka.event.dto.notification.NotificationPayload; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.project.domain.usage.enums.UsageOutboxStatus; -import com.project.domain.usage.repository.UsageEventOutboxRepository; +import com.project.domain.eventoutbox.enums.EventOutboxStatus; +import com.project.domain.eventoutbox.repository.EventOutboxRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -18,9 +18,9 @@ @Slf4j @Service @RequiredArgsConstructor -public class UsageEventOutboxService { +public class EventOutboxService { - private final UsageEventOutboxRepository usageEventOutboxRepository; + private final EventOutboxRepository eventOutboxRepository; private final ObjectMapper objectMapper; // notification 대상인 경우에만 PUBLISH_PENDING row를 보장한다. @@ -32,12 +32,12 @@ public Optional stageAfterRedisApplied( } String payloadJson = toJson(payload); - usageEventOutboxRepository.insertPublishPendingIgnore( + eventOutboxRepository.insertPublishPendingIgnore( eventId, payload.familyId(), payload.customerId(), payloadJson); - usageEventOutboxRepository.refreshPendingPayload(eventId, payloadJson); - return usageEventOutboxRepository + eventOutboxRepository.refreshPendingPayload(eventId, payloadJson); + return eventOutboxRepository .findByEventId(eventId) - .filter(row -> row.getStatus() == UsageOutboxStatus.PUBLISH_PENDING) + .filter(row -> row.getStatus() == EventOutboxStatus.PUBLISH_PENDING) .map( row -> new PendingNotificationDispatch( @@ -48,9 +48,9 @@ public Optional stageAfterRedisApplied( // eventId 기준으로 아직 발행되지 않은 notification payload를 찾는다. @Transactional(readOnly = true) public Optional findPendingDispatchByEventId(String eventId) { - return usageEventOutboxRepository + return eventOutboxRepository .findByEventId(eventId) - .filter(row -> row.getStatus() == UsageOutboxStatus.PUBLISH_PENDING) + .filter(row -> row.getStatus() == EventOutboxStatus.PUBLISH_PENDING) .map( row -> new PendingNotificationDispatch( @@ -61,7 +61,7 @@ public Optional findPendingDispatchByEventId(String // 발행 성공 시 Outbox 상태를 SENT로 변경한다. @Transactional public void markSent(Long outboxId) { - int updated = usageEventOutboxRepository.markSentIfPending(outboxId); + int updated = eventOutboxRepository.markSentIfPending(outboxId); if (updated == 0) { log.debug("Skip markSent because outbox is no longer pending. outboxId={}", outboxId); } diff --git a/src/main/java/com/project/domain/usage/enums/UsageOutboxStatus.java b/src/main/java/com/project/domain/usage/enums/UsageOutboxStatus.java deleted file mode 100644 index ace6f1a..0000000 --- a/src/main/java/com/project/domain/usage/enums/UsageOutboxStatus.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.project.domain.usage.enums; - -public enum UsageOutboxStatus { - PUBLISH_PENDING, - SENT, - FAILED -} diff --git a/src/main/java/com/project/domain/usage/service/UsageSyncServiceImpl.java b/src/main/java/com/project/domain/usage/service/UsageSyncServiceImpl.java index ba7d9f5..35ff48b 100644 --- a/src/main/java/com/project/domain/usage/service/UsageSyncServiceImpl.java +++ b/src/main/java/com/project/domain/usage/service/UsageSyncServiceImpl.java @@ -20,9 +20,9 @@ import com.project.common.config.TimeConfig; import com.project.common.util.LogSanitizer; import com.project.common.util.RedisKeyGenerator; +import com.project.domain.eventoutbox.service.EventOutboxService; import com.project.domain.policy.helper.PolicyConstraintWarmupHelper; import com.project.domain.usage.service.dto.UsageUpdateResult; -import com.project.domain.usage.service.helper.UsageEventOutboxService; import com.project.domain.usage.service.helper.UsageFamilyMembershipCacheHelper; import com.project.domain.usage.service.helper.UsageLuaExecutor; import com.project.domain.usage.service.helper.UsageNotificationPayloadMapper; @@ -46,7 +46,7 @@ public class UsageSyncServiceImpl implements UsageSyncService { private final PolicyConstraintWarmupHelper policyConstraintWarmupHelper; private final UsageLuaExecutor usageLuaExecutor; private final UsagePersistService usagePersistService; - private final UsageEventOutboxService usageEventOutboxService; + private final EventOutboxService eventOutboxService; private final UsageProcessingDecisionMapper usageProcessingDecisionMapper; private final UsageNotificationPayloadMapper usageNotificationPayloadMapper; private final UsageNotificationPublisher usageNotificationPublisher; @@ -167,7 +167,7 @@ public void syncUsage(String eventId, String eventTime, UsagePayload payload) { usageNotificationPayloadMapper.toNotificationPayload( eventId, resolvedEventDateTime, payload, decision.notificationStatus()); - usageEventOutboxService + eventOutboxService .stageAfterRedisApplied(eventId, notificationPayload, true) .ifPresent(this::publishAsync); } @@ -214,17 +214,17 @@ private void ensureWarmupOrThrow( // 이미 만들어진 pending notification이 있으면 다시 즉시 발행을 시도한다. private void dispatchPendingNotificationIfExists(String eventId) { - usageEventOutboxService.findPendingDispatchByEventId(eventId).ifPresent(this::publishAsync); + eventOutboxService.findPendingDispatchByEventId(eventId).ifPresent(this::publishAsync); } // notification은 비동기로 발행하고 성공 시에만 SENT로 마감한다. - private void publishAsync(UsageEventOutboxService.PendingNotificationDispatch pending) { + private void publishAsync(EventOutboxService.PendingNotificationDispatch pending) { usageNotificationPublisher .publishAsync(pending.payload()) .whenComplete( (SendResult ignored, Throwable throwable) -> { if (throwable == null) { - usageEventOutboxService.markSent(pending.outboxId()); + eventOutboxService.markSent(pending.outboxId()); return; } diff --git a/src/test/java/com/project/domain/usage/service/UsageSyncServiceImplTest.java b/src/test/java/com/project/domain/usage/service/UsageSyncServiceImplTest.java index 8557637..0f6259c 100644 --- a/src/test/java/com/project/domain/usage/service/UsageSyncServiceImplTest.java +++ b/src/test/java/com/project/domain/usage/service/UsageSyncServiceImplTest.java @@ -37,9 +37,9 @@ import com.dabom.messaging.kafka.metrics.KafkaMetrics; import com.project.common.util.LogSanitizer; import com.project.common.util.RedisKeyGenerator; +import com.project.domain.eventoutbox.service.EventOutboxService; import com.project.domain.policy.helper.PolicyConstraintWarmupHelper; import com.project.domain.usage.service.dto.UsageUpdateResult; -import com.project.domain.usage.service.helper.UsageEventOutboxService; import com.project.domain.usage.service.helper.UsageFamilyMembershipCacheHelper; import com.project.domain.usage.service.helper.UsageLuaExecutor; import com.project.domain.usage.service.helper.UsageNotificationPayloadMapper; @@ -57,7 +57,7 @@ class UsageSyncServiceImplTest { @Mock private PolicyConstraintWarmupHelper policyConstraintWarmupHelper; @Mock private UsageLuaExecutor usageLuaExecutor; @Mock private UsagePersistService usagePersistService; - @Mock private UsageEventOutboxService usageEventOutboxService; + @Mock private EventOutboxService eventOutboxService; @Mock private UsageProcessingDecisionMapper usageProcessingDecisionMapper; @Mock private UsageNotificationPayloadMapper usageNotificationPayloadMapper; @Mock private UsageNotificationPublisher usageNotificationPublisher; @@ -101,10 +101,10 @@ void syncUsage_SuccessFlow() { usageNotificationPayloadMapper.toNotificationPayload( any(), any(), any(), eq("WARNING_10"))) .willReturn(notificationPayload); - given(usageEventOutboxService.stageAfterRedisApplied(eventId, notificationPayload, true)) + given(eventOutboxService.stageAfterRedisApplied(eventId, notificationPayload, true)) .willReturn( Optional.of( - new UsageEventOutboxService.PendingNotificationDispatch( + new EventOutboxService.PendingNotificationDispatch( 11L, notificationPayload))); given(usageNotificationPublisher.publishAsync(notificationPayload)) .willReturn(CompletableFuture.completedFuture(null)); @@ -132,7 +132,7 @@ void syncUsage_SuccessFlow() { verify(usagePersistService).persistFromUsageEvent(eventId, eventTime, payload, "ALLOWED"); verify(usageNotificationPublisher).publishAsync(notificationPayload); - verify(usageEventOutboxService).markSent(11L); + verify(eventOutboxService).markSent(11L); } @Test @@ -195,10 +195,10 @@ void syncUsage_DuplicateStillReentersPersist() { usageNotificationPayloadMapper.toNotificationPayload( any(), any(), any(), eq("WARNING_10"))) .willReturn(notificationPayload); - given(usageEventOutboxService.stageAfterRedisApplied(eventId, notificationPayload, true)) + given(eventOutboxService.stageAfterRedisApplied(eventId, notificationPayload, true)) .willReturn( Optional.of( - new UsageEventOutboxService.PendingNotificationDispatch( + new EventOutboxService.PendingNotificationDispatch( 21L, notificationPayload))); given(usageNotificationPublisher.publishAsync(notificationPayload)) .willReturn(CompletableFuture.completedFuture(null)); @@ -234,10 +234,10 @@ void syncUsage_DuplicateRepublishesExistingPendingNotification() { new UsageUpdateResult( 5000L, 5000L, "NORMAL", 1000L, 0.1, 10000L, false, true)); given(usageProcessingDecisionMapper.fromLuaStatus("NORMAL")).willReturn(decision); - given(usageEventOutboxService.findPendingDispatchByEventId(eventId)) + given(eventOutboxService.findPendingDispatchByEventId(eventId)) .willReturn( Optional.of( - new UsageEventOutboxService.PendingNotificationDispatch( + new EventOutboxService.PendingNotificationDispatch( 31L, notificationPayload))); given(usageNotificationPublisher.publishAsync(notificationPayload)) .willReturn(CompletableFuture.completedFuture(null)); @@ -245,9 +245,9 @@ void syncUsage_DuplicateRepublishesExistingPendingNotification() { usageSyncServiceImpl.syncUsage(eventId, eventTime, payload); verify(usagePersistService).persistFromUsageEvent(eventId, eventTime, payload, "ALLOWED"); - verify(usageEventOutboxService, never()).stageAfterRedisApplied(any(), any(), anyBoolean()); + verify(eventOutboxService, never()).stageAfterRedisApplied(any(), any(), anyBoolean()); verify(usageNotificationPublisher).publishAsync(notificationPayload); - verify(usageEventOutboxService).markSent(31L); + verify(eventOutboxService).markSent(31L); } @Test @@ -267,7 +267,7 @@ void syncUsage_SkipsNotificationWhenShouldNotifyFalse() { new UsageUpdateResult( 5000L, 5000L, "APP_BLOCK", 1000L, 0.1, 10000L, false, false)); given(usageProcessingDecisionMapper.fromLuaStatus("APP_BLOCK")).willReturn(decision); - given(usageEventOutboxService.findPendingDispatchByEventId(eventId)) + given(eventOutboxService.findPendingDispatchByEventId(eventId)) .willReturn(Optional.empty()); usageSyncServiceImpl.syncUsage(eventId, eventTime, payload); @@ -275,7 +275,7 @@ void syncUsage_SkipsNotificationWhenShouldNotifyFalse() { verify(usagePersistService).persistFromUsageEvent(eventId, eventTime, payload, "APP_BLOCK"); verify(usageNotificationPayloadMapper, never()) .toNotificationPayload(any(), any(), any(), any()); - verify(usageEventOutboxService, never()).stageAfterRedisApplied(any(), any(), anyBoolean()); + verify(eventOutboxService, never()).stageAfterRedisApplied(any(), any(), anyBoolean()); verify(usageNotificationPublisher, never()).publishAsync(any()); } @@ -296,7 +296,7 @@ void syncUsage_NormalEventSkipsPayloadCreation() { new UsageUpdateResult( 5000L, 5000L, "NORMAL", 1000L, 0.1, 10000L, false, false)); given(usageProcessingDecisionMapper.fromLuaStatus("NORMAL")).willReturn(decision); - given(usageEventOutboxService.findPendingDispatchByEventId(eventId)) + given(eventOutboxService.findPendingDispatchByEventId(eventId)) .willReturn(Optional.empty()); usageSyncServiceImpl.syncUsage(eventId, eventTime, payload); @@ -304,7 +304,7 @@ void syncUsage_NormalEventSkipsPayloadCreation() { verify(usagePersistService).persistFromUsageEvent(eventId, eventTime, payload, "ALLOWED"); verify(usageNotificationPayloadMapper, never()) .toNotificationPayload(any(), any(), any(), any()); - verify(usageEventOutboxService, never()).stageAfterRedisApplied(any(), any(), anyBoolean()); + verify(eventOutboxService, never()).stageAfterRedisApplied(any(), any(), anyBoolean()); } @Test diff --git a/src/test/java/com/project/domain/usage/service/helper/UsageEventOutboxServiceTest.java b/src/test/java/com/project/domain/usage/service/helper/EventOutboxServiceTest.java similarity index 65% rename from src/test/java/com/project/domain/usage/service/helper/UsageEventOutboxServiceTest.java rename to src/test/java/com/project/domain/usage/service/helper/EventOutboxServiceTest.java index 6206379..8e4e3dd 100644 --- a/src/test/java/com/project/domain/usage/service/helper/UsageEventOutboxServiceTest.java +++ b/src/test/java/com/project/domain/usage/service/helper/EventOutboxServiceTest.java @@ -22,15 +22,16 @@ import com.dabom.messaging.kafka.event.dto.notification.NotificationPayload; import com.dabom.messaging.kafka.event.dto.notification.NotificationType; import com.fasterxml.jackson.databind.ObjectMapper; -import com.project.domain.usage.entity.UsageEventOutbox; -import com.project.domain.usage.enums.UsageOutboxStatus; -import com.project.domain.usage.repository.UsageEventOutboxRepository; +import com.project.domain.eventoutbox.entity.EventOutbox; +import com.project.domain.eventoutbox.enums.EventOutboxStatus; +import com.project.domain.eventoutbox.repository.EventOutboxRepository; +import com.project.domain.eventoutbox.service.EventOutboxService; @ExtendWith(MockitoExtension.class) -class UsageEventOutboxServiceTest { +class EventOutboxServiceTest { - @InjectMocks private UsageEventOutboxService usageEventOutboxService; - @Mock private UsageEventOutboxRepository usageEventOutboxRepository; + @InjectMocks private EventOutboxService eventOutboxService; + @Mock private EventOutboxRepository eventOutboxRepository; @Spy private ObjectMapper objectMapper = new ObjectMapper(); @Test @@ -39,33 +40,33 @@ void stageAfterRedisApplied_ToPublishPending() { NotificationPayload payload = new NotificationPayload( 100L, 1L, NotificationType.THRESHOLD_ALERT, "title", "message", Map.of()); - UsageEventOutbox pending = - UsageEventOutbox.builder() + EventOutbox pending = + EventOutbox.builder() .id(10L) .eventId("evt_2") .familyId(100L) .customerId(1L) - .status(UsageOutboxStatus.PUBLISH_PENDING) + .status(EventOutboxStatus.PUBLISH_PENDING) .payloadJson(objectMapper.valueToTree(payload).toString()) .retryCount(0) .build(); given( - usageEventOutboxRepository.insertPublishPendingIgnore( + eventOutboxRepository.insertPublishPendingIgnore( eq("evt_2"), eq(100L), eq(1L), any(String.class))) .willReturn(1); - given(usageEventOutboxRepository.refreshPendingPayload(eq("evt_2"), any(String.class))) + given(eventOutboxRepository.refreshPendingPayload(eq("evt_2"), any(String.class))) .willReturn(1); - given(usageEventOutboxRepository.findByEventId("evt_2")).willReturn(Optional.of(pending)); + given(eventOutboxRepository.findByEventId("evt_2")).willReturn(Optional.of(pending)); - Optional dispatch = - usageEventOutboxService.stageAfterRedisApplied("evt_2", payload, true); + Optional dispatch = + eventOutboxService.stageAfterRedisApplied("evt_2", payload, true); assertTrue(dispatch.isPresent()); assertEquals(100L, dispatch.get().payload().familyId()); - verify(usageEventOutboxRepository) + verify(eventOutboxRepository) .insertPublishPendingIgnore(eq("evt_2"), eq(100L), eq(1L), any(String.class)); - verify(usageEventOutboxRepository).refreshPendingPayload(eq("evt_2"), any(String.class)); + verify(eventOutboxRepository).refreshPendingPayload(eq("evt_2"), any(String.class)); } @Test @@ -75,13 +76,13 @@ void stageAfterRedisApplied_WhenNotificationSkipped_ReturnsEmpty() { new NotificationPayload( 100L, 1L, NotificationType.THRESHOLD_ALERT, "title", "message", Map.of()); - Optional dispatch = - usageEventOutboxService.stageAfterRedisApplied("evt_3", payload, false); + Optional dispatch = + eventOutboxService.stageAfterRedisApplied("evt_3", payload, false); assertTrue(dispatch.isEmpty()); - verify(usageEventOutboxRepository, never()) + verify(eventOutboxRepository, never()) .insertPublishPendingIgnore(any(), any(Long.class), any(Long.class), any()); - verify(usageEventOutboxRepository, never()).refreshPendingPayload(any(), any()); + verify(eventOutboxRepository, never()).refreshPendingPayload(any(), any()); } @Test @@ -95,20 +96,20 @@ void findPendingDispatchByEventId_ReturnsPayload() { "title", "message", Map.of("threshold", 10)); - UsageEventOutbox pending = - UsageEventOutbox.builder() + EventOutbox pending = + EventOutbox.builder() .id(20L) .eventId("evt_4") .familyId(100L) .customerId(1L) - .status(UsageOutboxStatus.PUBLISH_PENDING) + .status(EventOutboxStatus.PUBLISH_PENDING) .payloadJson(objectMapper.valueToTree(payload).toString()) .retryCount(0) .build(); - given(usageEventOutboxRepository.findByEventId("evt_4")).willReturn(Optional.of(pending)); + given(eventOutboxRepository.findByEventId("evt_4")).willReturn(Optional.of(pending)); - Optional found = - usageEventOutboxService.findPendingDispatchByEventId("evt_4"); + Optional found = + eventOutboxService.findPendingDispatchByEventId("evt_4"); assertTrue(found.isPresent()); assertEquals(20L, found.get().outboxId());