Search in sources :

Example 11 with ParsedRecordDto

use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-inventory by folio-org.

the class QuickMarcKafkaHandlerTest method shouldSendAuthorityUpdatedEvent.

@Test
public void shouldSendAuthorityUpdatedEvent(TestContext context) throws InterruptedException {
    // given
    Async async = context.async();
    Map<String, String> payload = new HashMap<>();
    payload.put("RECORD_TYPE", "MARC_AUTHORITY");
    payload.put("MARC_AUTHORITY", Json.encode(authorityRecord));
    payload.put("MAPPING_RULES", authorityMappingRules.encode());
    payload.put("MAPPING_PARAMS", new JsonObject().encode());
    payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_AUTHORITY).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));
    doAnswer(invocationOnMock -> {
        Consumer<Success<Authority>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(existingAuthority));
        return null;
    }).when(mockedAuthorityRecordCollection).findById(anyString(), any(), any());
    // when
    Future<String> future = handler.handle(kafkaRecord);
    // then
    String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_INVENTORY_AUTHORITY_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 : HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) JsonObject(io.vertx.core.json.JsonObject) Event(org.folio.rest.jaxrs.model.Event) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Success(org.folio.inventory.common.domain.Success) Test(org.junit.Test)

Aggregations

ParsedRecordDto (org.folio.rest.jaxrs.model.ParsedRecordDto)11 Async (io.vertx.ext.unit.Async)9 Test (org.junit.Test)9 HashMap (java.util.HashMap)8 JsonObject (io.vertx.core.json.JsonObject)6 Event (org.folio.rest.jaxrs.model.Event)5 SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)4 Future (io.vertx.core.Future)3 UUID (java.util.UUID)3 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)3 RawRecord (org.folio.rest.jaxrs.model.RawRecord)3 Record (org.folio.rest.jaxrs.model.Record)3 Future.failedFuture (io.vertx.core.Future.failedFuture)2 Promise (io.vertx.core.Promise)2 Buffer (io.vertx.core.buffer.Buffer)2 Json (io.vertx.core.json.Json)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2