Search in sources :

Example 11 with ExternalIdsHolder

use of org.folio.rest.jaxrs.model.ExternalIdsHolder in project mod-source-record-manager by folio-org.

the class ChangeManagerParsedRecordsAPITest method shouldReturnParsedRecordDtoIfSourceRecordExists.

@Test
public void shouldReturnParsedRecordDtoIfSourceRecordExists(TestContext testContext) {
    Async async = testContext.async();
    String externalId = UUID.randomUUID().toString();
    SourceRecord sourceRecord = new SourceRecord().withRecordId(UUID.randomUUID().toString()).withParsedRecord(new ParsedRecord().withId(UUID.randomUUID().toString()).withContent("{\"leader\":\"01240cas a2200397   4500\",\"fields\":[]}")).withRecordType(SourceRecord.RecordType.MARC_BIB).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(externalId));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(SOURCE_RECORDS_URL + ".*"), true)).willReturn(ok().withBody(JsonObject.mapFrom(sourceRecord).encode())));
    RestAssured.given().spec(spec).queryParam(EXTERNAL_ID_QUERY_PARAM, externalId).when().get(PARSED_RECORDS_URL).then().statusCode(HttpStatus.SC_OK).body("id", is(sourceRecord.getRecordId())).body("parsedRecord.id", is(sourceRecord.getParsedRecord().getId())).body("recordType", is(sourceRecord.getRecordType().value())).body("externalIdsHolder.instanceId", is(externalId));
    async.complete();
}
Also used : ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 12 with ExternalIdsHolder

use of org.folio.rest.jaxrs.model.ExternalIdsHolder in project mod-source-record-manager by folio-org.

the class HrIdFieldServiceTest method shouldNotAdd035FieldIf001FieldNotExists.

@Test
public void shouldNotAdd035FieldIf001FieldNotExists() {
    // given
    String parsedContent = "{\"leader\":\"00115nam  22000731a 4500\",\"fields\":[{\"003\":\"in001\"},{\"507\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}},{\"500\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";
    String expectedParsedContent = "{\"leader\":\"00115nam  22000731a 4500\",\"fields\":[{\"003\":\"in001\"},{\"507\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}},{\"500\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";
    ParsedRecord parsedRecord = new ParsedRecord();
    parsedRecord.setContent(parsedContent);
    Record record = new Record().withId(UUID.randomUUID().toString()).withParsedRecord(parsedRecord).withGeneration(0).withState(Record.State.ACTUAL).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId("001").withInstanceHrid("in001"));
    // when
    HrIdFieldService hrIdFieldService = new HrIdFieldServiceImpl();
    hrIdFieldService.move001valueTo035Field(Lists.newArrayList(record));
    // then
    Assert.assertEquals(expectedParsedContent, record.getParsedRecord().getContent());
}
Also used : ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) HrIdFieldService(org.folio.services.afterprocessing.HrIdFieldService) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Example 13 with ExternalIdsHolder

use of org.folio.rest.jaxrs.model.ExternalIdsHolder in project mod-source-record-manager by folio-org.

the class HrIdFieldServiceTest method shouldNotAdd035FieldIf035FieldExists.

@Test
public void shouldNotAdd035FieldIf035FieldExists() {
    // given
    String parsedContent = "{\"leader\":\"00115nam  22000731a 4500\",\"fields\":[{\"001\":\"in001\"},{\"003\":\"in001\"},{\"035\":{\"subfields\":[{\"a\":\"(test)data\"}],\"ind1\":\" \",\"ind2\":\" \"}},{\"507\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}},{\"500\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";
    String expectedParsedContent = "{\"leader\":\"00115nam  22000731a 4500\",\"fields\":[{\"001\":\"in001\"},{\"003\":\"in001\"},{\"035\":{\"subfields\":[{\"a\":\"(test)data\"}],\"ind1\":\" \",\"ind2\":\" \"}},{\"507\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}},{\"500\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";
    ParsedRecord parsedRecord = new ParsedRecord();
    parsedRecord.setContent(parsedContent);
    Record record = new Record().withId(UUID.randomUUID().toString()).withParsedRecord(parsedRecord).withGeneration(0).withState(Record.State.ACTUAL).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId("001").withInstanceHrid("in001"));
    // when
    HrIdFieldService hrIdFieldService = new HrIdFieldServiceImpl();
    hrIdFieldService.move001valueTo035Field(Lists.newArrayList(record));
    // then
    Assert.assertEquals(expectedParsedContent, record.getParsedRecord().getContent());
}
Also used : ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) HrIdFieldService(org.folio.services.afterprocessing.HrIdFieldService) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Example 14 with ExternalIdsHolder

