Search in sources :

Example 26 with ProfileSnapshotWrapper

use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper 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 27 with ProfileSnapshotWrapper

use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.

the class UpdateHoldingEventHandlerTest method shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile.

@Test
public void shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile() {
    HashMap<String, String> context = new HashMap<>();
    Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_INSTANCE_ID));
    context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
    context.put(HOLDINGS.value(), Json.encode(new HoldingsRecord()));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_MATCHED.value()).withContext(context).withCurrentNode(new ProfileSnapshotWrapper().withContent(JsonObject.mapFrom(actionProfile).getMap()).withContentType(ACTION_PROFILE));
    CompletableFuture<DataImportEventPayload> future = updateHoldingEventHandler.handle(dataImportEventPayload);
    ExecutionException exception = Assert.assertThrows(ExecutionException.class, future::get);
    Assert.assertEquals(ACTION_HAS_NO_MAPPING_MSG, exception.getCause().getMessage());
}
Also used : HoldingsRecord(org.folio.HoldingsRecord) HashMap(java.util.HashMap) HoldingsRecord(org.folio.HoldingsRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Record(org.folio.rest.jaxrs.model.Record) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ExecutionException(java.util.concurrent.ExecutionException) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Example 28 with ProfileSnapshotWrapper

use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.

the class UpdateItemEventHandlerTest method shouldReturnFailedFutureWhenCurrentActionProfileHasNoMappingProfile.

@Test
public void shouldReturnFailedFutureWhenCurrentActionProfileHasNoMappingProfile() {
    // given
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
    payloadContext.put(ITEM.value(), existingItemJson.encode());
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_ITEM_MATCHED.value()).withContext(payloadContext).withCurrentNode(new ProfileSnapshotWrapper().withContent(JsonObject.mapFrom(actionProfile).getMap()).withContentType(ACTION_PROFILE));
    // when
    CompletableFuture<DataImportEventPayload> future = updateItemHandler.handle(dataImportEventPayload);
    // then
    ExecutionException exception = Assert.assertThrows(ExecutionException.class, future::get);
    Assert.assertEquals(ACTION_HAS_NO_MAPPING_MSG, exception.getCause().getMessage());
}
Also used : HashMap(java.util.HashMap) HoldingsRecord(org.folio.HoldingsRecord) Record(org.folio.rest.jaxrs.model.Record) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ExecutionException(java.util.concurrent.ExecutionException) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Example 29 with ProfileSnapshotWrapper

use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-invoice by folio-org.

the class JobProfileSnapshotCacheTest method shouldReturnProfileSnapshot.

@Test
public void shouldReturnProfileSnapshot() throws InterruptedException, ExecutionException, TimeoutException {
    addMockEntry(JOB_PROFILE_SNAPSHOTS_MOCK, jobProfileSnapshot);
    CompletableFuture<Optional<ProfileSnapshotWrapper>> optionalFuture = jobProfileSnapshotCache.get(jobProfileSnapshot.getId(), this.okapiHeaders);
    Optional<ProfileSnapshotWrapper> profileOptional = optionalFuture.get(5, TimeUnit.SECONDS);
    Assertions.assertTrue(profileOptional.isPresent());
    ProfileSnapshotWrapper actualProfileSnapshot = profileOptional.get();
    Assertions.assertEquals(jobProfileSnapshot.getId(), actualProfileSnapshot.getId());
    Assertions.assertFalse(actualProfileSnapshot.getChildSnapshotWrappers().isEmpty());
    Assertions.assertEquals(jobProfileSnapshot.getChildSnapshotWrappers().get(0).getId(), actualProfileSnapshot.getChildSnapshotWrappers().get(0).getId());
}
Also used : Optional(java.util.Optional) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.jupiter.api.Test)

Example 30 with ProfileSnapshotWrapper

use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-invoice by folio-org.

the class CreateInvoiceEventHandlerTest method shouldPublishDiErrorEventWhenPostInvoiceToStorageFailed.

