Search in sources :

Example 1 with ParsedRecordDto

use of org.folio.rest.jaxrs.model.ParsedRecordDto 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 2 with ParsedRecordDto

use of org.folio.rest.jaxrs.model.ParsedRecordDto 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 3 with ParsedRecordDto

use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-source-record-storage by folio-org.

the class QuickMarcKafkaHandlerTest method shouldUpdateParsedRecordAndSendRecordUpdatedEvent.

@Test
public void shouldUpdateParsedRecordAndSendRecordUpdatedEvent(TestContext context) throws InterruptedException {
    Async async = context.async();
    ParsedRecord parsedRecord = record.getParsedRecord();
    Future<Record> future = recordService.saveRecord(record, TENANT_ID);
    ParsedRecordDto parsedRecordDto = new ParsedRecordDto().withId(record.getMatchedId()).withParsedRecord(new ParsedRecord().withContent(UPDATED_PARSED_RECORD_CONTENT)).withRelatedRecordVersion("1").withRecordType(ParsedRecordDto.RecordType.MARC_BIB);
    var payload = new HashMap<String, String>();
    payload.put("PARSED_RECORD_DTO", Json.encode(parsedRecordDto));
    cluster.send(createRequest(payload));
    String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_SRS_MARC_RECORD_UPDATED.name());
    cluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
    future.onComplete(ar -> {
        if (ar.failed()) {
            context.fail(ar.cause());
        }
        recordService.getSourceRecordById(record.getMatchedId(), IdType.RECORD, TENANT_ID).onComplete(getNew -> {
            if (getNew.failed()) {
                context.fail(getNew.cause());
            }
            context.assertTrue(getNew.result().isPresent());
            SourceRecord updatedRecord = getNew.result().get();
            context.assertNotEquals(parsedRecord.getId(), updatedRecord.getParsedRecord().getId());
            context.assertNotEquals(record.getSnapshotId(), updatedRecord.getSnapshotId());
            recordDao.getRecordByCondition(Tables.RECORDS_LB.ID.eq(UUID.fromString(record.getId())), TENANT_ID).onComplete(getOld -> {
                if (getOld.failed()) {
                    context.fail(getOld.cause());
                }
                context.assertTrue(getOld.result().isPresent());
                Record existingRecord = getOld.result().get();
                context.assertEquals(State.OLD, existingRecord.getState());
                context.assertEquals(0, existingRecord.getGeneration());
                context.assertEquals(parsedRecord.getId(), existingRecord.getParsedRecord().getId());
                context.assertEquals(parsedRecord.getContent(), existingRecord.getParsedRecord().getContent());
                context.assertEquals(record.getSnapshotId(), existingRecord.getSnapshotId());
                async.complete();
            });
        });
    });
}
Also used : HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test)

Example 4 with ParsedRecordDto

use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-source-record-storage by folio-org.

the class RecordServiceTest method shouldUpdateSourceRecord.

