use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.
the class SourceStorageBatchApiTest method shouldPostSourceStorageBatchRecordsCalculateRecordsGeneration.
@Test
public void shouldPostSourceStorageBatchRecordsCalculateRecordsGeneration(TestContext testContext) {
Snapshot snapshot1 = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withStatus(Snapshot.Status.PARSING_IN_PROGRESS);
Snapshot snapshot2 = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withStatus(Snapshot.Status.PARSING_IN_PROGRESS);
Snapshot snapshot3 = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withStatus(Snapshot.Status.PARSING_IN_PROGRESS);
Snapshot snapshot4 = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withStatus(Snapshot.Status.PARSING_IN_PROGRESS);
List<Snapshot> snapshots = Arrays.asList(snapshot1, snapshot2, snapshot3, snapshot4);
List<Record> records = TestMocks.getRecords().stream().filter(record -> record.getRecordType().equals(RecordType.MARC_BIB)).map(record -> {
RawRecord rawRecord = record.getRawRecord();
if (Objects.nonNull(rawRecord)) {
rawRecord.setId(null);
}
ParsedRecord parsedRecord = record.getParsedRecord();
if (Objects.nonNull(parsedRecord)) {
parsedRecord.setId(null);
}
ErrorRecord errorRecord = record.getErrorRecord();
if (Objects.nonNull(errorRecord)) {
errorRecord.setId(null);
}
return record.withId(null).withRawRecord(rawRecord).withParsedRecord(parsedRecord).withErrorRecord(errorRecord);
}).collect(Collectors.toList());
List<String> previousRecordIds = new ArrayList<>();
for (int i = 0; i < snapshots.size(); i++) {
final Snapshot snapshot = snapshots.get(i);
Async async = testContext.async();
RestAssured.given().spec(spec).body(snapshot.withStatus(Snapshot.Status.PARSING_IN_PROGRESS)).when().post(SOURCE_STORAGE_SNAPSHOTS_PATH).then().statusCode(HttpStatus.SC_CREATED);
async.complete();
records = records.stream().map(record -> record.withSnapshotId(snapshot.getJobExecutionId())).collect(Collectors.toList());
RecordCollection recordCollection = new RecordCollection().withRecords(records).withTotalRecords(records.size());
RecordsBatchResponse response = RestAssured.given().spec(spec).body(recordCollection).when().post(SOURCE_STORAGE_BATCH_RECORDS_PATH).body().as(RecordsBatchResponse.class);
testContext.assertEquals(records.size(), response.getRecords().size());
testContext.assertEquals(0, response.getErrorMessages().size());
testContext.assertEquals(records.size(), response.getTotalRecords());
async = testContext.async();
RestAssured.given().spec(spec).body(snapshot.withStatus(Snapshot.Status.COMMITTED)).when().put(SOURCE_STORAGE_SNAPSHOTS_PATH + "/" + snapshot.getJobExecutionId()).then().statusCode(HttpStatus.SC_OK);
async.complete();
if (!previousRecordIds.isEmpty()) {
// assert old records state and generation
for (String recordId : previousRecordIds) {
async = testContext.async();
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + recordId).then().statusCode(HttpStatus.SC_OK).body("id", is(recordId)).body("state", is(Record.State.OLD.name())).body("generation", is(i - 1));
async.complete();
}
previousRecordIds.clear();
}
// assert new records state and generation
for (Record record : response.getRecords()) {
async = testContext.async();
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + record.getId()).then().statusCode(HttpStatus.SC_OK).body("id", is(record.getId())).body("matchedId", is(record.getMatchedId())).body("state", is(Record.State.ACTUAL.name())).body("generation", is(i));
previousRecordIds.add(record.getId());
async.complete();
}
}
}
use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.
the class SourceStorageBatchApiTest method shouldFailWhenPostSourceStorageBatchRecordsWithMultipleSnapshots.
@Test
public void shouldFailWhenPostSourceStorageBatchRecordsWithMultipleSnapshots(TestContext testContext) {
Async async = testContext.async();
List<Record> expected = TestMocks.getRecords().stream().filter(record -> record.getRecordType().equals(RecordType.MARC_BIB)).collect(Collectors.toList());
RecordCollection recordCollection = new RecordCollection().withRecords(expected).withTotalRecords(expected.size());
RestAssured.given().spec(spec).body(recordCollection).when().post(SOURCE_STORAGE_BATCH_RECORDS_PATH).then().statusCode(HttpStatus.SC_BAD_REQUEST).body(is("Batch record collection only supports single snapshot"));
async.complete();
}
use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.
the class RecordsGenerationTest method shouldNotUpdateRecordsGenerationIfSnapshotsCommittedAfter.
@Test
public void shouldNotUpdateRecordsGenerationIfSnapshotsCommittedAfter(TestContext testContext) {
List<Snapshot> snapshots = Arrays.asList(snapshot_1, snapshot_2);
List<String> ids = new ArrayList<>();
// create snapshots and records
for (int i = 0; i < snapshots.size(); i++) {
Async async = testContext.async();
RestAssured.given().spec(spec).body(snapshots.get(i).withStatus(Snapshot.Status.PARSING_IN_PROGRESS)).when().post(SOURCE_STORAGE_SNAPSHOTS_PATH).then().statusCode(HttpStatus.SC_CREATED);
async.complete();
Record record = new Record().withId(matchedId).withSnapshotId(snapshots.get(i).getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(matchedId);
ids.add(record.getId());
async = testContext.async();
Record created = RestAssured.given().spec(spec).body(record).when().post(SOURCE_STORAGE_RECORDS_PATH).body().as(Record.class);
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + created.getId()).then().statusCode(HttpStatus.SC_OK).body("id", is(created.getId())).body("rawRecord.content", is(rawRecord.getContent())).body("matchedId", is(matchedId)).body("generation", is(0));
async.complete();
}
// update snapshots to committed after
for (int i = 0; i < snapshots.size(); i++) {
Async async = testContext.async();
RestAssured.given().spec(spec).body(snapshots.get(i).withStatus(Snapshot.Status.COMMITTED)).when().put(SOURCE_STORAGE_SNAPSHOTS_PATH + "/" + snapshots.get(i).getJobExecutionId()).then().statusCode(HttpStatus.SC_OK);
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + ids.get(i)).then().statusCode(HttpStatus.SC_OK).body("id", is(ids.get(i))).body("rawRecord.content", is(rawRecord.getContent())).body("matchedId", is(matchedId)).body("generation", is(0));
async.complete();
}
}
use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.
the class RecordsGenerationTest method shouldNotUpdateRecordsGenerationIfSnapshotsNotCommitted.
@Test
public void shouldNotUpdateRecordsGenerationIfSnapshotsNotCommitted(TestContext testContext) {
List<Snapshot> snapshots = Arrays.asList(snapshot_1, snapshot_2, snapshot_3, snapshot_4);
for (Snapshot snapshot : snapshots) {
Async async = testContext.async();
RestAssured.given().spec(spec).body(snapshot.withStatus(Snapshot.Status.PARSING_IN_PROGRESS)).when().post(SOURCE_STORAGE_SNAPSHOTS_PATH).then().statusCode(HttpStatus.SC_CREATED);
async.complete();
async = testContext.async();
Record record = new Record().withId(matchedId).withSnapshotId(snapshot.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(matchedId);
Record created = RestAssured.given().spec(spec).body(record).when().post(SOURCE_STORAGE_RECORDS_PATH).body().as(Record.class);
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + created.getId()).then().statusCode(HttpStatus.SC_OK).body("id", is(created.getId())).body("rawRecord.content", is(rawRecord.getContent())).body("matchedId", is(matchedId)).body("generation", is(0));
async.complete();
}
}
use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.
the class SnapshotApiTest method shouldReturnAllSnapshotsOnGetWhenNoQueryIsSpecified.
@Test
public void shouldReturnAllSnapshotsOnGetWhenNoQueryIsSpecified(TestContext testContext) {
Snapshot[] snapshots = new Snapshot[] { snapshot_1, snapshot_2, snapshot_3 };
postSnapshots(testContext, snapshots);
Async async = testContext.async();
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SNAPSHOTS_PATH).then().statusCode(HttpStatus.SC_OK).body("totalRecords", is(snapshots.length));
async.complete();
}
Aggregations