Search in sources :

Example 96 with Record

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

the class SourceRecordApiTest method shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified.

@Test
public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2, snapshot_3);
    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, record_2, record_2_tmp, record_4, record_4_tmp, record_7);
    Async async = testContext.async();
    List<SourceRecord> sourceRecordList = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?recordType=MARC_BIB&orderBy=createdDate,DESC").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(4)).body("totalRecords", is(4)).body("sourceRecords*.recordType", everyItem(is(RecordType.MARC_BIB.name()))).body("sourceRecords*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
    testContext.assertTrue(sourceRecordList.get(0).getMetadata().getCreatedDate().after(sourceRecordList.get(1).getMetadata().getCreatedDate()));
    testContext.assertTrue(sourceRecordList.get(1).getMetadata().getCreatedDate().after(sourceRecordList.get(2).getMetadata().getCreatedDate()));
    testContext.assertTrue(sourceRecordList.get(2).getMetadata().getCreatedDate().after(sourceRecordList.get(3).getMetadata().getCreatedDate()));
    async.complete();
}
Also used : 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 97 with Record

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

the class AbstractRestVerticleTest method postRecords.

protected void postRecords(TestContext testContext, Record... records) {
    Async async = testContext.async();
    for (Record record : records) {
        RestAssured.given().spec(spec).body(record).when().post(SOURCE_STORAGE_RECORDS_PATH).then().statusCode(HttpStatus.SC_CREATED);
    }
    async.complete();
}
Also used : Async(io.vertx.ext.unit.Async) Record(org.folio.rest.jaxrs.model.Record)

Example 98 with Record

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

the class RecordApiTest method shouldReturnMarcBibRecordsOnGetBySpecifiedSnapshotId.

@Test
public void shouldReturnMarcBibRecordsOnGetBySpecifiedSnapshotId(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2, snapshot_3);
    Record recordWithOldStatus = new Record().withId(FOURTH_UUID).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawMarcRecord).withParsedRecord(parsedMarcRecord).withMatchedId(FOURTH_UUID).withOrder(1).withState(Record.State.OLD);
    postRecords(testContext, record_1, record_2, record_3, record_6, recordWithOldStatus);
    Async async = testContext.async();
    RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "?recordType=MARC_BIB&state=ACTUAL&snapshotId=" + record_2.getSnapshotId()).then().statusCode(HttpStatus.SC_OK).body("totalRecords", is(2)).body("records*.recordType", everyItem(is(RecordType.MARC_BIB.name()))).body("records*.snapshotId", everyItem(is(record_2.getSnapshotId()))).body("records*.additionalInfo.suppressDiscovery", everyItem(is(false)));
    async.complete();
}
Also used : Async(io.vertx.ext.unit.Async) 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 99 with Record

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

the class RecordApiTest method shouldReturnSortedRecordsOnGetWhenSortByOrderIsSpecified.

@Test
public void shouldReturnSortedRecordsOnGetWhenSortByOrderIsSpecified(TestContext testContext) {
    postSnapshots(testContext, snapshot_2);
    postRecords(testContext, record_2, record_3, record_5);
    Async async = testContext.async();
    List<Record> records = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "?snapshotId=" + snapshot_2.getJobExecutionId() + "&orderBy=order").then().statusCode(HttpStatus.SC_OK).body("records.size()", is(3)).body("totalRecords", is(3)).body("records*.deleted", everyItem(is(false))).extract().response().body().as(RecordCollection.class).getRecords();
    Assert.assertEquals(11, records.get(0).getOrder().intValue());
    Assert.assertEquals(101, records.get(1).getOrder().intValue());
    Assert.assertNull(records.get(2).getOrder());
    async.complete();
}
Also used : 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 100 with Record

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

the class RecordApiTest method shouldUpdateExistingMarcRecordOnPut.

@Test
public void shouldUpdateExistingMarcRecordOnPut(TestContext testContext) {
    postSnapshots(testContext, snapshot_1);
    Async async = testContext.async();
    Response createResponse = RestAssured.given().spec(spec).body(record_1).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 putResponse = RestAssured.given().spec(spec).body(createdRecord.withParsedRecord(parsedMarcRecord)).when().put(SOURCE_STORAGE_RECORDS_PATH + "/" + createdRecord.getId());
    assertThat(putResponse.statusCode(), is(HttpStatus.SC_OK));
    Record updatedRecord = putResponse.body().as(Record.class);
    assertThat(updatedRecord.getId(), is(createdRecord.getId()));
    assertThat(updatedRecord.getRawRecord().getContent(), is(rawMarcRecord.getContent()));
    assertThat(updatedRecord.getAdditionalInfo().getSuppressDiscovery(), is(false));
    async.complete();
}
Also used : Response(io.restassured.response.Response) Async(io.vertx.ext.unit.Async) 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)

Aggregations

Record (org.folio.rest.jaxrs.model.Record)320 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)266 Test (org.junit.Test)253 RawRecord (org.folio.rest.jaxrs.model.RawRecord)164 Async (io.vertx.ext.unit.Async)154 JsonObject (io.vertx.core.json.JsonObject)149 HashMap (java.util.HashMap)125 DataImportEventPayload (org.folio.DataImportEventPayload)116 ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)116 SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)76 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)74 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)69 UUID (java.util.UUID)66 ArrayList (java.util.ArrayList)64 List (java.util.List)62 Before (org.junit.Before)60 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)58 SnapshotDaoUtil (org.folio.dao.util.SnapshotDaoUtil)55 TestContext (io.vertx.ext.unit.TestContext)52 RunWith (org.junit.runner.RunWith)51