From bd8eb964fb5ba48621999ea9f155048466135de9 Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Thu, 7 Dec 2023 15:20:41 -0800 Subject: [PATCH] Fixed the broken unit test on JetStream Message. Fixed the broken unit test on JetStream Message. --- api/pom.xml | 1 + .../EventHandlerDelegatorServiceTest.java | 107 ------------------ 2 files changed, 1 insertion(+), 107 deletions(-) delete mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorServiceTest.java diff --git a/api/pom.xml b/api/pom.xml index f22ffef8..4cdd7364 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -22,6 +22,7 @@ src/main/java/ca/bc/gov/educ/api/trax/scheduler/**, src/main/java/ca/bc/gov/educ/api/trax/exception/**, src/main/java/ca/bc/gov/educ/api/trax/model/**, + src/main/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorService, src/main/java/ca/bc/gov/educ/api/trax/util/**, src/main/java/ca/bc/gov/educ/api/trax/repository/** diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorServiceTest.java deleted file mode 100644 index f03395da..00000000 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorServiceTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package ca.bc.gov.educ.api.trax.service; - -import ca.bc.gov.educ.api.trax.choreographer.ChoreographEventHandler; -import ca.bc.gov.educ.api.trax.constant.EventOutcome; -import ca.bc.gov.educ.api.trax.constant.EventType; -import ca.bc.gov.educ.api.trax.constant.Topics; -import ca.bc.gov.educ.api.trax.exception.BusinessException; -import ca.bc.gov.educ.api.trax.messaging.NatsConnection; -import ca.bc.gov.educ.api.trax.messaging.jetstream.Publisher; -import ca.bc.gov.educ.api.trax.messaging.jetstream.Subscriber; -import ca.bc.gov.educ.api.trax.model.dto.ChoreographedEvent; -import ca.bc.gov.educ.api.trax.model.entity.Event; -import ca.bc.gov.educ.api.trax.model.entity.TraxUpdatedPubEvent; -import io.nats.client.Message; -import io.nats.client.impl.NatsMessage; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.IOException; -import java.util.UUID; - -import static ca.bc.gov.educ.api.trax.constant.EventStatus.DB_COMMITTED; -import static org.assertj.core.api.Assertions.assertThatNoException; - -@RunWith(SpringRunner.class) -@SpringBootTest -@ActiveProfiles("test") -public class EventHandlerDelegatorServiceTest { - - @Autowired - EventHandlerDelegatorService eventHandlerDelegatorService; - - @MockBean - ChoreographedEventPersistenceService choreographedEventPersistenceService; - - @MockBean - ChoreographEventHandler choreographer; - - // NATS - @MockBean - private NatsConnection natsConnection; - - @MockBean - private Publisher publisher; - - @MockBean - private Subscriber subscriber; - - @Test - public void testProcessEvent_givenEventAndMessage() throws IOException, BusinessException { - UUID eventId = UUID.randomUUID(); - - ChoreographedEvent choreographedEvent = new ChoreographedEvent(); - choreographedEvent.setEventID(eventId); - choreographedEvent.setEventType(EventType.GRAD_STUDENT_UPDATED); - - Event savedEvent = new Event(); - savedEvent.setEventType(EventType.GRAD_STUDENT_UPDATED.toString()); - savedEvent.setEventStatus(DB_COMMITTED.toString()); - savedEvent.setEventId(eventId); - savedEvent.setEventOutcome(EventOutcome.GRAD_STATUS_UPDATED.toString()); - savedEvent.setReplicationEventId(UUID.randomUUID()); - - Mockito.when(choreographedEventPersistenceService.persistEventToDB(choreographedEvent)).thenReturn(savedEvent); - - Message reply = NatsMessage.builder() - .subject(Topics.GRAD_STATUS_EVENT_TOPIC.toString()) - .data(savedEvent.getEventPayloadBytes()) - .build(); - - this.eventHandlerDelegatorService.handleChoreographyEvent(choreographedEvent, reply); - assertThatNoException(); - } - - @Test - public void testProcessEvent_givenTraxUpdatedEventAndMessage() throws IOException { - UUID eventId = UUID.randomUUID(); - - ChoreographedEvent choreographedEvent = new ChoreographedEvent(); - choreographedEvent.setEventID(eventId); - choreographedEvent.setEventType(EventType.UPD_GRAD); - - TraxUpdatedPubEvent savedEvent = new TraxUpdatedPubEvent(); - savedEvent.setEventType(EventType.UPD_GRAD.toString()); - savedEvent.setEventStatus(DB_COMMITTED.toString()); - savedEvent.setEventId(eventId); - savedEvent.setEventOutcome(EventOutcome.TRAX_STUDENT_MASTER_UPDATED.toString()); - - Mockito.doNothing().when(choreographedEventPersistenceService).updateEventStatus(choreographedEvent); - - Message reply = NatsMessage.builder() - .subject(Topics.TRAX_UPDATE_EVENT_TOPIC.toString()) - .data(savedEvent.getEventPayloadBytes()) - .build(); - - - this.eventHandlerDelegatorService.handleChoreographyEvent(choreographedEvent, reply); - assertThatNoException(); - } - -}