Search in sources :

Example 1 with HoldingsType

use of org.folio.HoldingsType in project mod-inventory by folio-org.

the class QuickMarcKafkaHandlerTest method shouldSendHoldingsUpdatedEvent.

@Test
public void shouldSendHoldingsUpdatedEvent(TestContext context) throws InterruptedException {
    List<HoldingsType> holdings = new ArrayList<>();
    holdings.add(new HoldingsType().withName("testingnote$a"));
    MappingParameters mappingParameters = new MappingParameters();
    mappingParameters.withHoldingsTypes(holdings);
    // given
    Async async = context.async();
    Map<String, String> payload = new HashMap<>();
    payload.put("RECORD_TYPE", "MARC_HOLDING");
    payload.put("MARC_HOLDING", Json.encode(holdingsRecord));
    payload.put("MAPPING_RULES", holdingsMappingRules.encode());
    payload.put("MAPPING_PARAMS", Json.encode(mappingParameters));
    payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_HOLDING).withRelatedRecordVersion("1")));
    Event event = new Event().withId("01").withEventPayload(Json.encode(payload));
    String expectedKafkaRecordKey = "test_key";
    when(kafkaRecord.key()).thenReturn(expectedKafkaRecordKey);
    when(kafkaRecord.value()).thenReturn(Json.encode(event));
    // when
    Future<String> future = handler.handle(kafkaRecord);
    // then
    String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_INVENTORY_HOLDINGS_UPDATED.name());
    cluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
    future.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        context.assertEquals(expectedKafkaRecordKey, ar.result());
        async.complete();
    });
}
Also used : HoldingsType(org.folio.HoldingsType) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) ArrayList(java.util.ArrayList) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) Event(org.folio.rest.jaxrs.model.Event) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with HoldingsType

use of org.folio.HoldingsType in project mod-source-record-manager by folio-org.

the class MappingParametersProvider method getHoldingsTypes.

private Future<List<HoldingsType>> getHoldingsTypes(OkapiConnectionParams params) {
    Promise<List<HoldingsType>> promise = Promise.promise();
    String holdingsTypesUrl = "/holdings-types?limit=" + settingsLimit;
    RestUtil.doRequest(params, holdingsTypesUrl, HttpMethod.GET, null).onComplete(ar -> {
        if (RestUtil.validateAsyncResult(ar, promise)) {
            JsonObject response = ar.result().getJson();
            if (response != null && response.containsKey(HOLDINGS_TYPES_RESPONSE_PARAM)) {
                List<HoldingsType> holdingsTypes = response.mapTo(Holdingstypes.class).getHoldingsTypes();
                promise.complete(holdingsTypes);
            } else {
                promise.complete(Collections.emptyList());
            }
        }
    });
    return promise.future();
}
Also used : Holdingstypes(org.folio.Holdingstypes) HoldingsType(org.folio.HoldingsType) JsonObject(io.vertx.core.json.JsonObject) List(java.util.List)

Example 3 with HoldingsType

use of org.folio.HoldingsType in project mod-inventory by folio-org.

the class MarcHoldingsRecordHridSetKafkaHandlerTest method setUp.

@Before
public void setUp() throws IOException {
    mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
    existingHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(HOLDINGS_PATH)).mapTo(HoldingsRecord.class);
    record = Json.decodeValue(TestUtil.readFileFromPath(RECORD_PATH), Record.class);
    record.getParsedRecord().withContent(JsonObject.mapFrom(record.getParsedRecord().getContent()).encode());
    mocks = MockitoAnnotations.openMocks(this);
    when(mockedStorage.getHoldingsRecordCollection(any(Context.class))).thenReturn(mockedHoldingsCollection);
    doAnswer(invocationOnMock -> {
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(existingHoldingsRecord));
        return null;
    }).when(mockedHoldingsCollection).findById(anyString(), any(), any());
    doAnswer(invocationOnMock -> {
        HoldingsRecord holdingsRecord = invocationOnMock.getArgument(0);
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(holdingsRecord));
        return null;
    }).when(mockedHoldingsCollection).update(any(HoldingsRecord.class), any(), any());
    List<HoldingsType> holdings = new ArrayList<>();
    holdings.add(new HoldingsType().withName("testingnote$a").withId("5f694a63-1bd4-4002-9f38-09170eb7aa62"));
    MappingParameters mappingParameters = new MappingParameters();
    mappingParameters.withHoldingsTypes(holdings);
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters)).withMappingRules(mappingRules.encode())))));
    MappingMetadataCache mappingMetadataCache = new MappingMetadataCache(vertx, vertx.createHttpClient(), 3600);
    marcHoldingsRecordHridSetKafkaHandler = new MarcHoldingsRecordHridSetKafkaHandler(new HoldingsUpdateDelegate(mockedStorage), mappingMetadataCache);
    this.okapiHeaders = List.of(KafkaHeader.header(OKAPI_TENANT_HEADER, "diku"), KafkaHeader.header(OKAPI_URL_HEADER, mockServer.baseUrl()));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Context(org.folio.inventory.common.Context) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) HoldingsUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate) Success(org.folio.inventory.common.domain.Success) HoldingsRecord(org.folio.HoldingsRecord) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) HoldingsType(org.folio.HoldingsType) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) HoldingsRecord(org.folio.HoldingsRecord) KafkaConsumerRecord(io.vertx.kafka.client.consumer.KafkaConsumerRecord) Record(org.folio.rest.jaxrs.model.Record) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Example 4 with HoldingsType

