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));
}
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());
}
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());
}
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());
}
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());
}
Aggregations