use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class RecordServiceTest method streamMarcSourceRecords.
private void streamMarcSourceRecords(TestContext context, RecordType parsedRecordType, Record.RecordType recordType) {
Async async = context.async();
List<Record> records = TestMocks.getRecords();
RecordCollection recordCollection = new RecordCollection().withRecords(records).withTotalRecords(records.size());
saveRecords(recordCollection.getRecords()).onComplete(batch -> {
if (batch.failed()) {
context.fail(batch.cause());
}
Condition condition = DSL.trueCondition();
List<OrderField<?>> orderFields = new ArrayList<>();
Flowable<SourceRecord> flowable = recordService.streamSourceRecords(condition, parsedRecordType, orderFields, 0, 10, TENANT_ID);
List<SourceRecord> expected = records.stream().filter(r -> r.getRecordType().equals(recordType)).map(RecordDaoUtil::toSourceRecord).sorted(comparing(SourceRecord::getRecordId)).sorted(comparing(SourceRecord::getOrder)).collect(Collectors.toList());
List<SourceRecord> actual = new ArrayList<>();
flowable.doFinally(() -> {
actual.sort(comparing(SourceRecord::getRecordId));
context.assertEquals(expected.size(), actual.size());
compareSourceRecords(context, expected, actual);
async.complete();
}).collect(() -> actual, List::add).subscribe();
});
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class SourceRecordApiTest method shouldReturnSortedMarcBibSourceRecordsOnGetWhenSortByOrderIsSpecified.
@Test
public void shouldReturnSortedMarcBibSourceRecordsOnGetWhenSortByOrderIsSpecified(TestContext testContext) {
postSnapshots(testContext, snapshot_2, snapshot_3);
postRecords(testContext, record_2, record_3, record_5, record_6, record_7);
Async async = testContext.async();
// NOTE: get source records will not return if there is no associated parsed record
List<SourceRecord> sourceRecordList = RestAssured.given().spec(spec).when().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*.recordType", everyItem(is(RecordType.MARC_BIB.name()))).body("sourceRecords*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
testContext.assertEquals(11, sourceRecordList.get(0).getOrder());
testContext.assertEquals(101, sourceRecordList.get(1).getOrder());
async.complete();
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class SourceRecordApiTest method shouldReturnSourceRecordsForPeriod.
@Test
public void shouldReturnSourceRecordsForPeriod(TestContext testContext) {
postSnapshots(testContext, snapshot_1, snapshot_2);
postRecords(testContext, record_1);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
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, record_2, record_3, record_4, record_5);
Date toDate = new Date();
String to = dateTimeFormatter.format(ZonedDateTime.ofInstant(toDate.toInstant(), ZoneId.systemDefault()));
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<SourceRecord> 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*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
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));
testContext.assertTrue(sourceRecordList.get(1).getMetadata().getUpdatedDate().before(toDate));
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedAfter=" + from).then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(3)).body("totalRecords", is(3)).body("sourceRecords*.deleted", everyItem(is(false)));
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedAfter=" + to).then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(1)).body("totalRecords", is(1)).body("sourceRecords*.deleted", everyItem(is(false)));
async.complete();
// NOTE: we do not expect record_1 id does not have a parsed record
async = testContext.async();
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedBefore=" + to).then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(2)).body("totalRecords", is(2)).body("sourceRecords*.deleted", everyItem(is(false)));
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedBefore=" + from).then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(0)).body("totalRecords", is(0));
async.complete();
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class SourceRecordApiTest method shouldReturnSortedMarcSourceRecordsOnGetWhenSortByOrderIsSpecified.
private void shouldReturnSortedMarcSourceRecordsOnGetWhenSortByOrderIsSpecified(TestContext testContext, RecordType recordType, Record record, Snapshot snapshot) {
postSnapshots(testContext, snapshot_2, snapshot_3, snapshot);
postRecords(testContext, record_2, record_3, record_5, record_6, record_7, record);
Async async = testContext.async();
// NOTE: get source records will not return if there is no associated parsed record
List<SourceRecord> sourceRecordList = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?recordType=" + recordType + "&snapshotId=" + snapshot.getJobExecutionId() + "&orderBy=order").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(1)).body("totalRecords", is(1)).body("sourceRecords*.recordType", everyItem(is(recordType.name()))).body("sourceRecords*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
testContext.assertEquals(0, sourceRecordList.get(0).getOrder());
async.complete();
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class SourceRecordApiTest method shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified.
@Test
public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContext testContext) {
postSnapshots(testContext, snapshot_1, snapshot_2, snapshot_3);
String firstMatchedId = UUID.randomUUID().toString();
Record record_4_tmp = new Record().withId(firstMatchedId).withSnapshotId(snapshot_1.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(firstMatchedId).withOrder(1).withState(Record.State.ACTUAL);
String secondMathcedId = UUID.randomUUID().toString();
Record record_2_tmp = new Record().withId(secondMathcedId).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(secondMathcedId).withOrder(11).withState(Record.State.ACTUAL);
postRecords(testContext, record_2, record_2_tmp, record_4, record_4_tmp, record_7);
Async async = testContext.async();
List<SourceRecord> sourceRecordList = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?recordType=MARC_BIB&orderBy=createdDate,DESC").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(4)).body("totalRecords", is(4)).body("sourceRecords*.recordType", everyItem(is(RecordType.MARC_BIB.name()))).body("sourceRecords*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
testContext.assertTrue(sourceRecordList.get(0).getMetadata().getCreatedDate().after(sourceRecordList.get(1).getMetadata().getCreatedDate()));
testContext.assertTrue(sourceRecordList.get(1).getMetadata().getCreatedDate().after(sourceRecordList.get(2).getMetadata().getCreatedDate()));
testContext.assertTrue(sourceRecordList.get(2).getMetadata().getCreatedDate().after(sourceRecordList.get(3).getMetadata().getCreatedDate()));
async.complete();
}
Aggregations