use of org.folio.rest.jaxrs.model.ExternalIdsHolder in project mod-source-record-manager by folio-org.

the class HrIdFieldServiceTest method shouldAdd035FieldIf001FieldExists.

@Test
public void shouldAdd035FieldIf001FieldExists() {
    // given
    String parsedContent = "{\"leader\":\"00115nam  22000731a 4500\",\"fields\":[{\"001\":\"in001\"},{\"507\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}},{\"500\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";
    String expectedParsedContent = "{\"leader\":\"00108nam  22000731a 4500\",\"fields\":[{\"001\":\"in001\"},{\"035\":{\"subfields\":[{\"a\":\"in001\"}],\"ind1\":\" \",\"ind2\":\" \"}},{\"507\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}},{\"500\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";
    ParsedRecord parsedRecord = new ParsedRecord();
    parsedRecord.setContent(parsedContent);
    Record record = new Record().withId(UUID.randomUUID().toString()).withParsedRecord(parsedRecord).withGeneration(0).withState(Record.State.ACTUAL).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId("001").withInstanceHrid("in001"));
    // when
    HrIdFieldService hrIdFieldService = new HrIdFieldServiceImpl();
    hrIdFieldService.move001valueTo035Field(Lists.newArrayList(record));
    // then
    Assert.assertEquals(expectedParsedContent, record.getParsedRecord().getContent());
}
Also used : ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) HrIdFieldService(org.folio.services.afterprocessing.HrIdFieldService) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Example 15 with ExternalIdsHolder

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

the class CreateHoldingEventHandlerTest method shouldNotProcessEventIfInstanceIdIsNotExistsInInstanceInContextAndMarcBibliographicNotExists.

@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfInstanceIdIsNotExistsInInstanceInContextAndMarcBibliographicNotExists() throws InterruptedException, ExecutionException, TimeoutException {
    Reader fakeReader = Mockito.mock(Reader.class);
    String permanentLocationId = UUID.randomUUID().toString();
    when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(permanentLocationId));
    when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
    when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
    MappingManager.registerReaderFactory(fakeReaderFactory);
    MappingManager.registerWriterFactory(new HoldingWriterFactory());
    String instanceId = String.valueOf(UUID.randomUUID());
    Record record = new Record().withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId));
    HashMap<String, String> context = new HashMap<>();
    context.put("INSTANCE", new JsonObject().encode());
    context.put("InvalidField", JsonObject.mapFrom(record).encode());
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
    CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
    future.get(5, TimeUnit.MILLISECONDS);
}
Also used : ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) HashMap(java.util.HashMap) HoldingWriterFactory(org.folio.inventory.dataimport.HoldingWriterFactory) Reader(org.folio.processing.mapping.mapper.reader.Reader) JsonObject(io.vertx.core.json.JsonObject) HoldingsRecord(org.folio.HoldingsRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Record(org.folio.rest.jaxrs.model.Record) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MappingRule(org.folio.rest.jaxrs.model.MappingRule) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Aggregations

ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)25 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)22 Record (org.folio.rest.jaxrs.model.Record)22 Test (org.junit.Test)18 RawRecord (org.folio.rest.jaxrs.model.RawRecord)16 Async (io.vertx.ext.unit.Async)15 JsonObject (io.vertx.core.json.JsonObject)11 ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)8 Date (java.util.Date)6 HashMap (java.util.HashMap)6 Snapshot (org.folio.rest.jaxrs.model.Snapshot)6 SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)6 Before (org.junit.Before)6 JsonArray (io.vertx.core.json.JsonArray)5 UUID (java.util.UUID)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 DataImportEventPayload (org.folio.DataImportEventPayload)4 SnapshotDaoUtil (org.folio.dao.util.SnapshotDaoUtil)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3