Search in sources :

Example 11 with ErrorRecord

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

the class RecordApiTest method shouldDeleteExistingMarcRecordOnDelete.

@Test
public void shouldDeleteExistingMarcRecordOnDelete(TestContext testContext) {
    postSnapshots(testContext, snapshot_2);
    Async async = testContext.async();
    Response createParsed = RestAssured.given().spec(spec).body(record_2).when().post(SOURCE_STORAGE_RECORDS_PATH);
    assertThat(createParsed.statusCode(), is(HttpStatus.SC_CREATED));
    Record parsed = createParsed.body().as(Record.class);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().delete(SOURCE_STORAGE_RECORDS_PATH + "/" + parsed.getId()).then().statusCode(HttpStatus.SC_NO_CONTENT);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + parsed.getId()).then().statusCode(HttpStatus.SC_OK).body("deleted", is(true));
    async.complete();
    async = testContext.async();
    Response createErrorRecord = RestAssured.given().spec(spec).body(record_3).when().post(SOURCE_STORAGE_RECORDS_PATH);
    assertThat(createErrorRecord.statusCode(), is(HttpStatus.SC_CREATED));
    Record errorRecord = createErrorRecord.body().as(Record.class);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().delete(SOURCE_STORAGE_RECORDS_PATH + "/" + errorRecord.getId()).then().statusCode(HttpStatus.SC_NO_CONTENT);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + errorRecord.getId()).then().statusCode(HttpStatus.SC_OK).body("deleted", is(true));
    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)

Example 12 with ErrorRecord

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

the class TestMocks method readRecord.

private static Optional<Record> readRecord(SourceRecord sourceRecord) {
    File file = new File(format(RECORD_PATH_TEMPLATE, sourceRecord.getRecordId()));
    if (file.exists()) {
        try {
            Record record = new ObjectMapper().readValue(file, Record.class).withRawRecord(sourceRecord.getRawRecord()).withParsedRecord(sourceRecord.getParsedRecord()).withExternalIdsHolder(sourceRecord.getExternalIdsHolder()).withAdditionalInfo(sourceRecord.getAdditionalInfo());
            if (Objects.nonNull(sourceRecord.getMetadata())) {
                record.withMetadata(sourceRecord.getMetadata());
            }
            Optional<ErrorRecord> errorRecord = errorRecords.stream().filter(er -> er.getId().equals(record.getId())).findAny();
            if (errorRecord.isPresent()) {
                record.withErrorRecord(errorRecord.get());
            }
            return Optional.of(record);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return Optional.empty();
}
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) Record(org.folio.rest.jaxrs.model.Record) RawRecord(org.folio.rest.jaxrs.model.RawRecord) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord)

Example 13 with ErrorRecord

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

the class RecordApiTest method shouldUpdateErrorRecordOnPut.

@Test
public void shouldUpdateErrorRecordOnPut(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();
    createdRecord.setErrorRecord(errorRecord);
    RestAssured.given().spec(spec).body(createdRecord).when().put(SOURCE_STORAGE_RECORDS_PATH + "/" + createdRecord.getId()).then().statusCode(HttpStatus.SC_OK).body("id", is(createdRecord.getId())).body("rawRecord.content", is(createdRecord.getRawRecord().getContent())).body("errorRecord.content", is(createdRecord.getErrorRecord().getContent())).body("additionalInfo.suppressDiscovery", 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

ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)13 Record (org.folio.rest.jaxrs.model.Record)7 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)6 RawRecord (org.folio.rest.jaxrs.model.RawRecord)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JsonObject (io.vertx.core.json.JsonObject)4 ArrayList (java.util.ArrayList)4 Response (io.restassured.response.Response)3 Async (io.vertx.ext.unit.Async)3 IOException (java.io.IOException)3 String.format (java.lang.String.format)3 List (java.util.List)3 Objects (java.util.Objects)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 NotFoundException (javax.ws.rs.NotFoundException)3 AdditionalInfo (org.folio.rest.jaxrs.model.AdditionalInfo)3 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)3 RecordCollection (org.folio.rest.jaxrs.model.RecordCollection)3 SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)3