Skip to content

Commit

Permalink
Merge branch 'ecs-tlr-feature' of https://github.com/folio-org/mod-in…
Browse files Browse the repository at this point in the history
…ventory-storage into ecs-tlr-feature
  • Loading branch information
alexanderkurash committed Nov 12, 2024
2 parents c7ed656 + ad2a2e1 commit 6ada10a
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ These environment variables configure the module interaction with S3-compatible
* `S3_ACCESS_KEY_ID`
* `S3_SECRET_ACCESS_KEY`
* `S3_IS_AWS` (default value - `false`)
* `ECS_TLR_FEATURE_ENABLED` (default value - `false`)

# Local Deployment using Docker

Expand Down
15 changes: 10 additions & 5 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1125,23 +1125,28 @@
{
"methods": ["GET"],
"pathPattern": "/service-points",
"permissionsRequired": ["inventory-storage.service-points.collection.get"]
"permissionsRequired": ["inventory-storage.service-points.collection.get"],
"modulePermissions": ["user-tenants.collection.get"]
}, {
"methods": ["GET"],
"pathPattern": "/service-points/{id}",
"permissionsRequired": ["inventory-storage.service-points.item.get"]
"permissionsRequired": ["inventory-storage.service-points.item.get"],
"modulePermissions": ["user-tenants.collection.get"]
}, {
"methods": ["POST"],
"pathPattern": "/service-points",
"permissionsRequired": ["inventory-storage.service-points.item.post"]
"permissionsRequired": ["inventory-storage.service-points.item.post"],
"modulePermissions": ["user-tenants.collection.get"]
}, {
"methods": ["PUT"],
"pathPattern": "/service-points/{id}",
"permissionsRequired": ["inventory-storage.service-points.item.put"]
"permissionsRequired": ["inventory-storage.service-points.item.put"],
"modulePermissions": ["user-tenants.collection.get"]
}, {
"methods": ["DELETE"],
"pathPattern": "/service-points/{id}",
"permissionsRequired": ["inventory-storage.service-points.item.delete"]
"permissionsRequired": ["inventory-storage.service-points.item.delete"],
"modulePermissions": ["user-tenants.collection.get"]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected ServicePointSynchronizationHandler(ConsortiumDataCache consortiumDataC

@Override
public Future<String> handle(KafkaConsumerRecord<String, String> kafkaConsumerRecord) {
log.info("handle:: Processing event {}", kafkaConsumerRecord.topic());
log.info("handle:: Processing event {}", kafkaConsumerRecord::topic);
var headers = new CaseInsensitiveMap<>(KafkaHeaderUtils.kafkaHeadersToMap(
kafkaConsumerRecord.headers()));
return consortiumDataCache.getConsortiumData(headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ public void shouldPropagateDeleteOfServicePointOnLendingTenant(TestContext conte
context.assertEquals(HTTP_NOT_FOUND, statusCode)));
}

@Test
public void shouldHandleUpdateEventForNonExistingServicePoint(TestContext context) {
Servicepoint nonExistingServicePoint = new Servicepoint().withId(UUID.randomUUID().toString());
publishServicePointUpdateEvent(nonExistingServicePoint, nonExistingServicePoint);

getStatusCodeOfServicePointById(COLLEGE_TENANT_ID)
.onComplete(context.asyncAssertSuccess(statusCode ->
context.assertEquals(HTTP_NOT_FOUND, statusCode)));
}

@Test
public void shouldHandleDeleteEventForNonExistingServicePoint(TestContext context) {
Servicepoint nonExistingServicePoint = new Servicepoint().withId(UUID.randomUUID().toString());
publishServicePointDeleteEvent(nonExistingServicePoint);

getStatusCodeOfServicePointById(COLLEGE_TENANT_ID)
.onComplete(context.asyncAssertSuccess(statusCode ->
context.assertEquals(HTTP_NOT_FOUND, statusCode)));
}

@SneakyThrows
public static <T> T waitFor(Future<T> future, int timeoutSeconds) {
return future.toCompletionStage()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
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;

import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import java.util.UUID;
import java.util.stream.Stream;
import org.folio.rest.jaxrs.model.HoldShelfExpiryPeriod;
import org.folio.rest.jaxrs.model.Servicepoint;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

@ExtendWith(VertxExtension.class)
class ServicePointSynchronizationEventProcessorTest {
private static final String TENANT = "tenant";

@Test
void shouldFailToUpdateEventDueToProcessEventException(VertxTestContext testContext) {
var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(updateEvent(
new Servicepoint(), new Servicepoint(), TENANT));
processEventToThrowException(updateEventProcessor, testContext);
}

@Test
void shouldFailToCreateEventDueToProcessEventException(VertxTestContext testContext) {
var createEventProcessor = new ServicePointSynchronizationCreateEventProcessor(createEvent(
new Servicepoint(), TENANT));
processEventToThrowException(createEventProcessor, testContext);
}

@ParameterizedTest
@MethodSource("servicePointProvider")
void shouldReturnFalseIfServicePointsAreNull(Servicepoint oldServicepoint, Servicepoint newServicepoint) {
String tenant = "tenant";
var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
updateEvent(oldServicepoint, newServicepoint, tenant));

assertFalse(updateEventProcessor.validateEventEntity());
}

static Stream<Arguments> servicePointProvider() {
return Stream.of(
Arguments.of(null, null),
Arguments.of(null, new Servicepoint()),
Arguments.of(new Servicepoint(), null));
}

@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() {
var servicepoint = new Servicepoint();
var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
updateEvent(servicepoint, servicepoint, TENANT));

assertFalse(updateEventProcessor.validateEventEntity());
}

@Test
void shouldReturnTrueForUpdateIfNewServicePointIsValid() {
var oldServicepoint = new Servicepoint().withId(UUID.randomUUID().toString());
var newServicepoint = new Servicepoint().withId(UUID.randomUUID().toString());

var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
updateEvent(oldServicepoint, newServicepoint, TENANT));

assertTrue(updateEventProcessor.validateEventEntity());
}

@Test
void shouldReturnTrueForCreateAndDeleteIfServicePointIsValid() {
var servicepoint = new Servicepoint().withId(UUID.randomUUID().toString());
var createEventProcessor = new ServicePointSynchronizationCreateEventProcessor(
createEvent(servicepoint, TENANT));
var deleteEventProcessor = new ServicePointSynchronizationDeleteEventProcessor(
deleteEvent(servicepoint, TENANT));

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

@Test
void shouldReturnFalseIfValidationMessageIsNotNull() {
Servicepoint oldServicepoint = new Servicepoint();
Servicepoint newServicepoint = new Servicepoint()
.withHoldShelfExpiryPeriod(new HoldShelfExpiryPeriod());

var updateEventProcessor = new ServicePointSynchronizationUpdateEventProcessor(
updateEvent(oldServicepoint, newServicepoint, TENANT));
var createEventProcessor = new ServicePointSynchronizationCreateEventProcessor(
createEvent(newServicepoint, TENANT));

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

private void processEventToThrowException(ServicePointSynchronizationEventProcessor processor,
VertxTestContext testContext) {

processor.processEvent(null, "")
.onComplete(ar ->
testContext.verify(() -> {
assertTrue(ar.cause() instanceof RuntimeException);
testContext.completeNow();
}));
}
}

0 comments on commit 6ada10a

Please sign in to comment.