use of org.folio.HoldingsType in project mod-inventory by folio-org.

the class UpdateHoldingsQuickMarcEventHandlerTest method shouldProcessEvent.

@Test
public void shouldProcessEvent() {
    List<HoldingsType> holdings = new ArrayList<>();
    holdings.add(new HoldingsType().withName("testingnote$a").withId("fe19bae4-da28-472b-be90-d442e2428eadx"));
    MappingParameters mappingParameters = new MappingParameters();
    mappingParameters.withHoldingsTypes(holdings);
    HashMap<String, String> eventPayload = new HashMap<>();
    eventPayload.put("RECORD_TYPE", "MARC_HOLDING");
    eventPayload.put("MARC_HOLDING", record.encode());
    eventPayload.put("MAPPING_RULES", mappingRules.encode());
    eventPayload.put("MAPPING_PARAMS", Json.encode(mappingParameters));
    eventPayload.put("RELATED_RECORD_VERSION", HOLDINGS_VERSION.toString());
    Future<HoldingsRecord> future = updateHoldingsQuickMarcEventHandler.handle(eventPayload);
    HoldingsRecord updatedHoldings = future.result();
    Assert.assertNotNull(updatedHoldings);
    Assert.assertEquals(HOLDINGS_ID, updatedHoldings.getId());
    Assert.assertEquals(HOLDINGS_VERSION, updatedHoldings.getVersion());
    Assert.assertNull(updatedHoldings.getHoldingsTypeId());
    Assert.assertNotNull(updatedHoldings.getHoldingsStatements());
    Assert.assertEquals(21, updatedHoldings.getHoldingsStatements().size());
    Assert.assertNotNull(updatedHoldings.getNotes());
    Assert.assertEquals("testingnote$a ; testingnote$u ; testingnote$3 ; testingnote$5 ; testingnote$6 ; testingnote$8", updatedHoldings.getNotes().get(0).getNote());
    ArgumentCaptor<Context> argument = ArgumentCaptor.forClass(Context.class);
    verify(holdingsUpdateDelegate).handle(any(), any(), argument.capture());
    Assert.assertEquals("token", argument.getValue().getToken());
    Assert.assertEquals("dummy", argument.getValue().getTenantId());
    Assert.assertEquals("http://localhost", argument.getValue().getOkapiLocation());
}
Also used : Context(org.folio.inventory.common.Context) HoldingsRecord(org.folio.HoldingsRecord) HoldingsType(org.folio.HoldingsType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 5 with HoldingsType

use of org.folio.HoldingsType in project mod-inventory by folio-org.

the class UpdateHoldingsQuickMarcEventHandlerTest 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(holdingsRecordCollection).update(any(), any(), any());
    List<HoldingsType> holdings = new ArrayList<>();
    holdings.add(new HoldingsType().withName("testingnote$a").withId("fe19bae4-da28-472b-be90-d442e2428eadx"));
    MappingParameters mappingParameters = new MappingParameters();
    mappingParameters.withHoldingsTypes(holdings);
    HashMap<String, String> eventPayload = new HashMap<>();
    eventPayload.put("RECORD_TYPE", "MARC_HOLDING");
    eventPayload.put("MARC_HOLDING", record.encode());
    eventPayload.put("MAPPING_RULES", mappingRules.encode());
    eventPayload.put("MAPPING_PARAMS", Json.encode(mappingParameters));
    Future<HoldingsRecord> future = updateHoldingsQuickMarcEventHandler.handle(eventPayload);
    Assert.assertTrue(future.failed());
}
Also used : HoldingsRecord(org.folio.HoldingsRecord) HoldingsType(org.folio.HoldingsType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Aggregations

HoldingsType (org.folio.HoldingsType)5 ArrayList (java.util.ArrayList)4 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)4 HashMap (java.util.HashMap)3 HoldingsRecord (org.folio.HoldingsRecord)3 Test (org.junit.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 JsonObject (io.vertx.core.json.JsonObject)2 Context (org.folio.inventory.common.Context)2 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)1 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 KafkaConsumerRecord (io.vertx.kafka.client.consumer.KafkaConsumerRecord)1 List (java.util.List)1 Holdingstypes (org.folio.Holdingstypes)1 MappingMetadataDto (org.folio.MappingMetadataDto)1 Failure (org.folio.inventory.common.domain.Failure)1 Success (org.folio.inventory.common.domain.Success)1 MappingMetadataCache (org.folio.inventory.dataimport.cache.MappingMetadataCache)1