Search in sources :

Example 11 with Snapshot

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();
        }
    }
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) SNAPSHOT_NOT_FOUND_TEMPLATE(org.folio.dao.util.SnapshotDaoUtil.SNAPSHOT_NOT_FOUND_TEMPLATE) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) SNAPSHOT_NOT_STARTED_MESSAGE_TEMPLATE(org.folio.dao.util.SnapshotDaoUtil.SNAPSHOT_NOT_STARTED_MESSAGE_TEMPLATE) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) ParsedRecordsBatchResponse(org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse) TestMocks(org.folio.TestMocks) Before(org.junit.Before) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) Response(io.restassured.response.Response) PostgresClientFactory(org.folio.dao.PostgresClientFactory) Matcher(org.hamcrest.Matcher) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) Matchers.containsString(org.hamcrest.Matchers.containsString) Collections(java.util.Collections) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) ParsedRecordsBatchResponse(org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) Test(org.junit.Test)

Example 12 with Snapshot

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();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) SNAPSHOT_NOT_FOUND_TEMPLATE(org.folio.dao.util.SnapshotDaoUtil.SNAPSHOT_NOT_FOUND_TEMPLATE) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) SNAPSHOT_NOT_STARTED_MESSAGE_TEMPLATE(org.folio.dao.util.SnapshotDaoUtil.SNAPSHOT_NOT_STARTED_MESSAGE_TEMPLATE) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) ParsedRecordsBatchResponse(org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse) TestMocks(org.folio.TestMocks) Before(org.junit.Before) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) Response(io.restassured.response.Response) PostgresClientFactory(org.folio.dao.PostgresClientFactory) Matcher(org.hamcrest.Matcher) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) Matchers.containsString(org.hamcrest.Matchers.containsString) Collections(java.util.Collections) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Example 13 with Snapshot

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();
    }
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) ArrayList(java.util.ArrayList) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 14 with Snapshot

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

Example 15 with Snapshot

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

Aggregations

Snapshot (org.folio.rest.jaxrs.model.Snapshot)31 Async (io.vertx.ext.unit.Async)25 Test (org.junit.Test)21 Record (org.folio.rest.jaxrs.model.Record)15 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)14 RawRecord (org.folio.rest.jaxrs.model.RawRecord)14 Before (org.junit.Before)13 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 JsonObject (io.vertx.core.json.JsonObject)9 UUID (java.util.UUID)9 TestContext (io.vertx.ext.unit.TestContext)8 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)8 RecordDaoImpl (org.folio.dao.RecordDaoImpl)8 SnapshotDaoUtil (org.folio.dao.util.SnapshotDaoUtil)8 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)8 RunWith (org.junit.runner.RunWith)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 IOException (java.io.IOException)7 Collections (java.util.Collections)7