From a95c3a112a3b94ddf8e0bdad0052b3ce5fc10955 Mon Sep 17 00:00:00 2001 From: Dmytro Krutii Date: Thu, 29 Aug 2024 13:19:02 +0300 Subject: [PATCH] MODSOURMAN-1203 Add additional validation before marc bib record saving (#638) * MODSOURMAN-1203 Add additional validation before marc bib record saving * MODSOURMAN-1203 Fix validation logic * MODSOURMAN-1203 Add instanceHrId to MARC_BIB tests records * MODSOURMAN-1203 Unit tests refactoring * MODSOURMAN-1203 Unit tests refactoring * MODSOURMAN-1203 Unit tests refactoring * MODSOURMAN-1203 Get 001 field from decoded parsedContent * MODSOURMAN-1203 Disable last commit changes * MODSOURMAN-1203 Fix Snapshot delete unit test * MODSOURMAN-1203 Disable failed test * MODSOURMAN-1203 Fix suppress from discovery test * MODSOURMAN-1203 Logger refactoring and add validation tests * MODSOURMAN-1203 Upd NEWS.md * MODSOURMAN-1203 Upd NEWS.md * MODSOURMAN-1203 Fix imports * MODSOURMAN-1203 Deprecate /source-storage/populate-test-marc-records endpoint * MODSOURMAN-1203 Fix raml * MODSOURMAN-1203 Revert shouldNotMatchRecordBy035FieldIfRecordExternalIdIsNull test * MODSOURMAN-1203 Fix sonar warnings --- NEWS.md | 1 + ...rceStoragePopulateTestMarcRecordsImpl.java | 4 + .../org/folio/services/RecordServiceImpl.java | 20 +++ .../org/folio/rest/impl/RecordApiTest.java | 165 ++++++++++++++--- .../rest/impl/RecordsGenerationTest.java | 41 ++++- .../rest/impl/RecordsMatchingApiTest.java | 15 +- .../org/folio/rest/impl/SnapshotApiTest.java | 17 +- .../folio/rest/impl/SourceRecordApiTest.java | 170 ++++++++++-------- .../rest/impl/SourceStorageBatchApiTest.java | 29 ++- .../rest/impl/SourceStorageStreamApiTest.java | 126 ++++++------- .../rest/impl/TestMarcRecordsApiTest.java | 3 + .../AuthorityLinkChunkKafkaHandlerTest.java | 9 +- ...AuthorityUpdateModifyEventHandlerTest.java | 10 +- .../MarcBibUpdateModifyEventHandlerTest.java | 12 +- ...cHoldingsUpdateModifyEventHandlerTest.java | 7 +- .../services/QuickMarcKafkaHandlerTest.java | 7 +- .../org/folio/services/RecordServiceTest.java | 35 ++-- ...rcIndexersVersionDeletionVerticleTest.java | 6 +- .../DataImportConsumersVerticleTest.java | 5 +- .../parsedMarcAuthorityWith999field.json | 22 +++ .../0f0fe962-d502-4a4f-9e74-7732bec94ee8.json | 3 +- .../4c0ff739-3f4d-4670-a693-84dd48e31c53.json | 3 +- .../7293f287-bb51-41f5-805d-00ff18a1f791.json | 3 +- .../8452daf9-c130-4955-99ce-1c397a218900.json | 3 +- .../8f462542-387c-4f06-a01b-50829c7c7b13.json | 3 +- .../8fb19e31-0920-49d7-9438-b573c292b1a6.json | 3 +- .../be1b25ae-4a9d-4077-93e6-7f8e59efd609.json | 3 +- .../d3cd3e1e-a18c-4f7c-b053-9aa50343394e.json | 3 +- .../e567b8e2-a45b-45f1-a85a-6b6312bdf4d8.json | 3 +- .../ec53a386-9616-428b-92a9-e1f07756ea1f.json | 3 +- ramls/source-record-storage-test-records.raml | 3 +- 31 files changed, 509 insertions(+), 228 deletions(-) diff --git a/NEWS.md b/NEWS.md index c0657b7cc..4565f2933 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ * [MODSOURMAN-783](https://folio-org.atlassian.net/browse/MODSOURCE-783) Extend MARC-MARC search query to account for qualifiers * [MODSOURCE-752](https://folio-org.atlassian.net/browse/MODSOURCE-752) Emit Domain Events For Source Records * [MODSOURCE-795](https://folio-org.atlassian.net/browse/MODSOURCE-795) Upgrade Spring 5 to 6 by 2024-08-31 +* [MODSOURMAN-1203](https://folio-org.atlassian.net/browse/MODSOURMAN-1203) Add validation on MARC_BIB record save ## 2024-03-20 5.8.0 * [MODSOURCE-733](https://issues.folio.org/browse/MODSOURCE-733) Reduce Memory Allocation of Strings diff --git a/mod-source-record-storage-server/src/main/java/org/folio/rest/impl/SourceStoragePopulateTestMarcRecordsImpl.java b/mod-source-record-storage-server/src/main/java/org/folio/rest/impl/SourceStoragePopulateTestMarcRecordsImpl.java index 82bf9aa61..a858397e7 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/rest/impl/SourceStoragePopulateTestMarcRecordsImpl.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/rest/impl/SourceStoragePopulateTestMarcRecordsImpl.java @@ -31,6 +31,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +/** + * @deprecated This class will no longer be used to create test data + */ +@Deprecated(forRemoval = true) public class SourceStoragePopulateTestMarcRecordsImpl implements SourceStoragePopulateTestMarcRecords { private static final Logger LOG = LogManager.getLogger(); diff --git a/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java b/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java index 161a9d602..958eefc7f 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java @@ -19,6 +19,7 @@ import static org.folio.services.util.AdditionalFieldsUtil.TAG_999; import static org.folio.services.util.AdditionalFieldsUtil.addFieldToMarcRecord; import static org.folio.services.util.AdditionalFieldsUtil.getFieldFromMarcRecord; +import static org.folio.services.util.AdditionalFieldsUtil.getValueFromControlledField; import io.reactivex.Flowable; import io.vertx.core.AsyncResult; @@ -96,8 +97,10 @@ public class RecordServiceImpl implements RecordService { private static final String NOT_FOUND_MESSAGE = "%s with id '%s' was not found"; private static final Character DELETED_LEADER_RECORD_STATUS = 'd'; public static final String UPDATE_RECORD_DUPLICATE_EXCEPTION = "Incoming record could be a duplicate, incoming record generation should not be the same as matched record generation and the execution of job should be started after of creating the previous record generation"; + public static final String EXTERNAL_IDS_MISSING_ERROR = "MARC_BIB records must contain external instance and hr id's and 001 field into parsed record"; public static final char SUBFIELD_S = 's'; public static final char INDICATOR = 'f'; + private static final String TAG_001 = "001"; private final RecordDao recordDao; @@ -128,6 +131,10 @@ public Future saveRecord(Record record, Map okapiHeaders LOG.debug("saveRecord:: Saving record with id: {} for tenant: {}", record.getId(), tenantId); ensureRecordHasId(record); ensureRecordHasSuppressDiscovery(record); + if (!isRecordContainsRequiredField(record)) { + LOG.error("saveRecord:: Record '{}' has invalid externalIdHolder or missing 001 field into parsed record", record.getId()); + return Future.failedFuture(new BadRequestException(EXTERNAL_IDS_MISSING_ERROR)); + } return recordDao.executeInTransaction(txQE -> SnapshotDaoUtil.findById(txQE, record.getSnapshotId()) .map(optionalSnapshot -> optionalSnapshot .orElseThrow(() -> new NotFoundException(format(SNAPSHOT_NOT_FOUND_TEMPLATE, record.getSnapshotId())))) @@ -523,4 +530,17 @@ private static void update005field(Record targetRecord) { } } + private boolean isRecordContainsRequiredField(Record marcRecord) { + if (marcRecord.getRecordType() == Record.RecordType.MARC_BIB) { + var idsHolder = marcRecord.getExternalIdsHolder(); + if (Objects.isNull(idsHolder) || StringUtils.isEmpty(getValueFromControlledField(marcRecord, TAG_001))) { + return false; + } + if (StringUtils.isEmpty(idsHolder.getInstanceId()) || StringUtils.isEmpty(idsHolder.getInstanceHrid())) { + return false; + } + } + return true; + } + } diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordApiTest.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordApiTest.java index 369d52cfc..683e72007 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordApiTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordApiTest.java @@ -22,6 +22,7 @@ import io.vertx.ext.unit.Async; import io.vertx.ext.unit.TestContext; import io.vertx.ext.unit.junit.VertxUnitRunner; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.http.HttpStatus; import org.folio.dao.util.ParsedRecordDaoUtil; import org.junit.Assert; @@ -53,14 +54,16 @@ public class RecordApiTest extends AbstractRestVerticleTest { private static final String SIXTH_UUID = UUID.randomUUID().toString(); private static final String SEVENTH_UUID = UUID.randomUUID().toString(); private static final String EIGHTH_UUID = UUID.randomUUID().toString(); + private static final String FIRST_HRID = RandomStringUtils.randomAlphanumeric(9); private static final String GENERATION = "generation"; private static RawRecord rawMarcRecord; private static ParsedRecord parsedMarcRecord; + private static ParsedRecord marcRecordWith001; private static RawRecord rawEdifactRecord; private static ParsedRecord parsedEdifactRecord; - private static ParsedRecord parsedMarcRecordWith999ff$s; + private static ParsedRecord parsedMarcRecordWith001and999; static { try { @@ -68,17 +71,20 @@ public class RecordApiTest extends AbstractRestVerticleTest { .withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class)); parsedMarcRecord = new ParsedRecord() .withContent(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH)); + marcRecordWith001 = new ParsedRecord() + .withContent(new JsonObject().put("fields", new JsonArray().add(new JsonObject().put("001", FIRST_HRID))).encode()); rawEdifactRecord = new RawRecord() .withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_EDIFACT_RECORD_CONTENT_SAMPLE_PATH), String.class)); parsedEdifactRecord = new ParsedRecord() .withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_EDIFACT_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode()); - parsedMarcRecordWith999ff$s = new ParsedRecord().withId(FIRST_UUID) + parsedMarcRecordWith001and999 = new ParsedRecord().withId(FIRST_UUID) .withContent(new JsonObject().put("leader", "01542ccm a2200361 4500") .put("fields", new JsonArray().add(new JsonObject().put("999", new JsonObject() .put("subfields", new JsonArray().add(new JsonObject().put("s", FIRST_UUID))) .put("ind1", "f") - .put("ind2", "f")))).encode()); + .put("ind2", "f"))) + .add(new JsonObject().put("001", FIRST_HRID))).encode()); } catch (IOException e) { e.printStackTrace(); } @@ -108,9 +114,13 @@ public class RecordApiTest extends AbstractRestVerticleTest { .withSnapshotId(snapshot_1.getJobExecutionId()) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawMarcRecord) + .withParsedRecord(marcRecordWith001) .withMatchedId(FIRST_UUID) .withOrder(0) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(FIRST_HRID)); private static Record record_2 = new Record() .withId(SECOND_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -119,24 +129,34 @@ public class RecordApiTest extends AbstractRestVerticleTest { .withParsedRecord(parsedMarcRecord) .withMatchedId(SECOND_UUID) .withOrder(11) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(FIRST_HRID)); private static Record record_3 = new Record() .withId(THIRD_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawMarcRecord) .withErrorRecord(errorRecord) + .withParsedRecord(marcRecordWith001) .withMatchedId(THIRD_UUID) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(FIRST_HRID)); private static Record record_5 = new Record() .withId(FIFTH_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawMarcRecord) .withMatchedId(FIFTH_UUID) - .withParsedRecord(invalidParsedRecord) + .withParsedRecord(marcRecordWith001) .withOrder(101) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(FIRST_HRID)); private static Record record_6 = new Record() .withId(SIXTH_UUID) .withSnapshotId(snapshot_3.getJobExecutionId()) @@ -164,6 +184,15 @@ public class RecordApiTest extends AbstractRestVerticleTest { .withMatchedId(EIGHTH_UUID) .withOrder(0) .withState(Record.State.ACTUAL); + private static Record record_9 = new Record() + .withId(FIFTH_UUID) + .withSnapshotId(snapshot_2.getJobExecutionId()) + .withRecordType(RecordType.MARC_AUTHORITY) + .withRawRecord(rawMarcRecord) + .withMatchedId(FIFTH_UUID) + .withParsedRecord(invalidParsedRecord) + .withOrder(101) + .withState(Record.State.ACTUAL); @Before public void setUp(TestContext context) { @@ -200,7 +229,10 @@ public void shouldReturnAllMarcBibRecordsWithNotEmptyStateOnGetWhenNoQueryIsSpec .withParsedRecord(parsedMarcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) - .withState(Record.State.OLD); + .withState(Record.State.OLD) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, record_1, record_2, record_3, record_4, record_6); @@ -268,7 +300,10 @@ public void shouldReturnAllEdifactRecordsWithNotEmptyStateOnGetWhenRecordTypeQue .withParsedRecord(parsedMarcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) - .withState(Record.State.OLD); + .withState(Record.State.OLD) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FOURTH_UUID) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, record_1, record_2, record_3, record_4, record_6); @@ -297,7 +332,10 @@ public void shouldReturnMarcBibRecordsOnGetBySpecifiedSnapshotId(TestContext tes .withParsedRecord(parsedMarcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) - .withState(Record.State.OLD); + .withState(Record.State.OLD) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FOURTH_UUID) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, record_1, record_2, record_3, record_6, recordWithOldStatus); @@ -367,7 +405,10 @@ public void shouldReturnEdifactRecordsOnGetBySpecifiedSnapshotId(TestContext tes .withParsedRecord(parsedMarcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) - .withState(Record.State.OLD); + .withState(Record.State.OLD) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FOURTH_UUID) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, record_1, record_2, record_3, record_6, recordWithOldStatus); @@ -397,7 +438,10 @@ public void shouldReturnLimitedCollectionWithActualStateOnGetWithLimit(TestConte .withParsedRecord(parsedMarcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) - .withState(Record.State.OLD); + .withState(Record.State.OLD) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FOURTH_UUID) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, record_1, record_2, record_3, recordWithOldStatus); @@ -631,7 +675,7 @@ public void shouldUpdateErrorRecordOnPut(TestContext testContext) { Async async = testContext.async(); Response createResponse = RestAssured.given() .spec(spec) - .body(record_1.withParsedRecord(parsedMarcRecordWith999ff$s)) + .body(record_1.withParsedRecord(parsedMarcRecordWith001and999)) .when() .post(SOURCE_STORAGE_RECORDS_PATH); assertThat(createResponse.statusCode(), is(HttpStatus.SC_CREATED)); @@ -652,7 +696,7 @@ public void shouldSendNotFoundWhenUpdateRecordGenerationForNonExistingRecord(Tes Async async = testContext.async(); RestAssured.given() .spec(spec) - .body(record_1.withParsedRecord(parsedMarcRecordWith999ff$s)) + .body(record_1.withParsedRecord(parsedMarcRecordWith001and999)) .when() .put(SOURCE_STORAGE_RECORDS_PATH + "/" + record_1.getMatchedId() + "/" + GENERATION) .then() @@ -667,7 +711,7 @@ public void shouldSendBadRequestWhenUpdateRecordGenerationWithDuplicate(TestCont Async async = testContext.async(); Response createResponse = RestAssured.given() .spec(spec) - .body(record_1.withParsedRecord(parsedMarcRecordWith999ff$s)) + .body(record_1.withParsedRecord(parsedMarcRecordWith001and999)) .when() .post(SOURCE_STORAGE_RECORDS_PATH); assertThat(createResponse.statusCode(), is(HttpStatus.SC_CREATED)); @@ -693,7 +737,7 @@ public void shouldUpdateRecordGeneration(TestContext testContext) { Async async = testContext.async(); Response createResponse = RestAssured.given() .spec(spec) - .body(record_1.withParsedRecord(parsedMarcRecordWith999ff$s)) + .body(record_1.withParsedRecord(parsedMarcRecordWith001and999)) .when() .post(SOURCE_STORAGE_RECORDS_PATH); assertThat(createResponse.statusCode(), is(HttpStatus.SC_CREATED)); @@ -842,11 +886,17 @@ public void shouldDeleteExistingMarcRecordOnDeleteByInstanceIdAndUpdate005FieldW String currentDate = "20240718132044.6"; ParsedRecord parsedRecord = new ParsedRecord().withId(srsId) - .withContent(new JsonObject().put("leader", "01542ccm a2200361 4500") + .withContent( + new JsonObject().put("leader", "01542ccm a2200361 4500") .put("fields", new JsonArray() .add(new JsonObject().put("005", currentDate)) + .add(new JsonObject().put("001", FIRST_HRID)) .add(new JsonObject().put("999", new JsonObject() - .put("subfields", new JsonArray().add(new JsonObject().put("s", srsId)).add(new JsonObject().put("i", instanceId))))))); + .put("ind1", "f") + .put("ind2", "f") + .put("subfields", new JsonArray() + .add(new JsonObject().put("s", srsId)) + .add(new JsonObject().put("i", instanceId)))))).encode()); Record newRecord = new Record() .withId(srsId) @@ -856,7 +906,8 @@ public void shouldDeleteExistingMarcRecordOnDeleteByInstanceIdAndUpdate005FieldW .withParsedRecord(parsedRecord) .withState(Record.State.ACTUAL) .withExternalIdsHolder(new ExternalIdsHolder() - .withInstanceId(instanceId)) + .withInstanceId(instanceId) + .withInstanceHrid(FIRST_HRID)) .withMatchedId(UUID.randomUUID().toString()); Async async = testContext.async(); @@ -894,7 +945,7 @@ public void shouldDeleteExistingMarcRecordOnDeleteByInstanceIdAndUpdate005FieldW //Complex verifying "005" field is NOT empty inside parsed record. LinkedHashMap>> content = (LinkedHashMap>>) deletedRecord.getParsedRecord().getContent(); - LinkedHashMap map = content.get("fields").get(0); + LinkedHashMap map = content.get("fields").get(1); String resulted005FieldValue = map.get("005"); Assert.assertNotNull(resulted005FieldValue); Assert.assertNotEquals(currentDate, resulted005FieldValue); @@ -913,7 +964,10 @@ public void shouldReturnNoContentAndDeleteRecordIfTryingToDeleteRecordWithStateN .withRawRecord(rawMarcRecord) .withParsedRecord(parsedMarcRecord) .withState(Record.State.OLD) - .withMatchedId(UUID.randomUUID().toString()); + .withMatchedId(UUID.randomUUID().toString()) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(FIRST_HRID)); Async async = testContext.async(); Response createParsed = RestAssured.given() @@ -940,6 +994,9 @@ public void shouldReturnNoContentAndDeleteRecordIfTryingToDeleteRecordWithStateN .withRawRecord(rawMarcRecord) .withParsedRecord(parsedMarcRecord) .withState(Record.State.DELETED) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(FIRST_HRID)) .withMatchedId(UUID.randomUUID().toString()); async = testContext.async(); @@ -1043,7 +1100,7 @@ public void shouldCreateErrorRecordIfParsedContentIsInvalid(TestContext testCont Async async = testContext.async(); Response createResponse = RestAssured.given() .spec(spec) - .body(record_5) + .body(record_9) .when() .post(SOURCE_STORAGE_RECORDS_PATH); assertThat(createResponse.statusCode(), is(HttpStatus.SC_CREATED)); @@ -1066,6 +1123,58 @@ public void shouldCreateErrorRecordIfParsedContentIsInvalid(TestContext testCont async.complete(); } + @Test + public void shouldReturnBadRequestWithInvalidMarcBibRecords(TestContext testContext) { + postSnapshots(testContext, snapshot_1); + + var missing001InParsedRecord = new Record() + .withId(UUID.randomUUID().toString()) + .withSnapshotId(snapshot_1.getJobExecutionId()) + .withRecordType(Record.RecordType.MARC_BIB) + .withRawRecord(rawMarcRecord) + .withParsedRecord(new ParsedRecord().withContent("")) + .withState(Record.State.ACTUAL) + .withMatchedId(UUID.randomUUID().toString()) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(FIRST_HRID)); + + var async = testContext.async(); + + RestAssured.given() + .spec(spec) + .body(missing001InParsedRecord) + .when() + .post(SOURCE_STORAGE_RECORDS_PATH) + .then() + .statusCode(HttpStatus.SC_BAD_REQUEST); + + var missingExternalInstanceIdRecord = missing001InParsedRecord + .withParsedRecord(marcRecordWith001) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceHrid(FIRST_HRID)); + + RestAssured.given() + .spec(spec) + .body(missingExternalInstanceIdRecord) + .when() + .post(SOURCE_STORAGE_RECORDS_PATH) + .then() + .statusCode(HttpStatus.SC_BAD_REQUEST); + + var missingExternalInstanceHrIdRecord = missingExternalInstanceIdRecord + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID)); + + RestAssured.given() + .spec(spec) + .body(missingExternalInstanceHrIdRecord) + .when() + .post(SOURCE_STORAGE_RECORDS_PATH) + .then() + .statusCode(HttpStatus.SC_BAD_REQUEST); + + async.complete(); + } + @Test public void shouldReturnErrorOnGet() { RestAssured.given() @@ -1126,6 +1235,9 @@ private void returnCreatedMarcRecordWithAdditionalInfoOnGetById(TestContext test .withParsedRecord(parsedMarcRecord) .withMatchedId(matchedId) .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(matchedId) + .withInstanceHrid(FIRST_HRID)) .withAdditionalInfo( new AdditionalInfo().withSuppressDiscovery(true)); @@ -1163,7 +1275,9 @@ public void suppressFromDiscoveryByInstanceIdSuccess(TestContext testContext) { ParsedRecord parsedRecord = new ParsedRecord().withId(srsId) .withContent(new JsonObject().put("leader", "01542ccm a2200361 4500") - .put("fields", new JsonArray().add(new JsonObject().put("999", new JsonObject() + .put("fields", new JsonArray() + .add(new JsonObject().put("001", FIRST_HRID)) + .add(new JsonObject().put("999", new JsonObject() .put("subfields", new JsonArray().add(new JsonObject().put("s", srsId)).add(new JsonObject().put("i", instanceId))))))); Record newRecord = new Record() @@ -1173,7 +1287,8 @@ public void suppressFromDiscoveryByInstanceIdSuccess(TestContext testContext) { .withRawRecord(rawMarcRecord) .withParsedRecord(parsedRecord) .withExternalIdsHolder(new ExternalIdsHolder() - .withInstanceId(instanceId)) + .withInstanceId(instanceId) + .withInstanceHrid(FIRST_HRID)) .withMatchedId(UUID.randomUUID().toString()); RestAssured.given() diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsGenerationTest.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsGenerationTest.java index b4a1c108a..08b4b9cce 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsGenerationTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsGenerationTest.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.http.HttpStatus; import org.folio.TestUtil; import org.folio.dao.PostgresClientFactory; @@ -97,7 +98,10 @@ public void shouldCalculateRecordsGeneration(TestContext testContext) { .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) .withParsedRecord(marcRecord) - .withMatchedId(matchedId); + .withMatchedId(matchedId) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); Record created = RestAssured.given() .spec(spec) @@ -151,7 +155,10 @@ public void shouldNotCalculateRecordGeneration(TestContext testContext){ .withRawRecord(rawRecord) .withParsedRecord(marcRecord) .withMatchedId(matchedId) - .withGeneration(5); + .withGeneration(5) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); Record created = RestAssured.given() .spec(spec) @@ -191,7 +198,9 @@ public void shouldUpdateRecordsGenerationIfSnapshotStatusIsParsingInProgress(Tes .then() .statusCode(HttpStatus.SC_CREATED); - ExternalIdsHolder externalIdsHolder = new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()); + ExternalIdsHolder externalIdsHolder = new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9)); Record record1 = new Record() .withId(matchedId) .withSnapshotId(snapshot_1.getJobExecutionId()) @@ -278,7 +287,10 @@ public void shouldReturnNotFoundIfSnapshotDoesNotExist(TestContext testContext) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) .withParsedRecord(marcRecord) - .withMatchedId(matchedId); + .withMatchedId(matchedId) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); RestAssured.given() .spec(spec) @@ -295,7 +307,10 @@ public void shouldReturnNotFoundIfSnapshotDoesNotExist(TestContext testContext) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) .withParsedRecord(marcRecord) - .withMatchedId(matchedId); + .withMatchedId(matchedId) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); RestAssured.given() .spec(spec) @@ -374,7 +389,9 @@ public void shouldReturnSameRecordOnGetByIdAndGetBySRSId(TestContext testContext ParsedRecord parsedRecord = new ParsedRecord().withId(srsId) .withContent(new JsonObject().put("leader", "01542ccm a2200361 4500") - .put("fields", new JsonArray().add(new JsonObject().put("999", new JsonObject() + .put("fields", new JsonArray() + .add(new JsonObject().put("001", RandomStringUtils.randomAlphanumeric(9))) + .add(new JsonObject().put("999", new JsonObject() .put("subfields", new JsonArray().add(new JsonObject().put("s", srsId))) .put("ind1", "f") @@ -386,7 +403,10 @@ public void shouldReturnSameRecordOnGetByIdAndGetBySRSId(TestContext testContext .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) .withParsedRecord(parsedRecord) - .withMatchedId(srsId); + .withMatchedId(srsId) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); RestAssured.given() .spec(spec) @@ -436,7 +456,9 @@ public void shouldReturnRecordOnGetByInstanceId(TestContext testContext) { ParsedRecord parsedRecord = new ParsedRecord().withId(srsId) .withContent(new JsonObject().put("leader", "01542ccm a2200361 4500") - .put("fields", new JsonArray().add(new JsonObject().put("999", new JsonObject() + .put("fields", new JsonArray() + .add(new JsonObject().put("001", RandomStringUtils.randomAlphanumeric(9))) + .add(new JsonObject().put("999", new JsonObject() .put("subfields", new JsonArray().add(new JsonObject().put("s", srsId)).add(new JsonObject().put("i", instanceId))))))); Record newRecord = new Record() @@ -447,7 +469,8 @@ public void shouldReturnRecordOnGetByInstanceId(TestContext testContext) { .withParsedRecord(parsedRecord) .withMatchedId(matchedId) .withExternalIdsHolder(new ExternalIdsHolder() - .withInstanceId(instanceId)); + .withInstanceId(instanceId) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); RestAssured.given() .spec(spec) diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsMatchingApiTest.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsMatchingApiTest.java index 99b343157..57696cc7a 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsMatchingApiTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsMatchingApiTest.java @@ -5,6 +5,7 @@ import io.vertx.ext.unit.Async; import io.vertx.ext.unit.TestContext; import io.vertx.ext.unit.junit.VertxUnitRunner; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.http.HttpStatus; import org.folio.TestUtil; import org.folio.dao.PostgresClientFactory; @@ -255,7 +256,7 @@ public void shouldMatchMarcBibRecordByInstanceIdFieldWithQualifierAndComparePart .withRecordType(MARC_BIB) .withRawRecord(new RawRecord().withId(recordId).withContent(rawRecordContent)) .withParsedRecord(new ParsedRecord().withId(recordId).withContent(parsedRecordContent)) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); postRecords(context, record); @@ -549,14 +550,14 @@ public void shouldMatchRecordByMultiple024FieldsWithWildcardsInd() { @Test public void shouldNotMatchRecordBy035FieldIfRecordExternalIdIsNull(TestContext context) { - String parsedRecordContent = TestUtil.readFileFromPath(PARSED_MARC_WITH_035_FIELD_SAMPLE_PATH); + String parsedRecordContent = TestUtil.readFileFromPath(PARSED_MARC_AUTHORITY_WITH_999_FIELD_SAMPLE_PATH); String recordId = UUID.randomUUID().toString(); Record record = new Record() .withId(recordId) .withMatchedId(recordId) .withSnapshotId(snapshot.getJobExecutionId()) .withGeneration(0) - .withRecordType(MARC_BIB) + .withRecordType(MARC_AUTHORITY) .withRawRecord(new RawRecord().withId(recordId).withContent(rawRecordContent)) .withParsedRecord(new ParsedRecord().withId(recordId).withContent(parsedRecordContent)); @@ -566,9 +567,9 @@ public void shouldNotMatchRecordBy035FieldIfRecordExternalIdIsNull(TestContext c .spec(spec) .when() .body(new RecordMatchingDto() - .withRecordType(RecordMatchingDto.RecordType.MARC_BIB) + .withRecordType(RecordMatchingDto.RecordType.MARC_AUTHORITY) .withFilters(List.of(new Filter() - .withValues(List.of("(OCoLC)63611770", "1234567")) + .withValues(List.of("(OCoLC)63611770", "nin00009530412")) .withField("035") .withIndicator1("") .withIndicator2("") @@ -595,7 +596,7 @@ public void shouldReturnLimitedRecordsIdentifiersCollectionWithLimitAndOffset(Te .withRecordType(MARC_BIB) .withRawRecord(new RawRecord().withId(recordId).withContent(rawRecordContent)) .withParsedRecord(new ParsedRecord().withId(recordId).withContent(parsedRecordContent)) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); postRecords(context, record); } @@ -696,7 +697,7 @@ public void shouldNotReturnTotalRecordsIfReturnTotalRecordsIsFalse(TestContext c .withRecordType(MARC_BIB) .withRawRecord(new RawRecord().withId(recordId).withContent(rawRecordContent)) .withParsedRecord(new ParsedRecord().withId(recordId).withContent(parsedRecordContent)) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); postRecords(context, record); } diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SnapshotApiTest.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SnapshotApiTest.java index f405996b8..fe7c44d3d 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SnapshotApiTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SnapshotApiTest.java @@ -5,6 +5,7 @@ import com.github.tomakehurst.wiremock.matching.RegexPattern; import com.github.tomakehurst.wiremock.matching.UrlPathPattern; import io.restassured.RestAssured; +import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.unit.Async; import io.vertx.ext.unit.TestContext; @@ -13,14 +14,13 @@ import org.folio.TestUtil; import org.folio.dao.PostgresClientFactory; import org.folio.dao.util.SnapshotDaoUtil; -import org.folio.rest.jaxrs.model.ExternalIdsHolder; -import org.folio.rest.jaxrs.model.RawRecord; +import org.folio.rest.jaxrs.model.*; import org.folio.rest.jaxrs.model.Record; -import org.folio.rest.jaxrs.model.Snapshot; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils; import java.io.IOException; import java.util.Arrays; @@ -295,19 +295,24 @@ public void shouldDeleteExistingSnapshotOnDelete(TestContext testContext) { .body("status", is(snapshot_3.getStatus().name())); async.complete(); - String instanceId = UUID.randomUUID().toString(); String recordId = UUID.randomUUID().toString(); + var marcRecordWith001 = new ParsedRecord() + .withContent(new JsonObject().put("fields", new JsonArray().add(new JsonObject().put("001", RandomStringUtils.randomAlphanumeric(9)))).encode()); Record record = new Record() .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId)) + .withParsedRecord(marcRecordWith001) .withSnapshotId(snapshot_3.getJobExecutionId()); List recordIds = Arrays.asList(recordId, UUID.randomUUID().toString()); for (String id : recordIds) { + record.withId(id).withMatchedId(id) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); RestAssured.given() .spec(spec) - .body(record.withId(id).withMatchedId(id)) + .body(record) .when() .post(SOURCE_STORAGE_RECORDS_PATH) .then() diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceRecordApiTest.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceRecordApiTest.java index 12b680f2c..d58b9a8d9 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceRecordApiTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceRecordApiTest.java @@ -15,7 +15,6 @@ import java.util.Arrays; import java.util.Date; import java.util.List; -import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; @@ -27,6 +26,7 @@ import io.vertx.ext.unit.Async; import io.vertx.ext.unit.TestContext; import io.vertx.ext.unit.junit.VertxUnitRunner; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Test; @@ -59,9 +59,13 @@ public class SourceRecordApiTest extends AbstractRestVerticleTest { private static final String SEVENTH_UUID = UUID.randomUUID().toString(); private static final String EIGHTH_UUID = UUID.randomUUID().toString(); private static final String NINTH_UUID = UUID.randomUUID().toString(); + private static final String FIRST_HRID = RandomStringUtils.randomAlphanumeric(9); + private static final String SECOND_HRID = RandomStringUtils.randomAlphanumeric(9); + private static final String THIRD_HRID = RandomStringUtils.randomAlphanumeric(9); private static final RawRecord rawRecord; private static final ParsedRecord marcRecord; + private static final ParsedRecord marcRecordWith001; private static final RawRecord rawEdifactRecord; private static final ParsedRecord parsedEdifactRecord; private static final ParsedRecord invalidParsedRecord; @@ -90,6 +94,8 @@ public class SourceRecordApiTest extends AbstractRestVerticleTest { new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class)); marcRecord = new ParsedRecord() .withContent(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH)); + marcRecordWith001 = new ParsedRecord() + .withContent(new JsonObject().put("fields", new JsonArray().add(new JsonObject().put("001", FIRST_HRID))).encode()); rawEdifactRecord = new RawRecord() .withContent( new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_EDIFACT_RECORD_CONTENT_SAMPLE_PATH), String.class)); @@ -128,6 +134,7 @@ public class SourceRecordApiTest extends AbstractRestVerticleTest { .withSnapshotId(snapshot_1.getJobExecutionId()) .withRecordType(RecordType.MARC_BIB) .withRawRecord(rawRecord) + .withParsedRecord(marcRecordWith001) .withMatchedId(FIRST_UUID) .withOrder(0) .withState(Record.State.ACTUAL) @@ -152,6 +159,7 @@ public class SourceRecordApiTest extends AbstractRestVerticleTest { .withRecordType(RecordType.MARC_BIB) .withRawRecord(rawRecord) .withErrorRecord(errorRecord) + .withParsedRecord(marcRecordWith001) .withMatchedId(THIRD_UUID) .withState(Record.State.ACTUAL) .withExternalIdsHolder(new ExternalIdsHolder() @@ -172,12 +180,15 @@ public class SourceRecordApiTest extends AbstractRestVerticleTest { record_5 = new Record() .withId(FIFTH_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) - .withRecordType(RecordType.MARC_BIB) + .withRecordType(RecordType.MARC_HOLDING) .withRawRecord(rawRecord) .withMatchedId(FIFTH_UUID) .withParsedRecord(invalidParsedRecord) .withOrder(101) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid("12345")); record_6 = new Record() .withId(SIXTH_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -427,7 +438,7 @@ public void shouldReturnBadRequestOnGetIfInvalidExternalIdType(TestContext testC .withMatchedId(FIRST_UUID) .withOrder(11) .withState(Record.State.ACTUAL) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID).withInstanceHrid(SECOND_HRID)); Record secondRecord = new Record().withId(SECOND_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -437,7 +448,7 @@ public void shouldReturnBadRequestOnGetIfInvalidExternalIdType(TestContext testC .withMatchedId(SECOND_UUID) .withOrder(11) .withState(Record.State.ACTUAL) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID).withInstanceHrid(FIRST_HRID)); RestAssured.given() .spec(spec) @@ -454,6 +465,7 @@ public void shouldReturnBadRequestOnGetIfInvalidExternalIdType(TestContext testC .body().as(Record.class); String instanceId = UUID.randomUUID().toString(); + String hrId = RandomStringUtils.randomAlphanumeric(9); Record record = new Record().withId(THIRD_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -463,7 +475,7 @@ public void shouldReturnBadRequestOnGetIfInvalidExternalIdType(TestContext testC .withMatchedId(THIRD_UUID) .withOrder(11) .withState(Record.State.ACTUAL) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId).withInstanceHrid(hrId)); RestAssured.given() .spec(spec) @@ -496,7 +508,7 @@ public void shouldNotReturnSpecificSourceRecordOnGetIfItIsNotExists(TestContext .withMatchedId(FIRST_UUID) .withOrder(11) .withState(Record.State.ACTUAL) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID).withInstanceHrid(SECOND_HRID)); Record secondRecord = new Record().withId(SECOND_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -506,7 +518,7 @@ public void shouldNotReturnSpecificSourceRecordOnGetIfItIsNotExists(TestContext .withMatchedId(SECOND_UUID) .withOrder(11) .withState(Record.State.ACTUAL) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID).withInstanceHrid(FIRST_HRID)); RestAssured.given() .spec(spec) @@ -523,6 +535,7 @@ public void shouldNotReturnSpecificSourceRecordOnGetIfItIsNotExists(TestContext .body().as(Record.class); String instanceId = UUID.randomUUID().toString(); + String hrId = RandomStringUtils.randomAlphanumeric(9); Record record = new Record().withId(THIRD_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -532,7 +545,7 @@ public void shouldNotReturnSpecificSourceRecordOnGetIfItIsNotExists(TestContext .withMatchedId(THIRD_UUID) .withOrder(11) .withState(Record.State.ACTUAL) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId).withInstanceHrid(hrId)); RestAssured.given() .spec(spec) @@ -565,7 +578,7 @@ public void shouldReturnDeletedRecordByExternalIdIfStateIsEmpty(TestContext test .withOrder(11) .withState(Record.State.ACTUAL) .withLeaderRecordStatus("d") - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID).withInstanceHrid(SECOND_HRID)); Record secondRecord = new Record().withId(SECOND_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -576,7 +589,7 @@ public void shouldReturnDeletedRecordByExternalIdIfStateIsEmpty(TestContext test .withOrder(11) .withState(Record.State.DELETED) .withLeaderRecordStatus("d") - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID).withInstanceHrid(FIRST_HRID)); Record thirdRecord = new Record().withId(THIRD_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -587,7 +600,7 @@ public void shouldReturnDeletedRecordByExternalIdIfStateIsEmpty(TestContext test .withOrder(11) .withState(Record.State.DELETED) .withLeaderRecordStatus("d") - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(THIRD_UUID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(THIRD_UUID).withInstanceHrid(THIRD_HRID)); Async async = testContext.async(); Response createResponse = RestAssured.given() @@ -633,14 +646,14 @@ public void shouldReturnDeletedRecordByExternalIdIfStateIsEmpty(TestContext test } @Test - public void shouldReturnEmptyCollectionOnGetByRecordIdIfParsedRecordIsNull(TestContext testContext) { + public void shouldReturnEmptyCollectionOnGetByRecordIdIfParsedRecordIsIncorrect(TestContext testContext) { postSnapshots(testContext, snapshot_1, snapshot_2); - postRecords(testContext, record_1, record_3); + postRecords(testContext, record_1, record_5); Record createdRecord = RestAssured.given() .spec(spec) - .body(record_3) + .body(record_5) .when() .post(SOURCE_STORAGE_RECORDS_PATH) .body().as(Record.class); @@ -748,7 +761,8 @@ public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContex .withParsedRecord(marcRecord) .withMatchedId(firstMatchedId) .withOrder(1) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID).withInstanceHrid(FIRST_HRID)); String secondMathcedId = UUID.randomUUID().toString(); @@ -760,7 +774,8 @@ public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContex .withParsedRecord(marcRecord) .withMatchedId(secondMathcedId) .withOrder(11) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID).withInstanceHrid(SECOND_HRID)); postRecords(testContext, record_2, record_2_tmp, record_4, record_4_tmp, record_7); @@ -800,8 +815,8 @@ public void shouldReturnSortedMarcBibSourceRecordsOnGetWhenSortByOrderIsSpecifie .get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?snapshotId=" + snapshot_2.getJobExecutionId() + "&orderBy=order") .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(2)) - .body("totalRecords", is(2)) + .body("sourceRecords.size()", is(3)) + .body("totalRecords", is(3)) .body("sourceRecords*.recordType", everyItem(is(RecordType.MARC_BIB.name()))) .body("sourceRecords*.deleted", everyItem(is(false))) .extract().response().body().as(SourceRecordCollection.class).getSourceRecords(); @@ -868,18 +883,21 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { postRecords(testContext, record_6); Async async = testContext.async(); - // NOTE: we do not expect record_3 or record_5 as they do not have a parsed record + List sourceRecordList = RestAssured.given() .spec(spec) .when() .get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedAfter=" + from + "&updatedBefore=" + to) .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(2)) - .body("totalRecords", is(2)) + .body("sourceRecords.size()", is(3)) + .body("totalRecords", is(3)) .body("sourceRecords*.deleted", everyItem(is(false))) .extract().response().body().as(SourceRecordCollection.class).getSourceRecords(); + // NOTE: we do not expect record_5 as they do not have a parsed record + testContext.assertTrue(sourceRecordList.stream().map(SourceRecord::getRecordId).noneMatch(id -> id.equals(record_5.getId()))); + testContext.assertTrue(sourceRecordList.get(0).getMetadata().getUpdatedDate().after(fromDate)); testContext.assertTrue(sourceRecordList.get(1).getMetadata().getUpdatedDate().after(fromDate)); testContext.assertTrue(sourceRecordList.get(0).getMetadata().getUpdatedDate().before(toDate)); @@ -893,8 +911,8 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { .get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedAfter=" + from) .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(3)) - .body("totalRecords", is(3)) + .body("sourceRecords.size()", is(4)) + .body("totalRecords", is(4)) .body("sourceRecords*.deleted", everyItem(is(false))); async.complete(); @@ -910,7 +928,7 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { .body("sourceRecords*.deleted", everyItem(is(false))); async.complete(); - // NOTE: we do not expect record_1 id does not have a parsed record + // NOTE: we do not expect record_5 id does not have a parsed record async = testContext.async(); RestAssured.given() .spec(spec) @@ -918,11 +936,15 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { .get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedBefore=" + to) .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(2)) - .body("totalRecords", is(2)) + .body("sourceRecords.size()", is(4)) + .body("totalRecords", is(4)) .body("sourceRecords*.deleted", everyItem(is(false))); async.complete(); + testContext.assertTrue(sourceRecordList.stream() + .map(SourceRecord::getRecordId) + .noneMatch(id -> id.equals(record_5.getId()) || id.equals(record_6.getId()))); + async = testContext.async(); RestAssured.given() .spec(spec) @@ -930,8 +952,8 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { .get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedBefore=" + from) .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(0)) - .body("totalRecords", is(0)); + .body("sourceRecords.size()", is(1)) + .body("totalRecords", is(1)); async.complete(); } @@ -941,6 +963,7 @@ public void shouldReturnSourceRecordsByListOfId(TestContext testContext) { String firstSrsId = UUID.randomUUID().toString(); String firstInstanceId = UUID.randomUUID().toString(); + String firstHrId = RandomStringUtils.randomAlphanumeric(9); ParsedRecord parsedRecord = new ParsedRecord().withId(firstSrsId) .withContent(new JsonObject().put("leader", "01542dcm a2200361 4500") @@ -948,7 +971,7 @@ public void shouldReturnSourceRecordsByListOfId(TestContext testContext) { .put("subfields", new JsonArray().add(new JsonObject().put("s", firstSrsId)).add(new JsonObject().put("i", firstInstanceId))) .put("ind1", "f") - .put("ind2", "f")))).encode()); + .put("ind2", "f"))).add(new JsonObject().put("001", firstHrId))).encode()); Record deleted_record_1 = new Record() .withId(firstSrsId) @@ -961,10 +984,12 @@ public void shouldReturnSourceRecordsByListOfId(TestContext testContext) { .withOrder(11) .withState(Record.State.ACTUAL) .withExternalIdsHolder(new ExternalIdsHolder() - .withInstanceId(firstInstanceId)); + .withInstanceId(firstInstanceId) + .withInstanceHrid(firstHrId)); String secondSrsId = UUID.randomUUID().toString(); String secondInstanceId = UUID.randomUUID().toString(); + String secondHrId = RandomStringUtils.randomAlphanumeric(9); Record deleted_record_2 = new Record() .withId(secondSrsId) @@ -976,13 +1001,13 @@ public void shouldReturnSourceRecordsByListOfId(TestContext testContext) { .withOrder(1) .withState(Record.State.DELETED) .withExternalIdsHolder(new ExternalIdsHolder() - .withInstanceId(secondInstanceId)); + .withInstanceId(secondInstanceId) + .withInstanceHrid(secondHrId)); Record[] records = new Record[] {record_1, record_2, record_3, record_4, record_6, deleted_record_1, deleted_record_2}; postRecords(testContext, records); List ids = Arrays.stream(records) - .filter(record -> Objects.nonNull(record.getParsedRecord())) .map(Record::getId) .collect(Collectors.toList()); @@ -994,8 +1019,8 @@ public void shouldReturnSourceRecordsByListOfId(TestContext testContext) { .post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=RECORD&deleted=false") .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(4)) - .body("totalRecords", is(4)) + .body("sourceRecords.size()", is(6)) + .body("totalRecords", is(6)) .body("sourceRecords*.deleted", everyItem(is(false))); async.complete(); @@ -1007,12 +1032,11 @@ public void shouldReturnSourceRecordsByListOfId(TestContext testContext) { .post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=RECORD&deleted=true") .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(5)) - .body("totalRecords", is(5)); + .body("sourceRecords.size()", is(7)) + .body("totalRecords", is(7)); async.complete(); List externalIds = Arrays.stream(records) - .filter(record -> Objects.nonNull(record.getParsedRecord())) .map(record -> record.getExternalIdsHolder().getInstanceId()) .collect(Collectors.toList()); @@ -1024,8 +1048,8 @@ public void shouldReturnSourceRecordsByListOfId(TestContext testContext) { .post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=INSTANCE&deleted=false") .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(4)) - .body("totalRecords", is(4)) + .body("sourceRecords.size()", is(6)) + .body("totalRecords", is(6)) .body("sourceRecords*.deleted", everyItem(is(false))); async.complete(); @@ -1037,8 +1061,8 @@ public void shouldReturnSourceRecordsByListOfId(TestContext testContext) { .post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=INSTANCE&deleted=true") .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(5)) - .body("totalRecords", is(5)); + .body("sourceRecords.size()", is(7)) + .body("totalRecords", is(7)); async.complete(); async = testContext.async(); @@ -1049,8 +1073,8 @@ public void shouldReturnSourceRecordsByListOfId(TestContext testContext) { .post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=RECORD") .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(4)) - .body("totalRecords", is(4)); + .body("sourceRecords.size()", is(6)) + .body("totalRecords", is(6)); async.complete(); } @@ -1068,7 +1092,7 @@ public void shouldReturnEmptyListOnGetResultsIfNoRecordsExist() { @Test public void shouldReturnMarcBibParsedResultsOnGetWhenNoQueryIsSpecified(TestContext testContext) { - shouldReturnMarcParsedResultsOnGetWhenNoQueryIsSpecified(testContext, snapshot_3, record_7, 2, RecordType.MARC_BIB); + shouldReturnMarcParsedResultsOnGetWhenNoQueryIsSpecified(testContext, snapshot_3, record_7, 4, RecordType.MARC_BIB); } @Test @@ -1099,7 +1123,8 @@ public void shouldReturnParsedResultsWithAnyStateWithNoParametersSpecified(TestC .withParsedRecord(marcRecord) .withMatchedId(SECOND_UUID) .withOrder(1) - .withState(Record.State.OLD); + .withState(Record.State.OLD) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID).withInstanceHrid(FIRST_HRID)); Record recordWithoutDeletedState = new Record() .withId(THIRD_UUID) @@ -1109,7 +1134,8 @@ public void shouldReturnParsedResultsWithAnyStateWithNoParametersSpecified(TestC .withParsedRecord(marcRecord) .withMatchedId(THIRD_UUID) .withOrder(0) - .withState(Record.State.DELETED); + .withState(Record.State.DELETED) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(THIRD_UUID).withInstanceHrid(FIRST_HRID)); Record recordWithActualState = new Record() .withId(FOURTH_UUID) @@ -1119,19 +1145,10 @@ public void shouldReturnParsedResultsWithAnyStateWithNoParametersSpecified(TestC .withParsedRecord(marcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) - .withState(Record.State.ACTUAL); - - Record recordWithoutParsedRecord = new Record() - .withId(FIRST_UUID) - .withSnapshotId(snapshot_1.getJobExecutionId()) - .withRecordType(Record.RecordType.MARC_BIB) - .withRawRecord(rawRecord) - .withMatchedId(FIRST_UUID) - .withOrder(0) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FOURTH_UUID).withInstanceHrid(FIRST_HRID)); - postRecords(testContext, recordWithOldState, recordWithoutDeletedState, recordWithActualState, - recordWithoutParsedRecord); + postRecords(testContext, recordWithOldState, recordWithoutDeletedState, recordWithActualState); Async async = testContext.async(); RestAssured.given() @@ -1158,7 +1175,7 @@ public void shouldReturnResultsOnGetBySpecifiedSnapshotId(TestContext testContex .get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?snapshotId=" + record_2.getSnapshotId()) .then() .statusCode(HttpStatus.SC_OK) - .body("totalRecords", is(1)) + .body("totalRecords", is(2)) .body("sourceRecords*.snapshotId", everyItem(is(record_2.getSnapshotId()))) .body("sourceRecords*.deleted", everyItem(is(false))) .body("sourceRecords*.additionalInfo.suppressDiscovery", everyItem(is(false))); @@ -1217,7 +1234,10 @@ public void shouldReturnAllSourceRecordsMarkedAsDeletedOnFindByRecordStateDelete .withParsedRecord(marcRecord) .withMatchedId(matchedId) .withOrder(11) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(matchedId) + .withInstanceHrid("12345")); async = testContext.async(); createParsed = RestAssured.given() @@ -1324,6 +1344,7 @@ public void shouldReturnSourceRecordWithAdditionalInfoOnGetBySpecifiedSnapshotId .withRawRecord(rawRecord) .withParsedRecord(marcRecord) .withMatchedId(matchedId) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID).withInstanceHrid(FIRST_HRID)) .withAdditionalInfo( new AdditionalInfo().withSuppressDiscovery(true)); @@ -1367,6 +1388,7 @@ public void shouldReturnActualRecordsOnFilteringByDeleted(TestContext testContex .withParsedRecord(marcRecord) .withMatchedId(UUID.randomUUID().toString()) .withLeaderRecordStatus("d") + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID).withInstanceHrid(FIRST_HRID)) .withState(Record.State.OLD); Record record2 = new Record() @@ -1377,6 +1399,7 @@ public void shouldReturnActualRecordsOnFilteringByDeleted(TestContext testContex .withParsedRecord(marcRecord) .withMatchedId(UUID.randomUUID().toString()) .withLeaderRecordStatus("d") + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID).withInstanceHrid(SECOND_HRID)) .withState(Record.State.ACTUAL); Record record3 = new Record() @@ -1387,6 +1410,7 @@ public void shouldReturnActualRecordsOnFilteringByDeleted(TestContext testContex .withParsedRecord(marcRecord) .withMatchedId(UUID.randomUUID().toString()) .withLeaderRecordStatus("d") + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(THIRD_UUID).withInstanceHrid(THIRD_HRID)) .withState(Record.State.DELETED); postRecords(testContext, record1, record2, record3); @@ -1443,7 +1467,7 @@ private void returnSpecificMarcSourceRecordOnGetByDefaultExternalId(TestContext .withMatchedId(FIRST_UUID) .withOrder(11) .withState(Record.State.ACTUAL); - setExternalIds(firstRecord, recordType, SECOND_UUID, null); + setExternalIds(firstRecord, recordType, SECOND_UUID, SECOND_HRID); Record secondRecord = new Record().withId(SECOND_UUID) .withSnapshotId(snapshot_4.getJobExecutionId()) @@ -1453,7 +1477,7 @@ private void returnSpecificMarcSourceRecordOnGetByDefaultExternalId(TestContext .withMatchedId(SECOND_UUID) .withOrder(11) .withState(Record.State.ACTUAL); - setExternalIds(secondRecord, recordType, FIRST_UUID, null); + setExternalIds(secondRecord, recordType, FIRST_UUID, FIRST_HRID); RestAssured.given() .spec(spec) @@ -1503,7 +1527,7 @@ private void returnSpecificMarcSourceRecordOnGetByExternalId(TestContext testCon .withMatchedId(FIRST_UUID) .withOrder(11) .withState(Record.State.ACTUAL); - setExternalIds(firstRecord, recordType, SECOND_UUID, null); + setExternalIds(firstRecord, recordType, SECOND_UUID, SECOND_HRID); Record secondRecord = new Record().withId(SECOND_UUID) .withSnapshotId(snapshot.getJobExecutionId()) @@ -1513,7 +1537,7 @@ private void returnSpecificMarcSourceRecordOnGetByExternalId(TestContext testCon .withMatchedId(SECOND_UUID) .withOrder(11) .withState(Record.State.ACTUAL); - setExternalIds(secondRecord, recordType, FIRST_UUID, null); + setExternalIds(secondRecord, recordType, FIRST_UUID, FIRST_HRID); RestAssured.given() .spec(spec) @@ -1530,6 +1554,7 @@ private void returnSpecificMarcSourceRecordOnGetByExternalId(TestContext testCon .body().as(Record.class); String externalId = UUID.randomUUID().toString(); + String externalHrId = RandomStringUtils.randomAlphanumeric(9); Record recordWithOldState = new Record().withId(FOURTH_UUID) .withSnapshotId(snapshot.getJobExecutionId()) @@ -1539,7 +1564,7 @@ private void returnSpecificMarcSourceRecordOnGetByExternalId(TestContext testCon .withMatchedId(FOURTH_UUID) .withOrder(11) .withState(Record.State.OLD); - setExternalIds(recordWithOldState, recordType, externalId, null); + setExternalIds(recordWithOldState, recordType, externalId, externalHrId); Record record = new Record().withId(THIRD_UUID) .withSnapshotId(snapshot.getJobExecutionId()) @@ -1549,7 +1574,7 @@ private void returnSpecificMarcSourceRecordOnGetByExternalId(TestContext testCon .withMatchedId(THIRD_UUID) .withOrder(11) .withState(Record.State.ACTUAL); - setExternalIds(record, recordType, externalId, null); + setExternalIds(record, recordType, externalId, externalHrId); RestAssured.given() .spec(spec) @@ -1724,7 +1749,7 @@ private void returnSpecificMarcSourceRecordOnGetByRecordExternalId(TestContext t .withMatchedId(FIRST_UUID) .withOrder(11) .withState(Record.State.ACTUAL); - setExternalIds(firstRecord, recordType, SECOND_UUID, null); + setExternalIds(firstRecord, recordType, SECOND_UUID, SECOND_HRID); Record secondRecord = new Record().withId(SECOND_UUID) .withSnapshotId(snapshot.getJobExecutionId()) @@ -1734,7 +1759,7 @@ private void returnSpecificMarcSourceRecordOnGetByRecordExternalId(TestContext t .withMatchedId(SECOND_UUID) .withOrder(11) .withState(Record.State.ACTUAL); - setExternalIds(secondRecord, recordType, FIRST_UUID, null); + setExternalIds(secondRecord, recordType, FIRST_UUID, FIRST_HRID); Record recordWithOldState = new Record().withId(FIFTH_UUID) .withSnapshotId(snapshot.getJobExecutionId()) @@ -1744,7 +1769,7 @@ private void returnSpecificMarcSourceRecordOnGetByRecordExternalId(TestContext t .withMatchedId(FIFTH_UUID) .withOrder(11) .withState(Record.State.OLD); - setExternalIds(recordWithOldState, recordType, FIRST_UUID, null); + setExternalIds(recordWithOldState, recordType, FIRST_UUID, FIRST_HRID); RestAssured.given() .spec(spec) @@ -1768,6 +1793,7 @@ private void returnSpecificMarcSourceRecordOnGetByRecordExternalId(TestContext t .body().as(Record.class); String instanceId = UUID.randomUUID().toString(); + String hrId = RandomStringUtils.randomAlphanumeric(9); Record record = new Record().withId(THIRD_UUID) .withSnapshotId(snapshot.getJobExecutionId()) @@ -1777,7 +1803,7 @@ private void returnSpecificMarcSourceRecordOnGetByRecordExternalId(TestContext t .withMatchedId(THIRD_UUID) .withOrder(11) .withState(Record.State.ACTUAL); - setExternalIds(record, recordType, instanceId, null); + setExternalIds(record, recordType, instanceId, hrId); RestAssured.given() .spec(spec) @@ -1824,7 +1850,7 @@ private void returnSpecificMarcSourceRecordOnGetByRecordExternalIdAndRecordState .withMatchedId(FIRST_UUID) .withOrder(11) .withState(state); - setExternalIds(recordWithState, recordType, SECOND_UUID, null); + setExternalIds(recordWithState, recordType, SECOND_UUID, SECOND_HRID); RestAssured.given() .spec(spec) diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageBatchApiTest.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageBatchApiTest.java index ce8d9a661..9f3c32dee 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageBatchApiTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageBatchApiTest.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.http.HttpStatus; import org.folio.TestMocks; import org.folio.TestUtil; @@ -71,9 +72,12 @@ public class SourceStorageBatchApiTest extends AbstractRestVerticleTest { private static final String FOURTH_UUID = UUID.randomUUID().toString(); private static final String FIFTH_UUID = UUID.randomUUID().toString(); private static final String VALID_HRID = "12345"; + private static final String MARC_RECORD_HRID = "393893"; + private static final String HRID = RandomStringUtils.randomAlphanumeric(9); private static RawRecord rawRecord; private static ParsedRecord marcRecord; + private static ParsedRecord marcRecordWithHrId; static { try { @@ -81,6 +85,8 @@ public class SourceStorageBatchApiTest extends AbstractRestVerticleTest { .withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class)); marcRecord = new ParsedRecord() .withContent(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH)); + marcRecordWithHrId = new ParsedRecord() + .withContent(new JsonObject().put("fields", new JsonArray().add(new JsonObject().put("001", HRID))).encode()); } catch (IOException e) { e.printStackTrace(); } @@ -105,11 +111,13 @@ public class SourceStorageBatchApiTest extends AbstractRestVerticleTest { .withSnapshotId(snapshot_1.getJobExecutionId()) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) + .withParsedRecord(marcRecordWithHrId) .withMatchedId(FIRST_UUID) .withOrder(0) .withState(Record.State.ACTUAL) .withExternalIdsHolder(new ExternalIdsHolder() - .withInstanceId(UUID.randomUUID().toString())); + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(HRID)); private static Record record_2 = new Record() .withId(SECOND_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -120,17 +128,20 @@ public class SourceStorageBatchApiTest extends AbstractRestVerticleTest { .withOrder(11) .withState(Record.State.ACTUAL) .withExternalIdsHolder(new ExternalIdsHolder() - .withInstanceId(UUID.randomUUID().toString())); + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(MARC_RECORD_HRID)); private static Record record_3 = new Record() .withId(THIRD_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) + .withParsedRecord(marcRecordWithHrId) .withErrorRecord(errorRecord) .withMatchedId(THIRD_UUID) .withState(Record.State.ACTUAL) .withExternalIdsHolder(new ExternalIdsHolder() - .withInstanceId(UUID.randomUUID().toString())); + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(HRID)); private static Record record_4 = new Record() .withId(FOURTH_UUID) .withSnapshotId(snapshot_1.getJobExecutionId()) @@ -139,6 +150,9 @@ public class SourceStorageBatchApiTest extends AbstractRestVerticleTest { .withParsedRecord(marcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(MARC_RECORD_HRID)) .withState(Record.State.ACTUAL); private static Record record_5 = new Record() .withId(FIFTH_UUID) @@ -601,6 +615,9 @@ public void shouldReturnBadRequestIfMarcBibIdsAreNotDefined(TestContext testCont .withParsedRecord(marcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(VALID_HRID)) .withState(Record.State.OLD); postRecords(testContext, record_1, record_2, record_3, recordWithOldStatus); @@ -785,6 +802,9 @@ public void shouldUpdateParsedRecords(TestContext testContext) { .withParsedRecord(parsedRecord) .withMatchedId(matchedId) .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(matchedId) + .withInstanceHrid(VALID_HRID)) .withAdditionalInfo( new AdditionalInfo().withSuppressDiscovery(false)); @@ -876,6 +896,9 @@ public void shouldUpdateParsedRecordsWithJsonContent(TestContext testContext) { .withRawRecord(rawRecord) .withParsedRecord(marcRecord) .withMatchedId(UUID.randomUUID().toString()) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(VALID_HRID)) .withAdditionalInfo( new AdditionalInfo().withSuppressDiscovery(false)); diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageStreamApiTest.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageStreamApiTest.java index df3dfdbbb..b800aadd2 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageStreamApiTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageStreamApiTest.java @@ -7,10 +7,12 @@ import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.unit.Async; import io.vertx.ext.unit.TestContext; import io.vertx.ext.unit.junit.VertxUnitRunner; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.http.HttpStatus; import org.folio.TestUtil; import org.folio.dao.PostgresClientFactory; @@ -62,9 +64,11 @@ public class SourceStorageStreamApiTest extends AbstractRestVerticleTest { private static final String SIXTH_UUID = UUID.randomUUID().toString(); private static final String SEVENTH_UUID = UUID.randomUUID().toString(); private static final String EIGHTH_UUID = UUID.randomUUID().toString(); + private static final String FIRST_HRID = RandomStringUtils.randomAlphanumeric(9); private static RawRecord rawRecord; private static ParsedRecord marcRecord; + private static ParsedRecord marcRecordWith001; static { try { @@ -72,13 +76,13 @@ public class SourceStorageStreamApiTest extends AbstractRestVerticleTest { .withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class)); marcRecord = new ParsedRecord() .withContent(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH)); + marcRecordWith001 = new ParsedRecord() + .withContent(new JsonObject().put("fields", new JsonArray().add(new JsonObject().put("001", FIRST_HRID))).encode()); } catch (IOException e) { e.printStackTrace(); } } - private static final ParsedRecord invalidParsedRecord = new ParsedRecord() - .withContent("Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."); private static final ErrorRecord errorRecord = new ErrorRecord() .withDescription("Oops... something happened") .withContent("Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."); @@ -98,9 +102,13 @@ public class SourceStorageStreamApiTest extends AbstractRestVerticleTest { .withSnapshotId(snapshot_1.getJobExecutionId()) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) + .withParsedRecord(marcRecordWith001) .withMatchedId(FIRST_UUID) .withOrder(0) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FIFTH_UUID) + .withInstanceHrid(FIRST_HRID)); private static final Record marc_bib_record_2 = new Record() .withId(SECOND_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -112,15 +120,20 @@ public class SourceStorageStreamApiTest extends AbstractRestVerticleTest { .withState(Record.State.ACTUAL) .withExternalIdsHolder(new ExternalIdsHolder() .withInstanceId(UUID.randomUUID().toString()) - .withInstanceHrid("12345")); + .withInstanceHrid(FIRST_HRID)); private static final Record marc_bib_record_3 = new Record() .withId(THIRD_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) + .withParsedRecord(marcRecordWith001) .withErrorRecord(errorRecord) + .withOrder(101) .withMatchedId(THIRD_UUID) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FIFTH_UUID) + .withInstanceHrid(FIRST_HRID)); private static final Record marc_bib_record_4 = new Record() .withId(FOURTH_UUID) .withSnapshotId(snapshot_1.getJobExecutionId()) @@ -132,17 +145,8 @@ public class SourceStorageStreamApiTest extends AbstractRestVerticleTest { .withState(Record.State.ACTUAL) .withExternalIdsHolder(new ExternalIdsHolder() .withInstanceId(UUID.randomUUID().toString()) - .withInstanceHrid("12345")); + .withInstanceHrid(FIRST_HRID)); private static final Record marc_bib_record_5 = new Record() - .withId(FIFTH_UUID) - .withSnapshotId(snapshot_2.getJobExecutionId()) - .withRecordType(Record.RecordType.MARC_BIB) - .withRawRecord(rawRecord) - .withMatchedId(FIFTH_UUID) - .withParsedRecord(invalidParsedRecord) - .withOrder(101) - .withState(Record.State.ACTUAL); - private static final Record marc_bib_record_6 = new Record() .withId(SIXTH_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) .withRecordType(Record.RecordType.MARC_BIB) @@ -153,7 +157,7 @@ public class SourceStorageStreamApiTest extends AbstractRestVerticleTest { .withState(Record.State.ACTUAL) .withExternalIdsHolder(new ExternalIdsHolder() .withInstanceId(UUID.randomUUID().toString()) - .withInstanceHrid("12345")); + .withInstanceHrid(FIRST_HRID)); private static final Record marc_auth_record_1 = new Record() .withId(SEVENTH_UUID) .withSnapshotId(snapshot_2.getJobExecutionId()) @@ -222,7 +226,10 @@ public void shouldReturnAllRecordsWithNotEmptyStateOnGetWhenNoQueryIsSpecified(T .withParsedRecord(marcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) - .withState(Record.State.OLD); + .withState(Record.State.OLD) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FIFTH_UUID) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, marc_bib_record_1, marc_bib_record_2, marc_bib_record_3, record_4); @@ -266,6 +273,9 @@ private void shouldReturnAllMarcRecordsWithNotEmptyStateOnGetWhenNoQueryIsSpecif .withParsedRecord(marcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FIFTH_UUID) + .withInstanceHrid(FIRST_HRID)) .withState(Record.State.OLD); postRecords(testContext, marc_bib_record_1, marc_bib_record_2, marc_bib_record_3, record_4, marc_auth_record_1); @@ -301,7 +311,10 @@ public void shouldReturnRecordsOnGetBySpecifiedSnapshotId(TestContext testContex .withParsedRecord(marcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) - .withState(Record.State.OLD); + .withState(Record.State.OLD) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FIFTH_UUID) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, marc_bib_record_1, marc_bib_record_2, marc_bib_record_3, recordWithOldStatus); @@ -386,7 +399,10 @@ public void shouldReturnLimitedCollectionWithActualStateOnGetWithLimit(TestConte .withParsedRecord(marcRecord) .withMatchedId(FOURTH_UUID) .withOrder(1) - .withState(Record.State.OLD); + .withState(Record.State.OLD) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FIFTH_UUID) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, marc_bib_record_1, marc_bib_record_2, marc_bib_record_3, recordWithOldStatus); @@ -682,7 +698,10 @@ public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContex .withParsedRecord(marcRecord) .withMatchedId(firstMatchedId) .withOrder(1) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(SECOND_UUID) + .withInstanceHrid(FIRST_HRID)); String secondMathcedId = UUID.randomUUID().toString(); @@ -694,7 +713,10 @@ public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContex .withParsedRecord(marcRecord) .withMatchedId(secondMathcedId) .withOrder(11) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FIFTH_UUID) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, marc_bib_record_2, record_2_tmp, marc_bib_record_4, record_4_tmp); @@ -732,8 +754,7 @@ public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContex public void shouldReturnSortedSourceRecordsOnGetWhenSortByOrderIsSpecified(TestContext testContext) { postSnapshots(testContext, snapshot_2); - // NOTE: record_5 saves but fails parsed record content validation and does not save parsed record - postRecords(testContext, marc_bib_record_2, marc_bib_record_3, marc_bib_record_5, marc_bib_record_6); + postRecords(testContext, marc_bib_record_2, marc_bib_record_3); final Async async = testContext.async(); InputStream response = RestAssured.given() @@ -771,8 +792,7 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { Date fromDate = new Date(); String from = dateTimeFormatter.format(ZonedDateTime.ofInstant(fromDate.toInstant(), ZoneId.systemDefault())); - // NOTE: record_5 saves but fails parsed record content validation and does not save parsed record - postRecords(testContext, marc_bib_record_2, marc_bib_record_3, marc_bib_record_4, marc_bib_record_5); + postRecords(testContext, marc_bib_record_2, marc_bib_record_3, marc_bib_record_4); Date toDate = new Date(); String to = dateTimeFormatter.format(ZonedDateTime.ofInstant(toDate.toInstant(), ZoneId.systemDefault())); @@ -780,7 +800,7 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { Async async = testContext.async(); RestAssured.given() .spec(spec) - .body(marc_bib_record_6) + .body(marc_bib_record_5) .when() .post(SOURCE_STORAGE_RECORDS_PATH) .then() @@ -788,7 +808,7 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { async.complete(); final Async finalAsync = testContext.async(); - // NOTE: we do not expect record_3 or record_5 as they do not have a parsed record + // NOTE: we do not marc_holdings_record_2 as they do not have a parsed record InputStream result = RestAssured.given() .spec(spec) .when() @@ -813,8 +833,8 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { .get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedAfter=" + from) .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(3)) - .body("totalRecords", is(3)) + .body("sourceRecords.size()", is(4)) + .body("totalRecords", is(4)) .body("sourceRecords*.deleted", everyItem(is(false))); innerAsync.complete(); @@ -830,7 +850,6 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { .body("sourceRecords*.deleted", everyItem(is(false))); innerAsync.complete(); - // NOTE: we do not expect record_1 id does not have a parsed record innerAsync = testContext.async(); RestAssured.given() .spec(spec) @@ -838,8 +857,8 @@ public void shouldReturnSourceRecordsForPeriod(TestContext testContext) { .get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedBefore=" + to) .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecords.size()", is(2)) - .body("totalRecords", is(2)) + .body("sourceRecords.size()", is(3)) + .body("totalRecords", is(3)) .body("sourceRecords*.deleted", everyItem(is(false))); innerAsync.complete(); @@ -1100,6 +1119,9 @@ public void shouldReturnEmptyResponseOnSearchMarcRecordIdsWhenRecordWasSuppresse .withParsedRecord(marc_bib_record_2.getParsedRecord()) .withMatchedId(marc_bib_record_2.getMatchedId()) .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FIFTH_UUID) + .withInstanceHrid(FIRST_HRID)) .withAdditionalInfo(new AdditionalInfo().withSuppressDiscovery(true)); postSnapshots(testContext, snapshot_2); postRecords(testContext, suppressedRecord); @@ -1107,6 +1129,7 @@ public void shouldReturnEmptyResponseOnSearchMarcRecordIdsWhenRecordWasSuppresse MarcRecordSearchRequest searchRequest = new MarcRecordSearchRequest(); searchRequest.setLeaderSearchExpression("p_05 = 'c' and p_06 = 'c' and p_07 = 'm'"); searchRequest.setFieldsSearchExpression("001.value = '393893' and 005.value ^= '2014110' and 035.ind1 = '#'"); + searchRequest.setSuppressFromDiscovery(false); // when ExtractableResponse response = RestAssured.given() .spec(spec) @@ -1357,40 +1380,6 @@ public void shouldReturnEmptyResponseOnSearchMarcRecordIdsWhenMarcBibAndAuthorit async.complete(); } - @Test - public void shouldReturnEmptyResponseOnSearchMarcRecordIdsWhenInstanceIdIsMissing(TestContext testContext) { - // given - final Async async = testContext.async(); - postSnapshots(testContext, snapshot_2); - Record marc_bib_record_withoutInstanceId = new Record() - .withId(SECOND_UUID) - .withSnapshotId(snapshot_2.getJobExecutionId()) - .withRecordType(Record.RecordType.MARC_BIB) - .withRawRecord(rawRecord) - .withParsedRecord(marcRecord) - .withMatchedId(SECOND_UUID) - .withOrder(11) - .withState(Record.State.ACTUAL); - postRecords(testContext, marc_bib_record_withoutInstanceId); - - MarcRecordSearchRequest searchRequest = new MarcRecordSearchRequest(); - searchRequest.setFieldsSearchExpression("001.value = '393893'"); - // when - ExtractableResponse response = RestAssured.given() - .spec(spec) - .body(searchRequest) - .when() - .post("/source-storage/stream/marc-record-identifiers") - .then() - .extract(); - JsonObject responseBody = new JsonObject(response.body().asString()); - // then - assertEquals(HttpStatus.SC_OK, response.statusCode()); - assertEquals(0, responseBody.getJsonArray("records").size()); - assertEquals(0, responseBody.getInteger("totalCount").intValue()); - async.complete(); - } - @Test public void shouldReturnIdOnSearchMarcRecordIdsWhenInstanceIdIsMissing(TestContext testContext) { // given @@ -1404,7 +1393,10 @@ public void shouldReturnIdOnSearchMarcRecordIdsWhenInstanceIdIsMissing(TestConte .withParsedRecord(marcRecord) .withMatchedId(SECOND_UUID) .withOrder(11) - .withState(Record.State.ACTUAL); + .withState(Record.State.ACTUAL) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(FIFTH_UUID) + .withInstanceHrid(FIRST_HRID)); postRecords(testContext, marc_bib_record_2, marc_bib_record_withoutInstanceId); MarcRecordSearchRequest searchRequest = new MarcRecordSearchRequest(); diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/TestMarcRecordsApiTest.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/TestMarcRecordsApiTest.java index 0b350dfa3..72f3cb731 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/TestMarcRecordsApiTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/TestMarcRecordsApiTest.java @@ -7,6 +7,7 @@ import org.folio.TestUtil; import org.folio.rest.jaxrs.model.RawRecord; import org.folio.rest.jaxrs.model.TestMarcRecordsCollection; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -20,6 +21,7 @@ public class TestMarcRecordsApiTest extends AbstractRestVerticleTest { private static final String POPULATE_TEST_MARK_RECORDS_PATH = "/source-storage/populate-test-marc-records"; @Test + @Ignore("Deprecated endpoint") public void shouldReturnNoContentOnPostRecordCollectionPassedInBody() throws IOException { RawRecord rawRecord = new RawRecord().withContent( new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class)); @@ -35,6 +37,7 @@ public void shouldReturnNoContentOnPostRecordCollectionPassedInBody() throws IOE } @Test + @Ignore("Deprecated endpoint") public void shouldReturnUnprocessableEntityOnPostWhenNoRecordCollectionPassedInBody() { TestMarcRecordsCollection testMarcRecordsCollection = new TestMarcRecordsCollection() .withRawRecords(Collections.singletonList(new RawRecord())); diff --git a/mod-source-record-storage-server/src/test/java/org/folio/services/AuthorityLinkChunkKafkaHandlerTest.java b/mod-source-record-storage-server/src/test/java/org/folio/services/AuthorityLinkChunkKafkaHandlerTest.java index 870b83ac4..1044dec9c 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/services/AuthorityLinkChunkKafkaHandlerTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/services/AuthorityLinkChunkKafkaHandlerTest.java @@ -32,6 +32,7 @@ import net.mguenther.kafka.junit.KeyValue; import net.mguenther.kafka.junit.ReadKeyValues; import net.mguenther.kafka.junit.SendKeyValues; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomUtils; import org.folio.TestUtil; import org.folio.dao.RecordDao; @@ -77,10 +78,12 @@ public class AuthorityLinkChunkKafkaHandlerTest extends AbstractLBServiceTest { private static final String LINKED_BIB_UPDATE_JOB_ID = UUID.randomUUID().toString(); private static final String RECORD_ID = UUID.randomUUID().toString(); private static final String INSTANCE_ID = UUID.randomUUID().toString(); + private static final String HR_ID = RandomStringUtils.randomAlphanumeric(9); private static final String SECOND_RECORD_ID = UUID.randomUUID().toString(); private static final String SECOND_INSTANCE_ID = UUID.randomUUID().toString(); private static final String ERROR_RECORD_ID = UUID.randomUUID().toString(); private static final String ERROR_INSTANCE_ID = UUID.randomUUID().toString(); + private static final String ERROR_HR_ID = RandomStringUtils.randomAlphanumeric(9); private static final String ERROR_RECORD_DESCRIPTION = "test error"; private static final Integer LINK_ID = RandomUtils.nextInt(); private static final String USER_ID = UUID.randomUUID().toString(); @@ -121,7 +124,7 @@ record = new Record() .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) .withParsedRecord(parsedRecord) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(INSTANCE_ID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(INSTANCE_ID).withInstanceHrid(HR_ID)); var secondParsedRecord = new ParsedRecord().withId(SECOND_RECORD_ID) .withContent(new JsonObject(TestUtil.readFileFromPath(PARSED_MARC_RECORD_LINKED_PATH)).encode()); @@ -132,7 +135,7 @@ record = new Record() .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(rawRecord) .withParsedRecord(secondParsedRecord) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_INSTANCE_ID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_INSTANCE_ID).withInstanceHrid(HR_ID)); var content2 = new JsonObject(TestUtil.readFileFromPath(PARSED_MARC_RECORD_LINKED_PATH)).encode(); var errorRecordContent = new ErrorRecord().withId(ERROR_RECORD_ID).withContent(content2).withDescription(ERROR_RECORD_DESCRIPTION); @@ -145,7 +148,7 @@ record = new Record() .withParsedRecord(errorParsedRecord) .withRecordType(Record.RecordType.MARC_BIB) .withSnapshotId(snapshot.getJobExecutionId()) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(ERROR_INSTANCE_ID)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(ERROR_INSTANCE_ID).withInstanceHrid(ERROR_HR_ID)); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); SnapshotDaoUtil.save(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshot) diff --git a/mod-source-record-storage-server/src/test/java/org/folio/services/MarcAuthorityUpdateModifyEventHandlerTest.java b/mod-source-record-storage-server/src/test/java/org/folio/services/MarcAuthorityUpdateModifyEventHandlerTest.java index 05b2c97de..863926109 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/services/MarcAuthorityUpdateModifyEventHandlerTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/services/MarcAuthorityUpdateModifyEventHandlerTest.java @@ -36,6 +36,8 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; + +import org.apache.commons.lang3.RandomStringUtils; import org.folio.ActionProfile; import org.folio.DataImportEventPayload; import org.folio.JobProfile; @@ -46,6 +48,8 @@ import org.folio.dao.util.SnapshotDaoUtil; import org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters; import org.folio.rest.jaxrs.model.Data; +import org.folio.rest.jaxrs.model.Snapshot; +import org.folio.rest.jaxrs.model.ExternalIdsHolder; import org.folio.rest.jaxrs.model.MappingDetail; import org.folio.rest.jaxrs.model.MappingMetadataDto; import org.folio.rest.jaxrs.model.MarcField; @@ -55,7 +59,6 @@ import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper; import org.folio.rest.jaxrs.model.RawRecord; import org.folio.rest.jaxrs.model.Record; -import org.folio.rest.jaxrs.model.Snapshot; import org.folio.services.caches.MappingParametersSnapshotCache; import org.folio.services.domainevent.RecordDomainEventPublisher; import org.folio.services.handlers.actions.MarcAuthorityUpdateModifyEventHandler; @@ -180,7 +183,10 @@ record = new Record() .withMatchedId(recordId) .withRecordType(MARC_BIB) .withRawRecord(rawRecord) - .withParsedRecord(parsedRecord); + .withParsedRecord(parsedRecord) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); diff --git a/mod-source-record-storage-server/src/test/java/org/folio/services/MarcBibUpdateModifyEventHandlerTest.java b/mod-source-record-storage-server/src/test/java/org/folio/services/MarcBibUpdateModifyEventHandlerTest.java index 1b8f5e6dd..8f20733e8 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/services/MarcBibUpdateModifyEventHandlerTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/services/MarcBibUpdateModifyEventHandlerTest.java @@ -46,6 +46,8 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; + +import org.apache.commons.lang3.RandomStringUtils; import org.folio.ActionProfile; import org.folio.DataImportEventPayload; import org.folio.InstanceLinkDtoCollection; @@ -272,7 +274,7 @@ record = new Record() .withRecordType(MARC_BIB) .withRawRecord(rawRecord) .withParsedRecord(parsedRecord) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))) .withMetadata(new Metadata()); Record record_2 = new Record() @@ -283,7 +285,7 @@ record = new Record() .withRecordType(MARC_BIB) .withRawRecord(rawRecord) .withParsedRecord(parsedRecord) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))) .withMetadata(new Metadata()); ReactiveClassicGenericQueryExecutor queryExecutorLocalTenant = postgresClientFactory.getQueryExecutor(TENANT_ID); @@ -707,7 +709,7 @@ public void shouldNotUpdateBibFieldWhen500ErrorGetEntityLinkRequest(TestContext .withRecordType(MARC_BIB) .withRawRecord(secondRawRecord) .withParsedRecord(secondParsedRecord) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId)) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))) .withMetadata(new Metadata()); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); @@ -885,7 +887,7 @@ private void verifyBibRecordUpdate(String incomingParsedContent, String expected .withRecordType(MARC_BIB) .withRawRecord(secondRawRecord) .withParsedRecord(secondParsedRecord) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId)) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))) .withMetadata(new Metadata()); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); @@ -896,7 +898,7 @@ private void verifyBibRecordUpdate(String incomingParsedContent, String expected .onSuccess(result -> { Record incomingRecord = new Record().withId(secondRecord.getId()) .withParsedRecord(new ParsedRecord().withContent(incomingParsedContent)) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId)); + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); secondRecord.getParsedRecord().setContent(Json.encode(secondRecord.getParsedRecord().getContent())); HashMap payloadContext = new HashMap<>(); payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(incomingRecord)); diff --git a/mod-source-record-storage-server/src/test/java/org/folio/services/MarcHoldingsUpdateModifyEventHandlerTest.java b/mod-source-record-storage-server/src/test/java/org/folio/services/MarcHoldingsUpdateModifyEventHandlerTest.java index 3dbb9b299..0b0ed0e48 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/services/MarcHoldingsUpdateModifyEventHandlerTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/services/MarcHoldingsUpdateModifyEventHandlerTest.java @@ -47,6 +47,8 @@ import org.folio.dao.util.SnapshotDaoUtil; import org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters; import org.folio.rest.jaxrs.model.Data; +import org.folio.rest.jaxrs.model.ExternalIdsHolder; +import org.folio.rest.jaxrs.model.Snapshot; import org.folio.rest.jaxrs.model.MappingDetail; import org.folio.rest.jaxrs.model.MappingMetadataDto; import org.folio.rest.jaxrs.model.MarcField; @@ -56,7 +58,6 @@ import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper; import org.folio.rest.jaxrs.model.RawRecord; import org.folio.rest.jaxrs.model.Record; -import org.folio.rest.jaxrs.model.Snapshot; import org.folio.services.caches.MappingParametersSnapshotCache; import org.folio.services.domainevent.RecordDomainEventPublisher; import org.folio.services.handlers.actions.MarcHoldingsUpdateModifyEventHandler; @@ -69,6 +70,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils; @RunWith(VertxUnitRunner.class) public class MarcHoldingsUpdateModifyEventHandlerTest extends AbstractLBServiceTest { @@ -181,7 +183,8 @@ record = new Record() .withMatchedId(recordId) .withRecordType(MARC_BIB) .withRawRecord(rawRecord) - .withParsedRecord(parsedRecord); + .withParsedRecord(parsedRecord) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); diff --git a/mod-source-record-storage-server/src/test/java/org/folio/services/QuickMarcKafkaHandlerTest.java b/mod-source-record-storage-server/src/test/java/org/folio/services/QuickMarcKafkaHandlerTest.java index 9a79e9587..78f5e003c 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/services/QuickMarcKafkaHandlerTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/services/QuickMarcKafkaHandlerTest.java @@ -25,6 +25,7 @@ import net.mguenther.kafka.junit.KeyValue; import net.mguenther.kafka.junit.ObserveKeyValues; import net.mguenther.kafka.junit.SendKeyValues; +import org.apache.commons.lang3.RandomStringUtils; import org.folio.TestUtil; import org.folio.dao.RecordDao; import org.folio.dao.RecordDaoImpl; @@ -33,6 +34,7 @@ import org.folio.rest.jaxrs.model.Event; import org.folio.rest.jaxrs.model.ParsedRecord; import org.folio.rest.jaxrs.model.ParsedRecordDto; +import org.folio.rest.jaxrs.model.ExternalIdsHolder; import org.folio.rest.jaxrs.model.RawRecord; import org.folio.rest.jaxrs.model.Record; import org.folio.rest.jaxrs.model.Record.State; @@ -94,7 +96,10 @@ record = new Record() .withMatchedId(recordId) .withRecordType(MARC_BIB) .withRawRecord(rawRecord) - .withParsedRecord(parsedRecord); + .withParsedRecord(parsedRecord) + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); SnapshotDaoUtil.save(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshot) .compose(savedSnapshot -> recordService.saveRecord(record, okapiHeaders)) diff --git a/mod-source-record-storage-server/src/test/java/org/folio/services/RecordServiceTest.java b/mod-source-record-storage-server/src/test/java/org/folio/services/RecordServiceTest.java index 24f1e02ca..60e91ea5a 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/services/RecordServiceTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/services/RecordServiceTest.java @@ -33,6 +33,8 @@ import java.util.stream.Collectors; import javax.ws.rs.BadRequestException; import javax.ws.rs.NotFoundException; + +import org.apache.commons.lang3.RandomStringUtils; import org.folio.TestMocks; import org.folio.TestUtil; import org.folio.dao.RecordDao; @@ -350,6 +352,7 @@ public void shouldSaveMarcBibRecord(TestContext context) { @Test public void shouldSaveMarcBibRecordWithMatchedIdFrom999field(TestContext context) { String marc999 = UUID.randomUUID().toString(); + String hrId = RandomStringUtils.randomAlphanumeric(9); Record original = TestMocks.getMarcBibRecord(); ParsedRecord parsedRecord = new ParsedRecord().withId(marc999) .withContent(new JsonObject().put("leader", "01542ccm a2200361 4500") @@ -357,7 +360,7 @@ public void shouldSaveMarcBibRecordWithMatchedIdFrom999field(TestContext context .put("subfields", new JsonArray().add(new JsonObject().put("s", marc999))) .put("ind1", "f") - .put("ind2", "f")))).encode()); + .put("ind2", "f"))).add(new JsonObject().put("001", hrId))).encode()); Record record = new Record() .withId(UUID.randomUUID().toString()) .withSnapshotId(original.getSnapshotId()) @@ -367,7 +370,7 @@ public void shouldSaveMarcBibRecordWithMatchedIdFrom999field(TestContext context .withRawRecord(original.getRawRecord()) .withParsedRecord(parsedRecord) .withAdditionalInfo(original.getAdditionalInfo()) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(hrId)) .withMetadata(original.getMetadata()); Async async = context.async(); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); @@ -473,6 +476,7 @@ public void shouldFailDuringUpdateRecordGenerationIfRecordWithIdAsIncomingMatche public void shouldFailUpdateRecordGenerationIfDuplicateError(TestContext context) { String matchedId = UUID.randomUUID().toString(); Record original = TestMocks.getMarcBibRecord(); + String hrId = RandomStringUtils.randomAlphanumeric(9); Record record1 = new Record() .withId(matchedId) @@ -483,7 +487,7 @@ public void shouldFailUpdateRecordGenerationIfDuplicateError(TestContext context .withRawRecord(rawRecord) .withParsedRecord(marcRecord) .withAdditionalInfo(original.getAdditionalInfo()) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(hrId)) .withMetadata(original.getMetadata()); Snapshot snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()) @@ -496,7 +500,7 @@ public void shouldFailUpdateRecordGenerationIfDuplicateError(TestContext context .put("subfields", new JsonArray().add(new JsonObject().put("s", matchedId))) .put("ind1", "f") - .put("ind2", "f")))).encode()); + .put("ind2", "f"))).add(new JsonObject().put("001", hrId))).encode()); Record recordToUpdateGeneration = new Record() .withId(UUID.randomUUID().toString()) .withSnapshotId(snapshot.getJobExecutionId()) @@ -507,7 +511,7 @@ public void shouldFailUpdateRecordGenerationIfDuplicateError(TestContext context .withRawRecord(original.getRawRecord()) .withParsedRecord(parsedRecord) .withAdditionalInfo(original.getAdditionalInfo()) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(hrId)) .withMetadata(original.getMetadata()); Async async = context.async(); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); @@ -538,6 +542,7 @@ public void shouldFailUpdateRecordGenerationIfDuplicateError(TestContext context public void shouldUpdateRecordGeneration(TestContext context) { String matchedId = UUID.randomUUID().toString(); Record original = TestMocks.getMarcBibRecord(); + String hrId = RandomStringUtils.randomAlphanumeric(9); Record record1 = new Record() .withId(matchedId) @@ -548,7 +553,7 @@ public void shouldUpdateRecordGeneration(TestContext context) { .withRawRecord(rawRecord) .withParsedRecord(marcRecord) .withAdditionalInfo(original.getAdditionalInfo()) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(hrId)) .withMetadata(original.getMetadata()); Snapshot snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()) @@ -561,7 +566,7 @@ public void shouldUpdateRecordGeneration(TestContext context) { .put("subfields", new JsonArray().add(new JsonObject().put("s", matchedId))) .put("ind1", "f") - .put("ind2", "f")))).encode()); + .put("ind2", "f"))).add(new JsonObject().put("001", hrId))).encode()); Record recordToUpdateGeneration = new Record() .withId(UUID.randomUUID().toString()) .withSnapshotId(snapshot.getJobExecutionId()) @@ -571,7 +576,7 @@ public void shouldUpdateRecordGeneration(TestContext context) { .withRawRecord(original.getRawRecord()) .withParsedRecord(parsedRecord) .withAdditionalInfo(original.getAdditionalInfo()) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(hrId)) .withMetadata(original.getMetadata()); Async async = context.async(); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); @@ -619,6 +624,7 @@ public void shouldUpdateRecordGeneration(TestContext context) { @Test public void shouldUpdateRecordGenerationByMatchId(TestContext context) { var mock = TestMocks.getMarcBibRecord(); + var hrId = RandomStringUtils.randomAlphanumeric(9); var recordToSave = new Record() .withId(UUID.randomUUID().toString()) .withSnapshotId(mock.getSnapshotId()) @@ -628,7 +634,7 @@ public void shouldUpdateRecordGenerationByMatchId(TestContext context) { .withRawRecord(rawRecord) .withParsedRecord(marcRecord) .withAdditionalInfo(mock.getAdditionalInfo()) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(hrId)) .withMetadata(mock.getMetadata()); var async = context.async(); @@ -654,7 +660,7 @@ public void shouldUpdateRecordGenerationByMatchId(TestContext context) { .put("subfields", new JsonArray().add(new JsonObject().put("s", matchedId))) .put("ind1", "f") - .put("ind2", "f")))).encode()); + .put("ind2", "f"))).add(new JsonObject().put("001", hrId))).encode()); var recordToUpdateGeneration = new Record() .withId(UUID.randomUUID().toString()) @@ -665,7 +671,7 @@ public void shouldUpdateRecordGenerationByMatchId(TestContext context) { .withRawRecord(mock.getRawRecord()) .withParsedRecord(parsedRecord) .withAdditionalInfo(mock.getAdditionalInfo()) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(hrId)) .withMetadata(mock.getMetadata()); SnapshotDaoUtil.save(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshot).onComplete(snapshotSaved -> { @@ -704,6 +710,8 @@ public void shouldUpdateRecordGenerationByMatchId(TestContext context) { public void shouldSaveMarcBibRecordWithMatchedIdFromRecordId(TestContext context) { Record original = TestMocks.getMarcBibRecord(); String recordId = UUID.randomUUID().toString(); + String hrId = RandomStringUtils.randomAlphanumeric(9); + Record record = new Record() .withId(recordId) .withSnapshotId(original.getSnapshotId()) @@ -713,7 +721,7 @@ public void shouldSaveMarcBibRecordWithMatchedIdFromRecordId(TestContext context .withRawRecord(rawRecord) .withParsedRecord(marcRecord) .withAdditionalInfo(original.getAdditionalInfo()) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(hrId)) .withMetadata(original.getMetadata()); Async async = context.async(); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); @@ -769,7 +777,8 @@ public void shouldSaveMarcBibRecordWithMatchedIdFromExistingSourceRecord(TestCon Record original = TestMocks.getMarcBibRecord(); String recordId1 = UUID.randomUUID().toString(); String instanceId = UUID.randomUUID().toString(); - ExternalIdsHolder externalIdsHolder = new ExternalIdsHolder().withInstanceId(instanceId); + String hrId = RandomStringUtils.randomAlphanumeric(9); + ExternalIdsHolder externalIdsHolder = new ExternalIdsHolder().withInstanceId(instanceId).withInstanceHrid(hrId); Record record1 = new Record() .withId(recordId1) .withSnapshotId(original.getSnapshotId()) diff --git a/mod-source-record-storage-server/src/test/java/org/folio/verticle/MarcIndexersVersionDeletionVerticleTest.java b/mod-source-record-storage-server/src/test/java/org/folio/verticle/MarcIndexersVersionDeletionVerticleTest.java index 30c7b3293..6e4669621 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/verticle/MarcIndexersVersionDeletionVerticleTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/verticle/MarcIndexersVersionDeletionVerticleTest.java @@ -14,10 +14,13 @@ import io.vertx.ext.unit.junit.VertxUnitRunner; import java.util.Map; import java.util.UUID; + +import org.apache.commons.lang3.RandomStringUtils; import org.folio.TestMocks; import org.folio.dao.RecordDao; import org.folio.dao.RecordDaoImpl; import org.folio.dao.util.SnapshotDaoUtil; +import org.folio.rest.jaxrs.model.ExternalIdsHolder; import org.folio.rest.jaxrs.model.Record; import org.folio.rest.jaxrs.model.Snapshot; import org.folio.services.AbstractLBServiceTest; @@ -70,7 +73,8 @@ public void setUp(TestContext context) { .withGeneration(0) .withRecordType(Record.RecordType.MARC_BIB) .withRawRecord(TestMocks.getRecord(0).getRawRecord().withId(recordId)) - .withParsedRecord(TestMocks.getRecord(0).getParsedRecord().withId(recordId)); + .withParsedRecord(TestMocks.getRecord(0).getParsedRecord().withId(recordId)) + .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); var okapiHeaders = Map.of(OKAPI_TENANT_HEADER, TENANT_ID); SnapshotDaoUtil.save(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshot) diff --git a/mod-source-record-storage-server/src/test/java/org/folio/verticle/consumers/DataImportConsumersVerticleTest.java b/mod-source-record-storage-server/src/test/java/org/folio/verticle/consumers/DataImportConsumersVerticleTest.java index 9f266b3d0..fc08e756b 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/verticle/consumers/DataImportConsumersVerticleTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/verticle/consumers/DataImportConsumersVerticleTest.java @@ -45,6 +45,7 @@ import net.mguenther.kafka.junit.KeyValue; import net.mguenther.kafka.junit.ObserveKeyValues; import net.mguenther.kafka.junit.SendKeyValues; +import org.apache.commons.lang3.RandomStringUtils; import org.folio.ActionProfile; import org.folio.JobProfile; import org.folio.MappingProfile; @@ -142,7 +143,9 @@ record = new Record() .withRecordType(MARC_BIB) .withRawRecord(rawRecord) .withParsedRecord(parsedRecord) - .withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString())); + .withExternalIdsHolder(new ExternalIdsHolder() + .withInstanceId(UUID.randomUUID().toString()) + .withInstanceHrid(RandomStringUtils.randomAlphanumeric(9))); ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID); RecordDaoImpl recordDao = new RecordDaoImpl(postgresClientFactory, recordDomainEventPublisher); diff --git a/mod-source-record-storage-server/src/test/resources/mock/parsedContents/parsedMarcAuthorityWith999field.json b/mod-source-record-storage-server/src/test/resources/mock/parsedContents/parsedMarcAuthorityWith999field.json index 7d2e2ddd1..dfc27d69f 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/parsedContents/parsedMarcAuthorityWith999field.json +++ b/mod-source-record-storage-server/src/test/resources/mock/parsedContents/parsedMarcAuthorityWith999field.json @@ -43,6 +43,28 @@ "ind2": " " } }, + { + "035": { + "ind1": " ", + "ind2": " ", + "subfields": [ + { + "a": "nin00009530412" + } + ] + } + }, + { + "035": { + "ind1": " ", + "ind2": " ", + "subfields": [ + { + "a": "12345" + } + ] + } + }, { "100": { "subfields": [ diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/0f0fe962-d502-4a4f-9e74-7732bec94ee8.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/0f0fe962-d502-4a4f-9e74-7732bec94ee8.json index a44e8b86a..f765b0a57 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/0f0fe962-d502-4a4f-9e74-7732bec94ee8.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/0f0fe962-d502-4a4f-9e74-7732bec94ee8.json @@ -284,7 +284,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "6b4ae089-e1ee-431f-af83-e1133f8e3da0" + "instanceId" : "6b4ae089-e1ee-431f-af83-e1133f8e3da0", + "instanceHrid" : "inst000000000019" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/4c0ff739-3f4d-4670-a693-84dd48e31c53.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/4c0ff739-3f4d-4670-a693-84dd48e31c53.json index 379730894..dc13fc73d 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/4c0ff739-3f4d-4670-a693-84dd48e31c53.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/4c0ff739-3f4d-4670-a693-84dd48e31c53.json @@ -442,7 +442,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "1b74ab75-9f41-4837-8662-a1d99118008d" + "instanceId" : "1b74ab75-9f41-4837-8662-a1d99118008d", + "instanceHrid" : "inst000000000018" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/7293f287-bb51-41f5-805d-00ff18a1f791.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/7293f287-bb51-41f5-805d-00ff18a1f791.json index 8a3dfbbc8..f0e665122 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/7293f287-bb51-41f5-805d-00ff18a1f791.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/7293f287-bb51-41f5-805d-00ff18a1f791.json @@ -292,7 +292,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "c1d3be12-ecec-4fab-9237-baf728575185" + "instanceId" : "c1d3be12-ecec-4fab-9237-baf728575185", + "instanceHrid" : "inst000000000009" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8452daf9-c130-4955-99ce-1c397a218900.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8452daf9-c130-4955-99ce-1c397a218900.json index 68d571c1b..362cf0e8a 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8452daf9-c130-4955-99ce-1c397a218900.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8452daf9-c130-4955-99ce-1c397a218900.json @@ -204,7 +204,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "3c4ae3f3-b460-4a89-a2f9-78ce3145e4fc" + "instanceId" : "3c4ae3f3-b460-4a89-a2f9-78ce3145e4fc", + "instanceHrid" : "inst000000000008" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8f462542-387c-4f06-a01b-50829c7c7b13.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8f462542-387c-4f06-a01b-50829c7c7b13.json index b3494a3c3..c13a9e31a 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8f462542-387c-4f06-a01b-50829c7c7b13.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8f462542-387c-4f06-a01b-50829c7c7b13.json @@ -350,7 +350,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "8be05cf5-fb4f-4752-8094-8e179d08fb99" + "instanceId" : "8be05cf5-fb4f-4752-8094-8e179d08fb99", + "instanceHrid" : "inst000000000004" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8fb19e31-0920-49d7-9438-b573c292b1a6.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8fb19e31-0920-49d7-9438-b573c292b1a6.json index 23c2d2cb1..994bd859f 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8fb19e31-0920-49d7-9438-b573c292b1a6.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/8fb19e31-0920-49d7-9438-b573c292b1a6.json @@ -340,7 +340,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "1640f178-f243-4e4a-bf1c-9e1e62b3171d" + "instanceId" : "1640f178-f243-4e4a-bf1c-9e1e62b3171d", + "instanceHrid" : "inst000000000005" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/be1b25ae-4a9d-4077-93e6-7f8e59efd609.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/be1b25ae-4a9d-4077-93e6-7f8e59efd609.json index 7ab5390bb..475f855b5 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/be1b25ae-4a9d-4077-93e6-7f8e59efd609.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/be1b25ae-4a9d-4077-93e6-7f8e59efd609.json @@ -240,7 +240,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "ce00bca2-9270-4c6b-b096-b83a2e56e8e9" + "instanceId" : "ce00bca2-9270-4c6b-b096-b83a2e56e8e9", + "instanceHrid" : "inst000000000007" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/d3cd3e1e-a18c-4f7c-b053-9aa50343394e.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/d3cd3e1e-a18c-4f7c-b053-9aa50343394e.json index 13977df28..c61a367ef 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/d3cd3e1e-a18c-4f7c-b053-9aa50343394e.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/d3cd3e1e-a18c-4f7c-b053-9aa50343394e.json @@ -302,7 +302,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "e50e9535-091c-451e-82b7-d078b7c4770f" + "instanceId" : "e50e9535-091c-451e-82b7-d078b7c4770f", + "instanceHrid" : "in00000000002" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/e567b8e2-a45b-45f1-a85a-6b6312bdf4d8.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/e567b8e2-a45b-45f1-a85a-6b6312bdf4d8.json index 2036d950c..c392650da 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/e567b8e2-a45b-45f1-a85a-6b6312bdf4d8.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/e567b8e2-a45b-45f1-a85a-6b6312bdf4d8.json @@ -406,7 +406,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "54cc0262-76df-4cac-acca-b10e9bc5c79a" + "instanceId" : "54cc0262-76df-4cac-acca-b10e9bc5c79a", + "instanceHrid" : "inst000000000023" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/ec53a386-9616-428b-92a9-e1f07756ea1f.json b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/ec53a386-9616-428b-92a9-e1f07756ea1f.json index ae618c4a7..4e0479983 100644 --- a/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/ec53a386-9616-428b-92a9-e1f07756ea1f.json +++ b/mod-source-record-storage-server/src/test/resources/mock/sourceRecords/ec53a386-9616-428b-92a9-e1f07756ea1f.json @@ -212,7 +212,8 @@ }, "deleted" : false, "externalIdsHolder" : { - "instanceId" : "5b1eb450-ff9f-412d-a9e7-887f6eaeb5b4" + "instanceId" : "5b1eb450-ff9f-412d-a9e7-887f6eaeb5b4", + "instanceHrid" : "inst000000000010" }, "additionalInfo" : { "suppressDiscovery" : false diff --git a/ramls/source-record-storage-test-records.raml b/ramls/source-record-storage-test-records.raml index ccff54cdd..51349ac33 100644 --- a/ramls/source-record-storage-test-records.raml +++ b/ramls/source-record-storage-test-records.raml @@ -18,7 +18,8 @@ traits: /source-storage/populate-test-marc-records: post: - description: A non-production endpoint to populate MARC records for testing purposes. Available only in case deployment tenant parameter "loadSample" is set to true + description: | + **Deprecated** A non-production endpoint to populate MARC records for testing purposes. Available only in case deployment tenant parameter "loadSample" is set to true is: [validate] body: application/json: