Search in sources :

Example 26 with SourceRecord

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();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Scanner(java.util.Scanner) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Flowable(io.reactivex.Flowable) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) BackpressureStrategy(io.reactivex.BackpressureStrategy) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) ZoneId(java.time.ZoneId) Objects(java.util.Objects) ExtractableResponse(io.restassured.response.ExtractableResponse) List(java.util.List) Response(io.restassured.response.Response) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) DateTimeFormatter(java.time.format.DateTimeFormatter) PostgresClientFactory(org.folio.dao.PostgresClientFactory) MarcRecordSearchRequest(org.folio.rest.jaxrs.model.MarcRecordSearchRequest) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Async(io.vertx.ext.unit.Async) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test)

Example 27 with SourceRecord

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();
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Response(io.restassured.response.Response) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Scanner(java.util.Scanner) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Flowable(io.reactivex.Flowable) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) BackpressureStrategy(io.reactivex.BackpressureStrategy) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) ZoneId(java.time.ZoneId) Objects(java.util.Objects) ExtractableResponse(io.restassured.response.ExtractableResponse) List(java.util.List) Response(io.restassured.response.Response) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) DateTimeFormatter(java.time.format.DateTimeFormatter) PostgresClientFactory(org.folio.dao.PostgresClientFactory) MarcRecordSearchRequest(org.folio.rest.jaxrs.model.MarcRecordSearchRequest) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Async(io.vertx.ext.unit.Async) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test)

Example 28 with SourceRecord

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();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Scanner(java.util.Scanner) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Flowable(io.reactivex.Flowable) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) BackpressureStrategy(io.reactivex.BackpressureStrategy) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) ZoneId(java.time.ZoneId) Objects(java.util.Objects) ExtractableResponse(io.restassured.response.ExtractableResponse) List(java.util.List) Response(io.restassured.response.Response) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) DateTimeFormatter(java.time.format.DateTimeFormatter) PostgresClientFactory(org.folio.dao.PostgresClientFactory) MarcRecordSearchRequest(org.folio.rest.jaxrs.model.MarcRecordSearchRequest) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Async(io.vertx.ext.unit.Async) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DateTimeFormatter(java.time.format.DateTimeFormatter) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Date(java.util.Date) Test(org.junit.Test)

Example 29 with SourceRecord

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();
}
Also used : Response(io.restassured.response.Response) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test)

Example 30 with SourceRecord

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();
}
Also used : SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test)

Aggregations

SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)30 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)22 Async (io.vertx.ext.unit.Async)21 RawRecord (org.folio.rest.jaxrs.model.RawRecord)20 Record (org.folio.rest.jaxrs.model.Record)20 Test (org.junit.Test)20 ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)19 ArrayList (java.util.ArrayList)17 AdditionalInfo (org.folio.rest.jaxrs.model.AdditionalInfo)17 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)17 List (java.util.List)16 Objects (java.util.Objects)16 Flowable (io.reactivex.Flowable)14 UUID (java.util.UUID)14 ParsedRecordDaoUtil (org.folio.dao.util.ParsedRecordDaoUtil)14 SnapshotDaoUtil (org.folio.dao.util.SnapshotDaoUtil)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 TestContext (io.vertx.ext.unit.TestContext)12 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)12 SourceRecordCollection (org.folio.rest.jaxrs.model.SourceRecordCollection)10