Search in sources :

Example 26 with ActionProfile

use of org.folio.ActionProfile in project mod-inventory by folio-org.

the class CreateHoldingEventHandlerTest method isEligibleShouldReturnFalseIfActionIsNotCreate.

@Test
public void isEligibleShouldReturnFalseIfActionIsNotCreate() {
    ActionProfile actionProfile = new ActionProfile().withId(UUID.randomUUID().toString()).withName("Create preliminary Item").withAction(ActionProfile.Action.DELETE).withFolioRecord(HOLDINGS);
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(actionProfile.getId()).withContentType(JOB_PROFILE).withContent(actionProfile);
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper);
    assertFalse(createHoldingEventHandler.isEligible(dataImportEventPayload));
}
Also used : HashMap(java.util.HashMap) ActionProfile(org.folio.ActionProfile) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 27 with ActionProfile

use of org.folio.ActionProfile in project mod-inventory by folio-org.

the class UpdateItemEventHandlerTest method shouldReturnFalseWhenHandlerIsNotEligibleForActionProfile.

@Test
public void shouldReturnFalseWhenHandlerIsNotEligibleForActionProfile() {
    // given
    ActionProfile actionProfile = new ActionProfile().withId(UUID.randomUUID().toString()).withName("Create preliminary Item").withAction(ActionProfile.Action.CREATE).withFolioRecord(ActionProfile.FolioRecord.ITEM);
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(jobProfile.getId()).withContentType(ACTION_PROFILE).withContent(actionProfile);
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_ITEM_MATCHED.value()).withCurrentNode(profileSnapshotWrapper);
    // when
    boolean isEligible = updateItemHandler.isEligible(dataImportEventPayload);
    // then
    Assert.assertFalse(isEligible);
}
Also used : ActionProfile(org.folio.ActionProfile) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 28 with ActionProfile

use of org.folio.ActionProfile in project mod-source-record-storage by folio-org.

the class MarcAuthorityDeleteEventHandlerTest method shouldDeleteRecord.

@Test
public void shouldDeleteRecord(TestContext context) {
    Async async = context.async();
    // given
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put("MATCHED_MARC_AUTHORITY", Json.encode(record));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withContext(payloadContext).withTenant(TENANT_ID).withCurrentNode(new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(ACTION_PROFILE).withContent(new ActionProfile().withId(UUID.randomUUID().toString()).withName("Delete Marc Authorities").withAction(DELETE).withFolioRecord(ActionProfile.FolioRecord.MARC_AUTHORITY)));
    recordService.saveRecord(record, TENANT_ID).onSuccess(ar -> eventHandler.handle(dataImportEventPayload).whenComplete((eventPayload, throwable) -> {
        context.assertNull(throwable);
        context.assertEquals(DI_SRS_MARC_AUTHORITY_RECORD_DELETED.value(), eventPayload.getEventType());
        context.assertNull(eventPayload.getContext().get("MATCHED_MARC_AUTHORITY"));
        context.assertEquals(record.getExternalIdsHolder().getAuthorityId(), eventPayload.getContext().get("AUTHORITY_RECORD_ID"));
        recordService.getRecordById(record.getId(), TENANT_ID).onSuccess(optionalDeletedRecord -> {
            context.assertTrue(optionalDeletedRecord.isPresent());
            Record deletedRecord = optionalDeletedRecord.get();
            context.assertTrue(deletedRecord.getDeleted());
            async.complete();
        });
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) EventHandler(org.folio.processing.events.services.handler.EventHandler) RecordDaoImpl(org.folio.dao.RecordDaoImpl) Date(java.util.Date) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) MarcAuthorityDeleteEventHandler(org.folio.services.handlers.actions.MarcAuthorityDeleteEventHandler) MARC_AUTHORITY(org.folio.rest.jaxrs.model.Record.RecordType.MARC_AUTHORITY) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) JsonObject(io.vertx.core.json.JsonObject) ActionProfile(org.folio.ActionProfile) Before(org.junit.Before) Record(org.folio.rest.jaxrs.model.Record) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) NotFoundException(javax.ws.rs.NotFoundException) UPDATE(org.folio.ActionProfile.Action.UPDATE) DI_SRS_MARC_AUTHORITY_RECORD_DELETED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_DELETED) MARC_BIB(org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB) DELETE(org.folio.ActionProfile.Action.DELETE) Assert(org.junit.Assert) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ActionProfile(org.folio.ActionProfile) Test(org.junit.Test)

Example 29 with ActionProfile

use of org.folio.ActionProfile in project mod-source-record-storage by folio-org.

the class MarcAuthorityDeleteEventHandlerTest method shouldCompleteExceptionallyIfNoRecordStored.

@Test
public void shouldCompleteExceptionallyIfNoRecordStored(TestContext context) {
    Async async = context.async();
    // given
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put("MATCHED_MARC_AUTHORITY", Json.encode(record));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withContext(payloadContext).withTenant(TENANT_ID).withCurrentNode(new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(ACTION_PROFILE).withContent(new ActionProfile().withId(UUID.randomUUID().toString()).withName("Delete Marc Authorities").withAction(DELETE).withFolioRecord(ActionProfile.FolioRecord.MARC_AUTHORITY)));
    // when
    CompletableFuture<DataImportEventPayload> future = eventHandler.handle(dataImportEventPayload);
    // then
    future.whenComplete((eventPayload, throwable) -> {
        context.assertNotNull(throwable);
        context.assertEquals(NotFoundException.class, throwable.getClass());
        async.complete();
    });
}
Also used : HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ActionProfile(org.folio.ActionProfile) Test(org.junit.Test)

Example 30 with ActionProfile

use of org.folio.ActionProfile in project mod-source-record-storage by folio-org.

the class MarcAuthorityDeleteEventHandlerTest method actionProfileIsNotEligible.

@Test
public void actionProfileIsNotEligible() {
    // given
    ActionProfile actionProfile = new ActionProfile().withId(UUID.randomUUID().toString()).withName("Delete marc authority").withAction(UPDATE).withFolioRecord(ActionProfile.FolioRecord.MARC_AUTHORITY);
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(actionProfile);
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withTenant(TENANT_ID).withContext(new HashMap<>()).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper);
    // when
    boolean isEligible = eventHandler.isEligible(dataImportEventPayload);
    // then
    Assert.assertFalse(isEligible);
}
Also used : ActionProfile(org.folio.ActionProfile) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Aggregations

ActionProfile (org.folio.ActionProfile)34 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)34 Test (org.junit.Test)33 DataImportEventPayload (org.folio.DataImportEventPayload)32 HashMap (java.util.HashMap)18 Async (io.vertx.ext.unit.Async)5 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)2 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)2 List (java.util.List)2 KeyValue (net.mguenther.kafka.junit.KeyValue)2 JobProfile (org.folio.JobProfile)2 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)2 DataImportEventPayload (org.folio.rest.jaxrs.model.DataImportEventPayload)2 Event (org.folio.rest.jaxrs.model.Event)2 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)2 RawRecord (org.folio.rest.jaxrs.model.RawRecord)2 Record (org.folio.rest.jaxrs.model.Record)2 Json (io.vertx.core.json.Json)1 JsonObject (io.vertx.core.json.JsonObject)1 TestContext (io.vertx.ext.unit.TestContext)1