@Test
public void shouldUpdateSourceRecord(TestContext context) {
    Async async = context.async();
    Record expected = TestMocks.getRecord(0);
    recordDao.saveRecord(expected, TENANT_ID).onComplete(save -> {
        if (save.failed()) {
            context.fail(save.cause());
        }
        String snapshotId = UUID.randomUUID().toString();
        ParsedRecordDto parsedRecordDto = new ParsedRecordDto().withId(expected.getId()).withRecordType(ParsedRecordDto.RecordType.fromValue(expected.getRecordType().toString())).withParsedRecord(expected.getParsedRecord()).withAdditionalInfo(expected.getAdditionalInfo()).withExternalIdsHolder(expected.getExternalIdsHolder()).withMetadata(expected.getMetadata());
        recordService.updateSourceRecord(parsedRecordDto, snapshotId, TENANT_ID).onComplete(update -> {
            if (update.failed()) {
                context.fail(update.cause());
            }
            SnapshotDaoUtil.findById(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshotId).onComplete(getSnapshot -> {
                if (getSnapshot.failed()) {
                    context.fail(getSnapshot.cause());
                }
                context.assertTrue(getSnapshot.result().isPresent());
                context.assertNotNull(getSnapshot.result().get().getProcessingStartedDate());
                recordDao.getRecordByCondition(RECORDS_LB.SNAPSHOT_ID.eq(UUID.fromString(snapshotId)), TENANT_ID).onComplete(getNewRecord -> {
                    if (getNewRecord.failed()) {
                        context.fail(getNewRecord.cause());
                    }
                    context.assertTrue(getNewRecord.result().isPresent());
                    context.assertEquals(State.ACTUAL, getNewRecord.result().get().getState());
                    context.assertEquals(expected.getGeneration() + 1, getNewRecord.result().get().getGeneration());
                    recordDao.getRecordByCondition(RECORDS_LB.SNAPSHOT_ID.eq(UUID.fromString(expected.getSnapshotId())), TENANT_ID).onComplete(getOldRecord -> {
                        if (getOldRecord.failed()) {
                            context.fail(getOldRecord.cause());
                        }
                        context.assertTrue(getOldRecord.result().isPresent());
                        context.assertEquals(State.OLD, getOldRecord.result().get().getState());
                        async.complete();
                    });
                });
            });
        });
    });
}
Also used : Async(io.vertx.ext.unit.Async) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Example 5 with ParsedRecordDto

use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-source-record-storage by folio-org.

the class RecordServiceTest method shouldGetMarcBibSourceRecordByMatchedIdNotEqualToId.

@Test
public void shouldGetMarcBibSourceRecordByMatchedIdNotEqualToId(TestContext context) {
    Record expected = TestMocks.getMarcBibRecord();
    Async async = context.async();
    String snapshotId = UUID.randomUUID().toString();
    ParsedRecordDto parsedRecordDto = new ParsedRecordDto().withId(expected.getId()).withRecordType(ParsedRecordDto.RecordType.fromValue(expected.getRecordType().toString())).withParsedRecord(expected.getParsedRecord()).withAdditionalInfo(expected.getAdditionalInfo()).withExternalIdsHolder(expected.getExternalIdsHolder()).withMetadata(expected.getMetadata());
    recordDao.saveRecord(expected, TENANT_ID).compose(ar -> recordService.updateSourceRecord(parsedRecordDto, snapshotId, TENANT_ID)).onComplete(update -> {
        if (update.failed()) {
            context.fail(update.cause());
        }
        recordDao.getRecordByMatchedId(expected.getMatchedId(), TENANT_ID).onComplete(get -> {
            if (get.failed()) {
                context.fail(get.cause());
            }
            context.assertTrue(get.result().isPresent());
            context.assertNotNull(get.result().get().getRawRecord());
            context.assertNotNull(get.result().get().getParsedRecord());
            context.assertEquals(expected.getMatchedId(), get.result().get().getMatchedId());
            context.assertTrue(get.result().get().getGeneration() > 0);
            context.assertNotEquals(get.result().get().getMatchedId(), get.result().get().getId());
            async.complete();
        });
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) DSL(org.jooq.impl.DSL) RecordDaoImpl(org.folio.dao.RecordDaoImpl) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) RecordType(org.folio.dao.util.RecordType) RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) RecordState(org.folio.rest.jooq.enums.RecordState) RECORDS_LB(org.folio.rest.jooq.Tables.RECORDS_LB) Flowable(io.reactivex.Flowable) IdType(org.folio.dao.util.IdType) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) After(org.junit.After) AsyncResult(io.vertx.core.AsyncResult) Comparator.comparing(java.util.Comparator.comparing) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SortOrder(org.jooq.SortOrder) TestMocks(org.folio.TestMocks) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) RecordDao(org.folio.dao.RecordDao) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) Record(org.folio.rest.jaxrs.model.Record) RecordDaoUtil(org.folio.dao.util.RecordDaoUtil) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) Future(io.vertx.core.Future) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) ChronoUnit(java.time.temporal.ChronoUnit) State(org.folio.rest.jaxrs.model.Record.State) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) OrderField(org.jooq.OrderField) Assertions(org.junit.jupiter.api.Assertions) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) 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