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 11, 2024
1 parent d88aab9 commit 87b9b1c
Showing 1 changed file with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.folio.services.consortium.processor;

import static org.folio.services.domainevent.DomainEvent.createEvent;
import static org.folio.services.domainevent.DomainEvent.deleteEvent;
import static org.folio.services.domainevent.DomainEvent.updateEvent;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -8,55 +11,51 @@
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;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@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();

createEventProcessor = new ServicePointSynchronizationCreateEventProcessor(
new DomainEvent<>(oldServicepoint, newServicepoint, DomainEventType.CREATE, TENANT)
);
}

@Test
void shouldFailToUpdateEventDueToProcessEventException(VertxTestContext testContext) {
updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(new DomainEvent<>(
new Servicepoint(), new Servicepoint(), DomainEventType.UPDATE, TENANT));
var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(updateEvent(
new Servicepoint(), new Servicepoint(), TENANT));
processEventToThrowException(updateEventProcessor, testContext);
}

@Test
void shouldFailToCreateEventDueToProcessEventException(VertxTestContext testContext) {
updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(new DomainEvent<>(
new Servicepoint(), new Servicepoint(), DomainEventType.UPDATE, TENANT));
var createEventProcessor = new ServicePointSynchronizationCreateEventProcessor(createEvent(
new Servicepoint(), TENANT));
processEventToThrowException(createEventProcessor, testContext);
}

@Test
void shouldReturnFalseIfBothServicePointsAreNull() {
updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
new DomainEvent<>(null, null, DomainEventType.UPDATE, TENANT));
var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
updateEvent(null, null, TENANT));

assertFalse(updateEventProcessor.validateEventEntity());
}

@Test
void shouldReturnFalseIfServicePointIsNull() {
var createEventProcessor = new ServicePointSynchronizationCreateEventProcessor(
createEvent(null, TENANT));
var deleteEventProcessor = new ServicePointSynchronizationDeleteEventProcessor(
deleteEvent(null, TENANT));

assertFalse(createEventProcessor.validateEventEntity());
assertFalse(deleteEventProcessor.validateEventEntity());
}

@Test
void shouldReturnFalseIfServicePointsAreIdentical() {
Servicepoint servicepoint = new Servicepoint();
updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
new DomainEvent<>(servicepoint, servicepoint, DomainEventType.UPDATE, TENANT));
var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
updateEvent(servicepoint, servicepoint, TENANT));

assertFalse(updateEventProcessor.validateEventEntity());
}
Expand All @@ -66,8 +65,8 @@ 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));
var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
updateEvent(oldServicepoint, newServicepoint, TENANT));

assertTrue(updateEventProcessor.validateEventEntity());
}
Expand All @@ -78,8 +77,8 @@ void shouldReturnFalseIfValidationMessageIsNotNull() {
Servicepoint newServicepoint = new Servicepoint()
.withHoldShelfExpiryPeriod(new HoldShelfExpiryPeriod());

updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
new DomainEvent<>(oldServicepoint, newServicepoint, DomainEventType.UPDATE, TENANT));
var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
updateEvent(oldServicepoint, newServicepoint, TENANT));

assertFalse(updateEventProcessor.validateEventEntity());
}
Expand Down

0 comments on commit 87b9b1c

Please sign in to comment.