diff --git a/src/main/java/com/modoospace/alarm/service/AlarmService.java b/src/main/java/com/modoospace/alarm/service/AlarmService.java index 009eb12..297ae65 100644 --- a/src/main/java/com/modoospace/alarm/service/AlarmService.java +++ b/src/main/java/com/modoospace/alarm/service/AlarmService.java @@ -10,18 +10,18 @@ import com.modoospace.common.exception.SSEConnectError; import com.modoospace.config.redis.aspect.CachePrefixEvict; import com.modoospace.member.domain.Member; -import com.modoospace.member.service.MemberService; +import com.modoospace.member.domain.MemberRepository; +import java.io.IOException; +import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.AmqpRejectAndDontRequeueException; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; -import java.io.IOException; -import java.util.Optional; - @Slf4j @RequiredArgsConstructor @Service @@ -30,7 +30,7 @@ public class AlarmService { private static final Long DEFAULT_TIMEOUT = 60L * 1000 * 60; private static final String ALARM_NAME = "sse"; - private final MemberService memberService; + private final MemberRepository memberRepository; private final AlarmRepository alarmRepository; private final AlarmQueryRepository alarmQueryRepository; private final EmitterLocalCacheRepository emitterRepository; @@ -54,7 +54,9 @@ public SseEmitter connectAlarm(String loginEmail) { @Transactional @CachePrefixEvict(cacheNames = "searchAlarms", key = "#alarmEvent.email") public void saveAndSend(AlarmEvent alarmEvent) { - Member member = memberService.findMemberByEmail(alarmEvent.getEmail()); + Member member = memberRepository.findByEmail(alarmEvent.getEmail()) + .orElseThrow(() -> new AmqpRejectAndDontRequeueException( + "사용자" + alarmEvent.getEmail() + "를 찾을 수 없습니다.")); Alarm alarm = alarmRepository.save(alarmEvent.toEntity()); send(member.getEmail(), AlarmResponse.of(alarm)); diff --git a/src/test/java/com/modoospace/alarm/consumer/AlarmConsumerTest.java b/src/test/java/com/modoospace/alarm/consumer/AlarmConsumerTest.java index eac689e..62fd997 100644 --- a/src/test/java/com/modoospace/alarm/consumer/AlarmConsumerTest.java +++ b/src/test/java/com/modoospace/alarm/consumer/AlarmConsumerTest.java @@ -1,26 +1,25 @@ package com.modoospace.alarm.consumer; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import com.modoospace.AbstractIntegrationContainerBaseTest; import com.modoospace.alarm.controller.dto.AlarmEvent; import com.modoospace.alarm.domain.Alarm; import com.modoospace.alarm.domain.AlarmRepository; import com.modoospace.alarm.domain.AlarmType; -import com.modoospace.common.exception.NotFoundEntityException; import com.modoospace.member.domain.Member; import com.modoospace.member.domain.MemberRepository; import com.modoospace.member.domain.Role; +import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.springframework.amqp.AmqpRejectAndDontRequeueException; import org.springframework.beans.factory.annotation.Autowired; import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException; import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - class AlarmConsumerTest extends AbstractIntegrationContainerBaseTest { @Autowired @@ -65,7 +64,6 @@ public void handler_ifMember_saveAlarm() throws JsonProcessingException { .containsExactly("test facility"); } - /* @DisplayName("Consumer는 가입되지 않은 멤버의 메시지를 소비할 경우 Exception을 던진다.") @Test public void handler_ifNotMember_throwException() throws JsonProcessingException { @@ -78,7 +76,6 @@ public void handler_ifNotMember_throwException() throws JsonProcessingException String message = objectMapper.writeValueAsString(alarmEvent); assertThatThrownBy(() -> alarmConsumer.handler(message)) - .isInstanceOf(NotFoundEntityException.class); + .isInstanceOf(AmqpRejectAndDontRequeueException.class); } - */ } \ No newline at end of file