diff --git a/src/test/java/org/folio/services/consortium/processor/ServicePointSynchronizationEventProcessorTest.java b/src/test/java/org/folio/services/consortium/processor/ServicePointSynchronizationEventProcessorTest.java index 30d7b33b1..3d4ae79d4 100644 --- a/src/test/java/org/folio/services/consortium/processor/ServicePointSynchronizationEventProcessorTest.java +++ b/src/test/java/org/folio/services/consortium/processor/ServicePointSynchronizationEventProcessorTest.java @@ -1,9 +1,12 @@ package org.folio.services.consortium.processor; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import io.vertx.junit5.VertxExtension; import io.vertx.junit5.VertxTestContext; +import java.util.UUID; +import org.folio.rest.jaxrs.model.HoldShelfExpiryPeriod; import org.folio.rest.jaxrs.model.Servicepoint; import org.folio.services.domainevent.DomainEvent; import org.folio.services.domainevent.DomainEventType; @@ -13,6 +16,7 @@ @ExtendWith(VertxExtension.class) public class ServicePointSynchronizationEventProcessorTest { + private static final String TENANT = "tenant"; private ServicePointSynchronizationUpdateEventProcessor updateEventProcessor; private ServicePointSynchronizationCreateEventProcessor createEventProcessor; @@ -20,23 +24,66 @@ public class ServicePointSynchronizationEventProcessorTest { void setUp() { Servicepoint newServicepoint = new Servicepoint(); Servicepoint oldServicepoint = new Servicepoint(); - updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(new DomainEvent<>( - oldServicepoint, newServicepoint, DomainEventType.UPDATE, "tenant")); + createEventProcessor = new ServicePointSynchronizationCreateEventProcessor( - new DomainEvent<>(oldServicepoint, newServicepoint, DomainEventType.CREATE, "tenant") + new DomainEvent<>(oldServicepoint, newServicepoint, DomainEventType.CREATE, TENANT) ); } @Test - void shouldFailToUpdateEventDueToNullServicePointService(VertxTestContext testContext) { + void shouldFailToUpdateEventDueToProcessEventException(VertxTestContext testContext) { + updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(new DomainEvent<>( + new Servicepoint(), new Servicepoint(), DomainEventType.UPDATE, TENANT)); processEventToThrowException(updateEventProcessor, testContext); } @Test - void shouldFailToCreateEventDueToNullServicePointService(VertxTestContext testContext) { + void shouldFailToCreateEventDueToProcessEventException(VertxTestContext testContext) { + updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(new DomainEvent<>( + new Servicepoint(), new Servicepoint(), DomainEventType.UPDATE, TENANT)); processEventToThrowException(createEventProcessor, testContext); } + @Test + void shouldReturnFalseIfBothServicePointsAreNull() { + updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor( + new DomainEvent<>(null, null, DomainEventType.UPDATE, TENANT)); + + assertFalse(updateEventProcessor.validateEventEntity()); + } + + @Test + void shouldReturnFalseIfServicePointsAreIdentical() { + Servicepoint servicepoint = new Servicepoint(); + updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor( + new DomainEvent<>(servicepoint, servicepoint, DomainEventType.UPDATE, TENANT)); + + assertFalse(updateEventProcessor.validateEventEntity()); + } + + @Test + void shouldReturnTrueIfNewServicePointIsValid() { + Servicepoint oldServicepoint = new Servicepoint().withId(UUID.randomUUID().toString()); + Servicepoint newServicepoint = new Servicepoint().withId(UUID.randomUUID().toString()); + + updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor( + new DomainEvent<>(oldServicepoint, newServicepoint, DomainEventType.UPDATE, TENANT)); + + assertTrue(updateEventProcessor.validateEventEntity()); + } + + @Test + void shouldReturnFalseIfValidationMessageIsNotNull() { + Servicepoint oldServicepoint = new Servicepoint(); + Servicepoint newServicepoint = new Servicepoint() + .withHoldShelfExpiryPeriod(new HoldShelfExpiryPeriod()); + + updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor( + new DomainEvent<>(oldServicepoint, newServicepoint, DomainEventType.UPDATE, TENANT)); + + assertFalse(updateEventProcessor.validateEventEntity()); + } + private void processEventToThrowException(ServicePointSynchronizationEventProcessor processor, VertxTestContext testContext) {