Search in sources :

Example 6 with Event

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

the class MarcBibInstanceHridSetKafkaHandlerTest method shouldReturnFailedFutureWhenPayloadCanNotBeMapped.

@Test
public void shouldReturnFailedFutureWhenPayloadCanNotBeMapped(TestContext context) {
    // given
    Async async = context.async();
    Event event = new Event().withId("01").withEventPayload(null);
    when(kafkaRecord.value()).thenReturn(Json.encode(event));
    // when
    Future<String> future = marcBibInstanceHridSetKafkaHandler.handle(kafkaRecord);
    // then
    future.onComplete(ar -> {
        context.assertTrue(ar.failed());
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Event(org.folio.rest.jaxrs.model.Event) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with Event

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

the class MarcHoldingsRecordHridSetKafkaHandlerTest method shouldReturnFailedFutureWhenPayloadCanNotBeMapped.

@Test
public void shouldReturnFailedFutureWhenPayloadCanNotBeMapped(TestContext context) {
    // given
    Async async = context.async();
    Event event = new Event().withId("01").withEventPayload(null);
    when(kafkaRecord.value()).thenReturn(Json.encode(event));
    // when
    Future<String> future = marcHoldingsRecordHridSetKafkaHandler.handle(kafkaRecord);
    // then
    future.onComplete(ar -> {
        context.assertTrue(ar.failed());
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Event(org.folio.rest.jaxrs.model.Event) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with Event

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

the class MarcHoldingsRecordHridSetKafkaHandlerTest method shouldReturnSucceededFutureWithObtainedRecordKey.

@Test
public void shouldReturnSucceededFutureWithObtainedRecordKey(TestContext context) {
    // given
    Async async = context.async();
    Map<String, String> payload = new HashMap<>();
    payload.put(JOB_EXECUTION_ID_KEY, UUID.randomUUID().toString());
    payload.put("MARC_HOLDINGS", Json.encode(record));
    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(kafkaRecord.headers()).thenReturn(okapiHeaders);
    // when
    Future<String> future = marcHoldingsRecordHridSetKafkaHandler.handle(kafkaRecord);
    // then
    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) Event(org.folio.rest.jaxrs.model.Event) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with Event

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

the class QuickMarcKafkaHandlerTest method shouldSendInstanceUpdatedEvent.

@Test
public void shouldSendInstanceUpdatedEvent(TestContext context) throws InterruptedException {
    // given
    Async async = context.async();
    Map<String, String> payload = new HashMap<>();
    payload.put("RECORD_TYPE", "MARC_BIB");
    payload.put("MARC_BIB", Json.encode(bibRecord));
    payload.put("MAPPING_RULES", bibMappingRules.encode());
    payload.put("MAPPING_PARAMS", new JsonObject().encode());
    payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_BIB).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_INSTANCE_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) Test(org.junit.Test)

Example 10 with Event

use of org.folio.rest.jaxrs.model.Event 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)

Aggregations

Event (org.folio.rest.jaxrs.model.Event)90 Test (org.junit.Test)41 HashMap (java.util.HashMap)32 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)28 DataImportEventPayload (org.folio.DataImportEventPayload)27 KeyValue (net.mguenther.kafka.junit.KeyValue)22 Async (io.vertx.ext.unit.Async)21 KafkaConsumerRecord (io.vertx.kafka.client.consumer.KafkaConsumerRecord)16 OkapiConnectionParams (org.folio.dataimport.util.OkapiConnectionParams)16 Record (org.folio.rest.jaxrs.model.Record)14 LogManager (org.apache.logging.log4j.LogManager)12 Logger (org.apache.logging.log4j.Logger)12 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)12 Test (org.junit.jupiter.api.Test)12 KafkaHeader (io.vertx.kafka.client.producer.KafkaHeader)11 DuplicateEventException (org.folio.kafka.exception.DuplicateEventException)10 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)10 RecordCollection (org.folio.rest.jaxrs.model.RecordCollection)10 RecordsBatchResponse (org.folio.rest.jaxrs.model.RecordsBatchResponse)10 Future (io.vertx.core.Future)9