use of org.folio.inventory.common.domain.Success in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldMatchWithSubMatchByAuthorityOnHandleEventPayload.
@Test
public void shouldMatchWithSubMatchByAuthorityOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
MatchDetail personalNameMatchDetail = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("personalName").withValue("authority.personalName"))));
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("personalName == \"%s\" AND id == \"%s\"", PERSONAL_NAME, AUTHORITY_ID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
HashMap<String, String> context = new HashMap<>();
context.put(AUTHORITY.value(), JsonObject.mapFrom(createAuthority()).encode());
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(), singletonList(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_AUTHORITY_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.inventory.common.domain.Success in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldMatchOnHandleEventPayload.
@Test
public void shouldMatchOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
MatchDetail personalNameMatchDetail = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("personalName").withValue("authority.personalName"))));
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("personalName == \"%s\"", PERSONAL_NAME)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = createEventPayload(personalNameMatchDetail);
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.inventory.common.domain.Success in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldNotMatchOnHandleEventPayload.
@Test
public void shouldNotMatchOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
MatchDetail personalNameMatchDetail = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("personalName").withValue("authority.personalName"))));
DataImportEventPayload eventPayload = createEventPayload(personalNameMatchDetail);
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Authority>>> callback = ans.getArgument(2);
Success<MultipleRecords<Authority>> result = new Success<>(new MultipleRecords<>(new ArrayList<>(), 0));
callback.accept(result);
return null;
}).when(collection).findByCql(anyString(), 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_NOT_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.inventory.common.domain.Success in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest method shouldNotMatchOnHandleEventPayload.
@Test
public void shouldNotMatchOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<HoldingsRecord>>> callback = ans.getArgument(2);
Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(new ArrayList<>(), 0));
callback.accept(result);
return null;
}).when(holdingCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = createEventPayload();
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_HOLDING_NOT_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.inventory.common.domain.Success in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest method shouldFailOnHandleEventPayloadIfMatchedMultipleHoldings.
@Test
public void shouldFailOnHandleEventPayloadIfMatchedMultipleHoldings(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<HoldingsRecord>>> callback = ans.getArgument(2);
Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(asList(createHolding(), createHolding()), 2));
callback.accept(result);
return null;
}).when(holdingCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = createEventPayload();
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNotNull(throwable);
async.complete();
});
}
Aggregations