Search in sources :

Example 16 with Authority

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();
    });
}
Also used : MarcValueReaderImpl(org.folio.processing.matching.reader.MarcValueReaderImpl) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Authority(org.folio.Authority) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Field(org.folio.rest.jaxrs.model.Field) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) MatchDetail(org.folio.MatchDetail) Test(org.junit.Test)

Example 17 with Authority

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();
    });
}
Also used : MarcValueReaderImpl(org.folio.processing.matching.reader.MarcValueReaderImpl) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Authority(org.folio.Authority) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Field(org.folio.rest.jaxrs.model.Field) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) MatchDetail(org.folio.MatchDetail) Test(org.junit.Test)

Example 18 with Authority

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());
}
Also used : HashMap(java.util.HashMap) Authority(org.folio.Authority) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Example 19 with Authority

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"));
}
Also used : Authority(org.folio.Authority) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 20 with Authority

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();
    });
}
Also used : PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Authority(org.folio.Authority) HashMap(java.util.HashMap) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Field(org.folio.rest.jaxrs.model.Field) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) MatchDetail(org.folio.MatchDetail) Test(org.junit.Test)

Aggregations

Authority (org.folio.Authority)20 JsonObject (io.vertx.core.json.JsonObject)13 Test (org.junit.Test)13 Success (org.folio.inventory.common.domain.Success)11 Async (io.vertx.ext.unit.Async)8 Consumer (java.util.function.Consumer)8 DataImportEventPayload (org.folio.DataImportEventPayload)8 MatchDetail (org.folio.MatchDetail)8 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)8 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)8 MatchAuthorityEventHandler (org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler)8 EventHandler (org.folio.processing.events.services.handler.EventHandler)8 Field (org.folio.rest.jaxrs.model.Field)8 MatchExpression (org.folio.rest.jaxrs.model.MatchExpression)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 HashMap (java.util.HashMap)5 Context (org.folio.inventory.common.Context)4 Before (org.junit.Before)4 Future (io.vertx.core.Future)2 TestContext (io.vertx.ext.unit.TestContext)2