Search in sources :

Example 11 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class MarcUtilTest method readSourceRecord.

@Before
public void readSourceRecord() throws JsonParseException, JsonMappingException, IOException {
    File file = new File(SOURCE_RECORD_PATH);
    sourceRecord = new ObjectMapper().readValue(file, SourceRecord.class);
}
Also used : File(java.io.File) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 12 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class SourceStorageStreamApiTest method shouldReturnEmptyCollectionOnGetByRecordIdIfParsedRecordIsNull.

@Test
public void shouldReturnEmptyCollectionOnGetByRecordIdIfParsedRecordIsNull(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2);
    postRecords(testContext, marc_bib_record_1, marc_bib_record_3);
    Record createdRecord = RestAssured.given().spec(spec).body(marc_bib_record_3).when().post(SOURCE_STORAGE_RECORDS_PATH).body().as(Record.class);
    final Async async = testContext.async();
    InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?recordId=" + createdRecord.getId() + "&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());
        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 13 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class SourceStorageStreamApiTest method shouldReturnSpecificSourceRecordOnGetByRecordLeaderRecordStatus.

@Test
public void shouldReturnSpecificSourceRecordOnGetByRecordLeaderRecordStatus(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2);
    postRecords(testContext, marc_bib_record_1, marc_bib_record_3);
    Record createdRecord = RestAssured.given().spec(spec).body(marc_bib_record_2).when().post(SOURCE_STORAGE_RECORDS_PATH).body().as(Record.class);
    String leaderStatus = ParsedRecordDaoUtil.getLeaderStatus(createdRecord.getParsedRecord());
    final Async async = testContext.async();
    InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?leaderRecordStatus=" + leaderStatus + "&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(1, actual.size());
        testContext.assertTrue(Objects.nonNull(actual.get(0).getParsedRecord()));
        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 14 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class TestMocks method readSourceRecords.

private static List<SourceRecord> readSourceRecords() {
    File sourceRecordsDirectory = new File(SOURCE_RECORDS_FOLDER_PATH);
    String[] extensions = new String[] { "json" };
    return FileUtils.listFiles(sourceRecordsDirectory, extensions, false).stream().map(TestMocks::readSourceRecord).filter(sr -> sr.isPresent()).map(sr -> sr.get()).collect(Collectors.toList());
}
Also used : Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RawRecord(org.folio.rest.jaxrs.model.RawRecord) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) File(java.io.File) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) List(java.util.List) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) Optional(java.util.Optional) JsonObject(io.vertx.core.json.JsonObject) Metadata(org.folio.rest.jaxrs.model.Metadata) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) File(java.io.File)

Example 15 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class EdifactUtilTest method readSourceRecord.

@Before
public void readSourceRecord() throws JsonParseException, JsonMappingException, IOException {
    File file = new File(SOURCE_RECORD_PATH);
    sourceRecord = new ObjectMapper().readValue(file, SourceRecord.class);
}
Also used : File(java.io.File) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

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