Search in sources :

Example 1 with MarcMappingDetail

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

the class DataImportConsumersVerticleTest method shouldModifyRecordWhenPayloadContainsModifyMarcBibActionInCurrentNode.

@Test
public void shouldModifyRecordWhenPayloadContainsModifyMarcBibActionInCurrentNode() throws InterruptedException {
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(JOB_PROFILE).withContent(JsonObject.mapFrom(new JobProfile().withId(UUID.randomUUID().toString()).withDataType(JobProfile.DataType.MARC)).getMap()).withChildSnapshotWrappers(singletonList(new ProfileSnapshotWrapper().withContentType(ACTION_PROFILE).withContent(JsonObject.mapFrom(new ActionProfile().withId(UUID.randomUUID().toString()).withAction(MODIFY).withFolioRecord(ActionProfile.FolioRecord.MARC_BIBLIOGRAPHIC)).getMap()).withChildSnapshotWrappers(singletonList(new ProfileSnapshotWrapper().withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(new MappingProfile().withId(UUID.randomUUID().toString()).withIncomingRecordType(MARC_BIBLIOGRAPHIC).withExistingRecordType(MARC_BIBLIOGRAPHIC).withMappingDetails(new MappingDetail().withMarcMappingOption(MappingDetail.MarcMappingOption.MODIFY).withMarcMappingDetails(List.of(marcMappingDetail)))).getMap())))));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(PROFILE_SNAPSHOT_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(profileSnapshotWrapper))));
    String expectedParsedContent = "{\"leader\":\"00107nam  22000491a 4500\",\"fields\":[{\"001\":\"ybp7406411\"},{\"856\":{\"subfields\":[{\"u\":\"http://libproxy.smith.edu?url=example.com\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";
    DataImportEventPayload eventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(snapshotId).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withOkapiUrl(mockServer.baseUrl()).withTenant(TENANT_ID).withToken(TOKEN).withContext(new HashMap<>() {

        {
            put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
            put(PROFILE_SNAPSHOT_ID_KEY, profileSnapshotWrapper.getId());
        }
    });
    String topic = getTopicName(DI_SRS_MARC_BIB_RECORD_CREATED.value());
    KeyValue<String, String> kafkaRecord = buildKafkaRecord(eventPayload);
    kafkaRecord.addHeader(RECORD_ID_HEADER, record.getId(), UTF_8);
    kafkaRecord.addHeader(CHUNK_ID_HEADER, UUID.randomUUID().toString(), UTF_8);
    SendKeyValues<String, String> request = SendKeyValues.to(topic, singletonList(kafkaRecord)).useDefaults();
    // when
    cluster.send(request);
    // then
    var value = DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING.value();
    String observeTopic = getTopicName(value);
    List<KeyValue<String, String>> observedRecords = cluster.observe(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
    Event obtainedEvent = Json.decodeValue(observedRecords.get(0).getValue(), Event.class);
    DataImportEventPayload dataImportEventPayload = Json.decodeValue(obtainedEvent.getEventPayload(), DataImportEventPayload.class);
    assertEquals(DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING.value(), dataImportEventPayload.getEventType());
    Record actualRecord = Json.decodeValue(dataImportEventPayload.getContext().get(MARC_BIBLIOGRAPHIC.value()), Record.class);
    assertEquals(expectedParsedContent, actualRecord.getParsedRecord().getContent().toString());
    assertEquals(Record.State.ACTUAL, actualRecord.getState());
    assertEquals(dataImportEventPayload.getJobExecutionId(), actualRecord.getSnapshotId());
    assertNotNull(observedRecords.get(0).getHeaders().lastHeader(RECORD_ID_HEADER));
}
Also used : KeyValue(net.mguenther.kafka.junit.KeyValue) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) JobProfile(org.folio.JobProfile) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.rest.jaxrs.model.DataImportEventPayload) MappingProfile(org.folio.MappingProfile) MarcMappingDetail(org.folio.rest.jaxrs.model.MarcMappingDetail) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Event(org.folio.rest.jaxrs.model.Event) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ActionProfile(org.folio.ActionProfile) Test(org.junit.Test) AbstractLBServiceTest(org.folio.services.AbstractLBServiceTest)

Aggregations

RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)1 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)1 KeyValue (net.mguenther.kafka.junit.KeyValue)1 ActionProfile (org.folio.ActionProfile)1 JobProfile (org.folio.JobProfile)1 MappingProfile (org.folio.MappingProfile)1 DataImportEventPayload (org.folio.rest.jaxrs.model.DataImportEventPayload)1 Event (org.folio.rest.jaxrs.model.Event)1 MappingDetail (org.folio.rest.jaxrs.model.MappingDetail)1 MarcMappingDetail (org.folio.rest.jaxrs.model.MarcMappingDetail)1 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)1 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)1 RawRecord (org.folio.rest.jaxrs.model.RawRecord)1 Record (org.folio.rest.jaxrs.model.Record)1 AbstractLBServiceTest (org.folio.services.AbstractLBServiceTest)1 Test (org.junit.Test)1