use of org.folio.Authority in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldMatchOnHandleEventPayloadFor999s.
@Test
public void shouldMatchOnHandleEventPayloadFor999s(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
MatchValueReaderFactory.clearReaderFactory();
MatchDetail matchDetail999s = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("idField").withValue("authority.id"))));
DataImportEventPayload eventPayload = createEventPayload(matchDetail999s);
MarcValueReaderImpl marcValueReaderMock = Mockito.mock(MarcValueReaderImpl.class);
when(marcValueReaderMock.isEligibleForEntityType(MARC_AUTHORITY)).thenReturn(true);
when(marcValueReaderMock.read(eventPayload, matchDetail999s)).thenReturn(StringValue.of(AUTHORITY_ID));
MatchValueReaderFactory.register(marcValueReaderMock);
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Authority>>> callback = ans.getArgument(2);
Success<MultipleRecords<Authority>> result = new Success<>(new MultipleRecords<>(singletonList(createAuthority()), 1));
callback.accept(result);
return null;
}).when(collection).findByCql(eq(format("id == \"%s\"", AUTHORITY_ID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_AUTHORITY_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.Authority in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldMatchOnHandleEventPayloadFor001.
@Test
public void shouldMatchOnHandleEventPayloadFor001(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
MatchValueReaderFactory.clearReaderFactory();
MatchDetail matchDetail001 = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("identifiersField").withValue("authority.identifiers[]"))));
DataImportEventPayload eventPayload = createEventPayload(matchDetail001);
MarcValueReaderImpl marcValueReaderMock = Mockito.mock(MarcValueReaderImpl.class);
when(marcValueReaderMock.isEligibleForEntityType(MARC_AUTHORITY)).thenReturn(true);
when(marcValueReaderMock.read(eventPayload, matchDetail001)).thenReturn(ListValue.of(singletonList(JsonObject.mapFrom(IDENTIFIER).toString())));
MatchValueReaderFactory.register(marcValueReaderMock);
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Authority>>> callback = ans.getArgument(2);
Success<MultipleRecords<Authority>> result = new Success<>(new MultipleRecords<>(singletonList(createAuthority()), 1));
callback.accept(result);
return null;
}).when(collection).findByCql(eq("identifiers=\\\"[{\\\"value\\\":\\\"955335\\\",\\\"identifierTypeId\\\":\\\"11bf5f7c-30e1-4308-8170-1fbb5b817cf2\\\"}]\\\""), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_AUTHORITY_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.Authority in project mod-inventory by folio-org.
the class UpdateAuthorityQuickMarcEventHandlerTest method shouldSendError.
@Test
public void shouldSendError() {
doAnswer(invocationOnMock -> {
Consumer<Failure> failureHandler = invocationOnMock.getArgument(2);
failureHandler.accept(new Failure("Internal Server Error", 500));
return null;
}).when(authorityRecordCollection).update(any(), any(), any());
HashMap<String, String> eventPayload = new HashMap<>();
eventPayload.put("RECORD_TYPE", "MARC_AUTHORITY");
eventPayload.put("MARC_AUTHORITY", record.encode());
eventPayload.put("MAPPING_RULES", mappingRules.encode());
eventPayload.put("MAPPING_PARAMS", new JsonObject().encode());
Future<Authority> future = updateAuthorityQuickMarcEventHandler.handle(eventPayload);
Assert.assertTrue(future.failed());
}
use of org.folio.Authority in project mod-inventory by folio-org.
the class ExternalStorageModuleAuthorityRecordCollectionExamples method shouldMapToRequest.
@Test
public void shouldMapToRequest() {
Authority authority = new Authority().withId(AUTHORITY_ID).withVersion(Integer.valueOf(VERSION)).withCorporateName(CORPORATE_NAME);
JsonObject jsonObject = storage.mapToRequest(authority);
assertNotNull(jsonObject);
assertEquals(AUTHORITY_ID, jsonObject.getString("id"));
assertEquals(VERSION.toString(), jsonObject.getString("_version"));
assertEquals(CORPORATE_NAME, jsonObject.getString("corporateName"));
}
use of org.folio.Authority in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldMatchWithSubConditionBasedOnMultiMatchResultOnHandleEventPayload.
@Test
public void shouldMatchWithSubConditionBasedOnMultiMatchResultOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
List<String> multiMatchResult = List.of(UUID.randomUUID().toString(), UUID.randomUUID().toString());
Authority expectedAuthority = createAuthority();
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<>(singletonList(expectedAuthority), 1));
successHandler.accept(result);
return null;
}).when(collection).findByCql(eq(format("personalName == \"%s\" AND id == (%s OR %s)", PERSONAL_NAME, multiMatchResult.get(0), multiMatchResult.get(1))), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
HashMap<String, String> context = new HashMap<>();
context.put(MULTI_MATCH_IDS, Json.encode(multiMatchResult));
context.put("MAPPING_PARAMS", new JsonObject().encode());
DataImportEventPayload eventPayload = createEventPayload(personalNameMatchDetail).withContext(context);
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), List.of(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_AUTHORITY_MATCHED.value(), updatedEventPayload.getEventType());
testContext.assertEquals(Json.decodeValue(updatedEventPayload.getContext().get(AUTHORITY.value()), Authority.class).getId(), expectedAuthority.getId());
async.complete();
});
}
Aggregations