Search in sources :

Example 26 with Snapshot

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

the class RecordsGenerationTest method shouldCalculateRecordsGeneration.

@Test
public void shouldCalculateRecordsGeneration(TestContext testContext) {
    List<Snapshot> snapshots = Arrays.asList(snapshot_1, snapshot_2, snapshot_3, snapshot_4);
    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();
        async = testContext.async();
        Record record = new Record().withId(matchedId).withSnapshotId(snapshots.get(i).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);
        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 + "/" + 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(i));
        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 27 with Snapshot

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

the class SnapshotApiTest method shouldReturnLimitedCollectionOnGet.

@Test
public void shouldReturnLimitedCollectionOnGet(TestContext testContext) {
    Snapshot[] snapshots = new Snapshot[] { snapshot_1, snapshot_2, snapshot_3, snapshot_4 };
    postSnapshots(testContext, snapshots);
    Async async = testContext.async();
    RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SNAPSHOTS_PATH + "?limit=3").then().statusCode(HttpStatus.SC_OK).body("snapshots.size()", is(3)).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)

Example 28 with Snapshot

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

the class SnapshotServiceTest method shouldNotGetSnapshotById.

@Test
public void shouldNotGetSnapshotById(TestContext context) {
    Async async = context.async();
    Snapshot expected = TestMocks.getSnapshot(0);
    snapshotService.getSnapshotById(expected.getJobExecutionId(), TENANT_ID).onComplete(get -> {
        if (get.failed()) {
            context.fail(get.cause());
        }
        context.assertFalse(get.result().isPresent());
        async.complete();
    });
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 29 with Snapshot

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

the class SnapshotServiceTest method shouldDeleteSnapshot.

@Test
public void shouldDeleteSnapshot(TestContext context) {
    Async async = context.async();
    Snapshot snapshot = TestMocks.getSnapshot(0);
    snapshotDao.saveSnapshot(snapshot, TENANT_ID).onComplete(save -> {
        if (save.failed()) {
            context.fail(save.cause());
        }
        snapshotService.deleteSnapshot(snapshot.getJobExecutionId(), TENANT_ID).onComplete(delete -> {
            if (delete.failed()) {
                context.fail(delete.cause());
            }
            context.assertTrue(delete.result());
            snapshotDao.getSnapshotById(snapshot.getJobExecutionId(), TENANT_ID).onComplete(get -> {
                if (get.failed()) {
                    context.fail(get.cause());
                }
                context.assertFalse(get.result().isPresent());
                async.complete();
            });
        });
    });
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 30 with Snapshot

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

the class SnapshotServiceTest method shouldFailToSaveSnapshot.

@Test
public void shouldFailToSaveSnapshot(TestContext context) {
    Async async = context.async();
    Snapshot valid = TestMocks.getSnapshot(0);
    Snapshot invalid = new Snapshot().withJobExecutionId(valid.getJobExecutionId()).withProcessingStartedDate(valid.getProcessingStartedDate()).withMetadata(valid.getMetadata());
    snapshotService.saveSnapshot(invalid, TENANT_ID).onComplete(save -> {
        context.assertTrue(save.failed());
        String expected = "null value in column \"status\" violates not-null constraint";
        context.assertTrue(save.cause().getMessage().contains(expected));
        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