Search in sources :

Example 6 with ActionProfile

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

the class CreateAuthorityEventHandlerTest method isEligibleShouldReturnFalseIfActionIsNotCreate.

@Test
public void isEligibleShouldReturnFalseIfActionIsNotCreate() {
    ActionProfile actionProfile = new ActionProfile().withId(UUID.randomUUID().toString()).withName("Create preliminary Item").withAction(ActionProfile.Action.UPDATE).withFolioRecord(AUTHORITY);
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(actionProfile.getId()).withContentType(JOB_PROFILE).withContent(actionProfile);
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()).withContext(new HashMap<>()).withProfileSnapshot(profileSnapshotWrapper);
    assertFalse(createMarcAuthoritiesEventHandler.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 7 with ActionProfile

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

the class UpdateHoldingEventHandlerTest method isEligibleShouldReturnFalseIfActionIsNotCreate.

@Test
public void isEligibleShouldReturnFalseIfActionIsNotCreate() {
    ActionProfile actionProfile = new ActionProfile().withId(UUID.randomUUID().toString()).withName("Update 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_UPDATED.value()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper);
    assertFalse(updateHoldingEventHandler.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 8 with ActionProfile

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

the class CreateInvoiceEventHandlerTest method shouldReturnFalseWhenHandlerIsNotEligibleForActionProfile.

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

Example 9 with ActionProfile

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

the class DataImportConsumersVerticleTest method shouldDeleteMarcAuthorityRecord.

@Test
public void shouldDeleteMarcAuthorityRecord() throws InterruptedException {
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(JOB_PROFILE).withContent(JsonObject.mapFrom(new JobProfile().withId(UUID.randomUUID().toString()).withDataType(JobProfile.DataType.MARC)).getMap()).withChildSnapshotWrappers(List.of(new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(ACTION_PROFILE).withOrder(0).withContent(JsonObject.mapFrom(new ActionProfile().withId(UUID.randomUUID().toString()).withAction(DELETE).withFolioRecord(ActionProfile.FolioRecord.MARC_AUTHORITY)).getMap())));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(PROFILE_SNAPSHOT_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(profileSnapshotWrapper))));
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put("MATCHED_MARC_AUTHORITY", Json.encode(record));
    payloadContext.put(PROFILE_SNAPSHOT_ID_KEY, profileSnapshotWrapper.getId());
    var eventPayload = new DataImportEventPayload().withContext(payloadContext).withOkapiUrl(mockServer.baseUrl()).withTenant(TENANT_ID).withToken(TOKEN).withJobExecutionId(snapshotId).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
    String topic = getTopicName(DI_MARC_FOR_DELETE_RECEIVED.value());
    KeyValue<String, String> kafkaRecord = buildKafkaRecord(eventPayload);
    kafkaRecord.addHeader(RECORD_ID_HEADER, record.getId(), UTF_8);
    kafkaRecord.addHeader(CHUNK_ID_HEADER, UUID.randomUUID().toString(), UTF_8);
    var request = SendKeyValues.to(topic, singletonList(kafkaRecord)).useDefaults();
    // when
    cluster.send(request);
    String observeTopic = getTopicName(DI_SRS_MARC_AUTHORITY_RECORD_DELETED.name());
    List<KeyValue<String, String>> observedRecords = cluster.observe(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
    Event obtainedEvent = Json.decodeValue(observedRecords.get(0).getValue(), Event.class);
    var resultPayload = Json.decodeValue(obtainedEvent.getEventPayload(), DataImportEventPayload.class);
    assertEquals(DI_SRS_MARC_AUTHORITY_RECORD_DELETED.value(), resultPayload.getEventType());
    assertEquals(record.getExternalIdsHolder().getAuthorityId(), resultPayload.getContext().get("AUTHORITY_RECORD_ID"));
    assertEquals(ACTION_PROFILE, resultPayload.getCurrentNode().getContentType());
}
Also used : KeyValue(net.mguenther.kafka.junit.KeyValue) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) HashMap(java.util.HashMap) JobProfile(org.folio.JobProfile) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.rest.jaxrs.model.DataImportEventPayload) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Event(org.folio.rest.jaxrs.model.Event) ActionProfile(org.folio.ActionProfile) Test(org.junit.Test) AbstractLBServiceTest(org.folio.services.AbstractLBServiceTest)

Example 10 with ActionProfile

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

the class HoldingsPostProcessingEventHandlerTest method shouldReturnFalseWhenHandlerIsNotEligibleForProfile.

@Test
public void shouldReturnFalseWhenHandlerIsNotEligibleForProfile() {
    ActionProfile actionProfile = new ActionProfile().withId(UUID.randomUUID().toString()).withName("Create holdings").withAction(ActionProfile.Action.CREATE).withFolioRecord(ActionProfile.FolioRecord.HOLDINGS);
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(actionProfile);
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withTenant(TENANT_ID).withEventType(DI_SRS_MARC_HOLDING_RECORD_CREATED.value()).withContext(new HashMap<>()).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper);
    boolean isEligible = handler.isEligible(dataImportEventPayload);
    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