use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper 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.ProfileSnapshotWrapper in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldPutMultipleMatchResultToPayloadOnHandleEventPayload.
@Test
public void shouldPutMultipleMatchResultToPayloadOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
List<Authority> matchedAuthorities = List.of(new Authority().withId(AUTHORITY_ID), new Authority().withId(UUID.randomUUID().toString()));
MatchDetail personalNameMatchDetail = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("personalName").withValue("authority.personalName"))));
doAnswer(invocation -> {
Consumer<Success<MultipleRecords<Authority>>> successHandler = invocation.getArgument(2);
Success<MultipleRecords<Authority>> result = new Success<>(new MultipleRecords<>(matchedAuthorities, 2));
successHandler.accept(result);
return null;
}).when(collection).findByCql(eq(format("personalName == \"%s\"", PERSONAL_NAME)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
HashMap<String, String> context = new HashMap<>();
context.put("MAPPING_PARAMS", new JsonObject().encode());
DataImportEventPayload eventPayload = createEventPayload(personalNameMatchDetail).withContext(context);
eventPayload.getCurrentNode().setChildSnapshotWrappers(List.of(new ProfileSnapshotWrapper().withContent(new MatchProfile().withExistingRecordType(AUTHORITY).withIncomingRecordType(MARC_BIBLIOGRAPHIC)).withContentType(MATCH_PROFILE).withReactTo(MATCH)));
eventHandler.handle(eventPayload).whenComplete((processedPayload, throwable) -> testContext.verify(v -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, processedPayload.getEventsChain().size());
testContext.assertEquals(processedPayload.getEventsChain(), List.of(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_AUTHORITY_MATCHED.value(), processedPayload.getEventType());
assertThat(new JsonArray(processedPayload.getContext().get(MULTI_MATCH_IDS)), hasItems(matchedAuthorities.get(0).getId(), matchedAuthorities.get(1).getId()));
async.complete();
}));
}
use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldReturnFalseOnIsEligibleForNotAuthorityMatchProfile.
@Test
public void shouldReturnFalseOnIsEligibleForNotAuthorityMatchProfile() {
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = new DataImportEventPayload().withCurrentNode(new ProfileSnapshotWrapper().withContentType(MATCH_PROFILE).withContent(JsonObject.mapFrom(new MatchProfile().withExistingRecordType(MARC_AUTHORITY))));
assertFalse(eventHandler.isEligible(eventPayload));
}
use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest method shouldReturnFalseOnIsEligibleForNotItemMatchProfile.
@Test
public void shouldReturnFalseOnIsEligibleForNotItemMatchProfile() {
EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = new DataImportEventPayload().withCurrentNode(new ProfileSnapshotWrapper().withContentType(MATCH_PROFILE).withContent(JsonObject.mapFrom(new MatchProfile().withExistingRecordType(MARC_BIBLIOGRAPHIC))));
assertFalse(eventHandler.isEligible(eventPayload));
}
use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest method shouldReturnTrueOnIsEligibleForItemMatchProfile.
@Test
public void shouldReturnTrueOnIsEligibleForItemMatchProfile() {
EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = new DataImportEventPayload().withCurrentNode(new ProfileSnapshotWrapper().withContentType(MATCH_PROFILE).withContent(JsonObject.mapFrom(new MatchProfile().withExistingRecordType(ITEM))));
assertTrue(eventHandler.isEligible(eventPayload));
}
Aggregations