Skip to content

Commit

Permalink
MODINVSTOR-1262 improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-barannyk committed Nov 9, 2024
1 parent 89c4bfe commit d88aab9
Showing 1 changed file with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,30 +16,74 @@

@ExtendWith(VertxExtension.class)
public class ServicePointSynchronizationEventProcessorTest {
private static final String TENANT = "tenant";
private ServicePointSynchronizationUpdateEventProcessor updateEventProcessor;
private ServicePointSynchronizationCreateEventProcessor createEventProcessor;

@BeforeEach
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) {

Expand Down

0 comments on commit d88aab9

Please sign in to comment.