use of org.folio.rest.jaxrs.model.MappingRule in project mod-inventory by folio-org.
the class CreateItemEventHandlerTest method shouldNotRequestWhenCreatedItemHasEmptyBarcode.
@Test
public void shouldNotRequestWhenCreatedItemHasEmptyBarcode() throws UnsupportedEncodingException {
// given
Mockito.doAnswer(invocationOnMock -> {
Item itemByCql = new Item(null, null, null, new Status(AVAILABLE), null, null, null);
MultipleRecords<Item> result = new MultipleRecords<>(Collections.singletonList(itemByCql), 0);
Consumer<Success<MultipleRecords<Item>>> successHandler = invocationOnMock.getArgument(2);
successHandler.accept(new Success<>(result));
return null;
}).when(mockedItemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new ItemWriterFactory());
JsonObject holdingAsJson = new JsonObject().put("id", UUID.randomUUID().toString());
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(EntityType.HOLDINGS.value(), holdingAsJson.encode());
MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Prelim item from MARC").withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withExistingRecordType(ITEM).withMappingDetails(new MappingDetail().withMappingFields(Arrays.asList(new MappingRule().withPath("item.status.name").withValue("\"statusExpression\"").withEnabled("true"), new MappingRule().withPath("item.permanentLoanType.id").withValue("\"permanentLoanTypeExpression\"").withEnabled("true"), new MappingRule().withPath("item.materialType.id").withValue("\"materialTypeExpression\"").withEnabled("true"))));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(new ProfileSnapshotWrapper().withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(JsonObject.mapFrom(actionProfile).getMap()).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(mappingProfile).getMap()))));
// when
createItemHandler.handle(dataImportEventPayload);
// then
verify(mockedItemCollection, Mockito.times(0)).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
}
use of org.folio.rest.jaxrs.model.MappingRule in project mod-inventory by folio-org.
the class CreateHoldingEventHandlerTest method shouldNotProcessEventIfHoldingRecordIsInvalid.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfHoldingRecordIsInvalid() throws IOException, InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Prelim item from MARC").withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withExistingRecordType(EntityType.HOLDINGS).withMappingDetails(new MappingDetail().withMappingFields(Lists.newArrayList(new MappingRule().withPath("permanentLocationId").withValue("permanentLocationExpression"), new MappingRule().withPath("invalidField").withValue("invalidFieldValue"))));
ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(jobProfile.getId()).withContentType(JOB_PROFILE).withContent(jobProfile).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(actionProfile).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(mappingProfile).getMap())))));
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(UUID.randomUUID().toString()), StringValue.of(UUID.randomUUID().toString()));
when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new HoldingWriterFactory());
String instanceId = String.valueOf(UUID.randomUUID());
Instance instance = new Instance(instanceId, "7", String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
HashMap<String, String> context = new HashMap<>();
context.put("INSTANCE", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(instance)).encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
use of org.folio.rest.jaxrs.model.MappingRule in project mod-inventory by folio-org.
the class UpdateItemEventHandlerTest method shouldReturnFailedFutureWhenMappedItemWithUnrecognizedStatusName.
@Test(expected = ExecutionException.class)
public void shouldReturnFailedFutureWhenMappedItemWithUnrecognizedStatusName() throws InterruptedException, ExecutionException, TimeoutException {
// given
MappingRule statusMappingRule = new MappingRule().withPath("item.status.name").withValue("\"statusExpression\"").withEnabled("true");
when(fakeReader.read(eq(statusMappingRule))).thenReturn(StringValue.of("Invalid status"));
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()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = updateItemHandler.handle(dataImportEventPayload);
// then
future.get(5, TimeUnit.SECONDS);
}
use of org.folio.rest.jaxrs.model.MappingRule in project mod-inventory by folio-org.
the class UpdateItemEventHandlerTest method shouldReturnFailedFutureAndUpdateItemExceptStatusWhenStatusCanNotBeUpdated.
@Test
@Parameters({ "Aged to lost", "Awaiting delivery", "Awaiting pickup", "Checked out", "Claimed returned", "Declared lost", "Paged" })
public void shouldReturnFailedFutureAndUpdateItemExceptStatusWhenStatusCanNotBeUpdated(String protectedItemStatus) throws UnsupportedEncodingException {
// given
doAnswer(invocationOnMock -> {
MultipleRecords<Item> result = new MultipleRecords<>(new ArrayList<>(), 0);
Consumer<Success<MultipleRecords<Item>>> successHandler = invocationOnMock.getArgument(2);
successHandler.accept(new Success<>(result));
return null;
}).when(mockedItemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
String expectedItemBarcode = "BC-123123";
MappingRule barcodeMappingRule = mappingProfile.getMappingDetails().getMappingFields().get(1);
when(fakeReader.read(eq(barcodeMappingRule))).thenReturn(StringValue.of(expectedItemBarcode));
existingItemJson.put(STATUS_KEY, new JsonObject().put("name", protectedItemStatus));
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()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = updateItemHandler.handle(dataImportEventPayload);
// then
Assert.assertTrue(future.isCompletedExceptionally());
JsonObject updatedItem = new JsonObject(payloadContext.get(ITEM.value()));
Assert.assertEquals(protectedItemStatus, updatedItem.getJsonObject(STATUS_KEY).getString("name"));
Assert.assertEquals(expectedItemBarcode, updatedItem.getString(ItemUtil.BARCODE));
}
use of org.folio.rest.jaxrs.model.MappingRule in project mod-inventory by folio-org.
the class CreateMarcHoldingsEventHandlerTest method shouldNotProcessEventIfHoldingRecordIsInvalid.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfHoldingRecordIsInvalid() throws IOException, InterruptedException, ExecutionException, TimeoutException {
MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Prelim item from MARC").withIncomingRecordType(EntityType.MARC_HOLDINGS).withExistingRecordType(EntityType.HOLDINGS).withMappingDetails(new MappingDetail().withMappingFields(Lists.newArrayList(new MappingRule().withPath("permanentLocationId").withValue("permanentLocationExpression"), new MappingRule().withPath("invalidField").withValue("invalidFieldValue"))));
ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(jobProfile.getId()).withContentType(JOB_PROFILE).withContent(jobProfile).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(actionProfile).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(mappingProfile).getMap())))));
when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
HoldingsRecord holdings = new HoldingsRecord().withId(String.valueOf(UUID.randomUUID())).withHrid(String.valueOf(UUID.randomUUID())).withInstanceId(String.valueOf(UUID.randomUUID())).withSourceId(String.valueOf(UUID.randomUUID())).withHoldingsTypeId(String.valueOf(UUID.randomUUID())).withPermanentLocationId(PERMANENT_LOCATION_ID);
var parsedHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(PARSED_HOLDINGS_RECORD));
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(parsedHoldingsRecord.encode()));
HashMap<String, String> context = new HashMap<>();
context.put("HOLDINGS", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(holdings)).encode());
context.put(MARC_HOLDINGS.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withContext(context).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = createMarcHoldingsEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
Aggregations