use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class SourceStorageStreamApiTest method shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified.
@Test
public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContext testContext) {
postSnapshots(testContext, snapshot_1, snapshot_2);
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, marc_bib_record_2, record_2_tmp, marc_bib_record_4, record_4_tmp);
final Async async = testContext.async();
InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?recordType=MARC_BIB&orderBy=createdDate,DESC").then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
List<SourceRecord> actual = new ArrayList<>();
flowableInputStreamScanner(response).map(r -> Json.decodeValue(r, SourceRecord.class)).doFinally(() -> {
testContext.assertEquals(4, actual.size());
testContext.assertTrue(Objects.nonNull(actual.get(0).getParsedRecord()));
testContext.assertTrue(Objects.nonNull(actual.get(1).getParsedRecord()));
testContext.assertTrue(Objects.nonNull(actual.get(2).getParsedRecord()));
testContext.assertTrue(Objects.nonNull(actual.get(3).getParsedRecord()));
testContext.assertEquals(false, actual.get(0).getDeleted());
testContext.assertEquals(false, actual.get(1).getDeleted());
testContext.assertEquals(false, actual.get(2).getDeleted());
testContext.assertEquals(false, actual.get(3).getDeleted());
testContext.assertTrue(actual.get(0).getMetadata().getCreatedDate().after(actual.get(1).getMetadata().getCreatedDate()));
testContext.assertTrue(actual.get(1).getMetadata().getCreatedDate().after(actual.get(2).getMetadata().getCreatedDate()));
testContext.assertTrue(actual.get(2).getMetadata().getCreatedDate().after(actual.get(3).getMetadata().getCreatedDate()));
async.complete();
}).collect(() -> actual, (a, r) -> a.add(r)).subscribe();
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class SourceStorageStreamApiTest method shouldReturnEmptyCollectionOnGetByRecordIdAndRecordStateActualIfRecordWasDeleted.
@Test
public void shouldReturnEmptyCollectionOnGetByRecordIdAndRecordStateActualIfRecordWasDeleted(TestContext testContext) {
postSnapshots(testContext, snapshot_2);
Response createParsed = RestAssured.given().spec(spec).body(marc_bib_record_2).when().post(SOURCE_STORAGE_RECORDS_PATH);
assertThat(createParsed.statusCode(), is(HttpStatus.SC_CREATED));
Record parsed = createParsed.body().as(Record.class);
Async async = testContext.async();
RestAssured.given().spec(spec).when().delete(SOURCE_STORAGE_RECORDS_PATH + "/" + parsed.getId()).then().statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();
final Async finalAsync = testContext.async();
InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?recordId=" + parsed.getId() + "&recordState=ACTUAL&limit=1&offset=0").then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
List<SourceRecord> actual = new ArrayList<>();
flowableInputStreamScanner(response).map(r -> Json.decodeValue(r, SourceRecord.class)).doFinally(() -> {
testContext.assertEquals(0, actual.size());
finalAsync.complete();
}).collect(() -> actual, (a, r) -> a.add(r)).subscribe();
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class SourceStorageStreamApiTest method shouldReturnSourceRecordsForPeriod.
@Test
public void shouldReturnSourceRecordsForPeriod(TestContext testContext) {
postSnapshots(testContext, snapshot_1, snapshot_2);
postRecords(testContext, marc_bib_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, marc_bib_record_2, marc_bib_record_3, marc_bib_record_4, marc_bib_record_5);
Date toDate = new Date();
String to = dateTimeFormatter.format(ZonedDateTime.ofInstant(toDate.toInstant(), ZoneId.systemDefault()));
Async async = testContext.async();
RestAssured.given().spec(spec).body(marc_bib_record_6).when().post(SOURCE_STORAGE_RECORDS_PATH).then().statusCode(HttpStatus.SC_CREATED);
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
InputStream result = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?updatedAfter=" + from + "&updatedBefore=" + to).then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
List<SourceRecord> sourceRecordList = new ArrayList<>();
flowableInputStreamScanner(result).map(r -> Json.decodeValue(r, SourceRecord.class)).doFinally(() -> {
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 innerAsync = 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)));
innerAsync.complete();
innerAsync = 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)));
innerAsync.complete();
// NOTE: we do not expect record_1 id does not have a parsed record
innerAsync = 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)));
innerAsync.complete();
InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?updatedBefore=" + from).then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
List<SourceRecord> actual = new ArrayList<>();
flowableInputStreamScanner(response).map(r -> Json.decodeValue(r, SourceRecord.class)).doFinally(() -> {
testContext.assertEquals(0, actual.size());
finalAsync.complete();
}).collect(() -> actual, (a, r) -> a.add(r)).subscribe();
}).collect(() -> sourceRecordList, (a, r) -> a.add(r)).subscribe();
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class SourceRecordApiTest method shouldReturnSourceRecordWithAdditionalInfoOnGetBySpecifiedSnapshotId.
@Test
public void shouldReturnSourceRecordWithAdditionalInfoOnGetBySpecifiedSnapshotId(TestContext testContext) {
postSnapshots(testContext, snapshot_2);
String matchedId = UUID.randomUUID().toString();
Record newRecord = new Record().withId(matchedId).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(matchedId).withAdditionalInfo(new AdditionalInfo().withSuppressDiscovery(true));
Async async = testContext.async();
Response createResponse = RestAssured.given().spec(spec).body(newRecord).when().post(SOURCE_STORAGE_RECORDS_PATH);
assertThat(createResponse.statusCode(), is(HttpStatus.SC_CREATED));
Record createdRecord = createResponse.body().as(Record.class);
async.complete();
async = testContext.async();
Response getResponse = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?snapshotId=" + newRecord.getSnapshotId() + "&suppressFromDiscovery=true");
assertThat(getResponse.statusCode(), is(HttpStatus.SC_OK));
SourceRecordCollection sourceRecordCollection = getResponse.body().as(SourceRecordCollection.class);
assertThat(sourceRecordCollection.getSourceRecords().size(), is(1));
SourceRecord sourceRecord = sourceRecordCollection.getSourceRecords().get(0);
assertThat(sourceRecord.getRecordId(), is(createdRecord.getId()));
// NOTE: raw record is no longer returned with source records for effeciency
// assertThat(sourceRecord.getRawRecord().getContent(), is(rawRecord.getContent()));
assertThat(sourceRecord.getAdditionalInfo().getSuppressDiscovery(), is(createdRecord.getAdditionalInfo().getSuppressDiscovery()));
async.complete();
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class SourceRecordApiTest method shouldReturnSortedEdifactSourceRecordsOnGetWhenSortByOrderIsSpecified.
@Test
public void shouldReturnSortedEdifactSourceRecordsOnGetWhenSortByOrderIsSpecified(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 + "?recordType=EDIFACT&snapshotId=" + snapshot_3.getJobExecutionId() + "&orderBy=order").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(1)).body("totalRecords", is(1)).body("sourceRecords*.recordType", everyItem(is(RecordType.EDIFACT.name()))).body("sourceRecords*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
testContext.assertEquals(0, sourceRecordList.get(0).getOrder());
async.complete();
}
Aggregations