@Test
public void shouldPublishDiErrorEventWhenPostInvoiceToStorageFailed() throws InterruptedException {
    // given
    ProfileSnapshotWrapper profileSnapshotWrapper = buildProfileSnapshotWrapper(jobProfile, actionProfile, mappingProfile);
    addMockEntry(JOB_PROFILE_SNAPSHOTS_MOCK, profileSnapshotWrapper);
    Record record = new Record().withParsedRecord(new ParsedRecord().withContent(EDIFACT_PARSED_CONTENT)).withId(UUID.randomUUID().toString());
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(EDIFACT_INVOICE.value(), Json.encode(record));
    payloadContext.put(JOB_PROFILE_SNAPSHOT_ID_KEY, profileSnapshotWrapper.getId());
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_EDIFACT_RECORD_CREATED.value()).withTenant(ERROR_TENANT).withOkapiUrl(OKAPI_URL).withToken(TOKEN).withContext(payloadContext);
    String topic = KafkaTopicNameHelper.formatTopicName(KAFKA_ENV_VALUE, getDefaultNameSpace(), ERROR_TENANT, dataImportEventPayload.getEventType());
    Event event = new Event().withEventPayload(Json.encode(dataImportEventPayload));
    KeyValue<String, String> kafkaRecord = new KeyValue<>("test-key", Json.encode(event));
    kafkaRecord.addHeader(RECORD_ID_HEADER, record.getId(), UTF_8);
    SendKeyValues<String, String> request = SendKeyValues.to(topic, Collections.singletonList(kafkaRecord)).useDefaults();
    // when
    kafkaCluster.send(request);
    // then
    String topicToObserve = KafkaTopicNameHelper.formatTopicName(KAFKA_ENV_VALUE, getDefaultNameSpace(), ERROR_TENANT, DI_ERROR.value());
    List<String> observedValues = kafkaCluster.observeValues(ObserveKeyValues.on(topicToObserve, 1).with(ConsumerConfig.GROUP_ID_CONFIG, GROUP_ID).observeFor(30, TimeUnit.SECONDS).build());
    Event publishedEvent = Json.decodeValue(observedValues.get(0), Event.class);
    DataImportEventPayload eventPayload = Json.decodeValue(publishedEvent.getEventPayload(), DataImportEventPayload.class);
    assertEquals(DI_INVOICE_CREATED.value(), eventPayload.getEventsChain().get(eventPayload.getEventsChain().size() - 1));
    assertNotNull(eventPayload.getContext().get(ERROR_MSG_KEY));
    assertNotNull(eventPayload.getContext().get(INVOICE.value()));
    assertNotNull(eventPayload.getContext().get(INVOICE_LINES_KEY));
    assertNotNull(eventPayload.getContext().get(EDIFACT_INVOICE.value()));
    Record sourceRecord = Json.decodeValue(eventPayload.getContext().get(EDIFACT_INVOICE.value()), Record.class);
    assertNull(sourceRecord.getParsedRecord());
    assertNull(sourceRecord.getRawRecord());
    InvoiceLineCollection invoiceLineCollection = Json.decodeValue(eventPayload.getContext().get(INVOICE_LINES_KEY), InvoiceLineCollection.class);
    assertEquals(3, invoiceLineCollection.getTotalRecords());
    assertEquals(3, invoiceLineCollection.getInvoiceLines().size());
}
Also used : KeyValue(net.mguenther.kafka.junit.KeyValue) HashMap(java.util.HashMap) ParsedRecord(org.folio.ParsedRecord) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) Event(org.folio.rest.jaxrs.model.Event) ParsedRecord(org.folio.ParsedRecord) Record(org.folio.Record) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection) Test(org.junit.jupiter.api.Test)

Aggregations

ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)120 DataImportEventPayload (org.folio.DataImportEventPayload)106 Test (org.junit.Test)100 HashMap (java.util.HashMap)77 ActionProfile (org.folio.ActionProfile)34 Record (org.folio.rest.jaxrs.model.Record)32 Async (io.vertx.ext.unit.Async)29 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)29 MatchProfile (org.folio.MatchProfile)28 JsonObject (io.vertx.core.json.JsonObject)27 EventHandler (org.folio.processing.events.services.handler.EventHandler)23 MappingProfile (org.folio.MappingProfile)22 List (java.util.List)18 RawRecord (org.folio.rest.jaxrs.model.RawRecord)18 ArrayList (java.util.ArrayList)16 Before (org.junit.Before)16 Json (io.vertx.core.json.Json)15 TestContext (io.vertx.ext.unit.TestContext)15 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)15 UUID (java.util.UUID)15