Search in sources :

Example 6 with AdditionalInfo

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

the class SourceStorageBatchApiTest method shouldUpdateParsedRecordsWithJsonContent.

@Test
public void shouldUpdateParsedRecordsWithJsonContent(TestContext testContext) {
    postSnapshots(testContext, snapshot_2);
    Record newRecord = new Record().withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(UUID.randomUUID().toString()).withAdditionalInfo(new AdditionalInfo().withSuppressDiscovery(false));
    Async async = testContext.async();
    Response createResponse = RestAssured.given().spec(spec).body(newRecord).when().post(SOURCE_STORAGE_RECORDS_PATH);
    assertThat(createResponse.statusCode(), is(HttpStatus.SC_CREATED));
    Record createdRecord = createResponse.body().as(Record.class);
    async.complete();
    ParsedRecord parsedRecordJson = new ParsedRecord().withId(createdRecord.getParsedRecord().getId()).withContent(new JsonObject().put("leader", "01542ccm a2200361   4500").put("fields", new JsonArray()));
    RecordCollection recordCollection = new RecordCollection().withRecords(Collections.singletonList(createdRecord.withParsedRecord(parsedRecordJson))).withTotalRecords(1);
    async = testContext.async();
    ParsedRecordsBatchResponse updatedParsedRecordCollection = RestAssured.given().spec(spec).body(recordCollection).when().put(SOURCE_STORAGE_BATCH_PARSED_RECORDS_PATH).then().statusCode(HttpStatus.SC_OK).extract().response().body().as(ParsedRecordsBatchResponse.class);
    ParsedRecord updatedParsedRecord = updatedParsedRecordCollection.getParsedRecords().get(0);
    assertThat(updatedParsedRecord.getId(), notNullValue());
    assertThat(JsonObject.mapFrom(updatedParsedRecord).encode(), containsString("\"leader\":\"01542ccm a2200361   4500\""));
    async.complete();
}
Also used : RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) ParsedRecordsBatchResponse(org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse) Response(io.restassured.response.Response) JsonArray(io.vertx.core.json.JsonArray) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) Async(io.vertx.ext.unit.Async) ParsedRecordsBatchResponse(org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) JsonObject(io.vertx.core.json.JsonObject) 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) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Example 7 with AdditionalInfo

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

the class SourceStorageBatchApiTest method shouldUpdateParsedRecords.

@Test
public void shouldUpdateParsedRecords(TestContext testContext) {
    postSnapshots(testContext, snapshot_2);
    String matchedId = UUID.randomUUID().toString();
    Record newRecord = new Record().withId(matchedId).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(matchedId).withState(Record.State.ACTUAL).withAdditionalInfo(new AdditionalInfo().withSuppressDiscovery(false));
    Async async = testContext.async();
    Response createResponse = RestAssured.given().spec(spec).body(newRecord).when().post(SOURCE_STORAGE_RECORDS_PATH);
    assertThat(createResponse.statusCode(), is(HttpStatus.SC_CREATED));
    Record createdRecord = createResponse.body().as(Record.class);
    async.complete();
    RecordCollection recordCollection = new RecordCollection().withRecords(Collections.singletonList(createdRecord)).withTotalRecords(1);
    async = testContext.async();
    ParsedRecordsBatchResponse updatedParsedRecordCollection = RestAssured.given().spec(spec).body(recordCollection).when().put(SOURCE_STORAGE_BATCH_PARSED_RECORDS_PATH).then().statusCode(HttpStatus.SC_OK).extract().response().body().as(ParsedRecordsBatchResponse.class);
    ParsedRecord updatedParsedRecord = updatedParsedRecordCollection.getParsedRecords().get(0);
    assertThat(updatedParsedRecord.getId(), notNullValue());
    assertThat(JsonObject.mapFrom(updatedParsedRecord).encode(), containsString("\"leader\":\"01542ccm a2200361   4500\""));
    async.complete();
    RestAssured.given().spec(spec).body(recordCollection).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + createdRecord.getId()).then().statusCode(HttpStatus.SC_OK).body("metadata", notNullValue()).body("metadata.createdDate", notNullValue(String.class)).body("metadata.createdByUserId", notNullValue(String.class)).body("metadata.updatedDate", notNullValue(String.class)).body("metadata.updatedByUserId", notNullValue(String.class));
}
Also used : RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) ParsedRecordsBatchResponse(org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse) Response(io.restassured.response.Response) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) Async(io.vertx.ext.unit.Async) ParsedRecordsBatchResponse(org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse) 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) Matchers.containsString(org.hamcrest.Matchers.containsString) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Aggregations

AdditionalInfo (org.folio.rest.jaxrs.model.AdditionalInfo)7 ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)7 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)7 RawRecord (org.folio.rest.jaxrs.model.RawRecord)7 Record (org.folio.rest.jaxrs.model.Record)7 Response (io.restassured.response.Response)6 Async (io.vertx.ext.unit.Async)6 SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)4 Test (org.junit.Test)4 JsonObject (io.vertx.core.json.JsonObject)3 ExtractableResponse (io.restassured.response.ExtractableResponse)2 ParsedRecordsBatchResponse (org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse)2 RecordCollection (org.folio.rest.jaxrs.model.RecordCollection)2 RecordsBatchResponse (org.folio.rest.jaxrs.model.RecordsBatchResponse)2 Lists (com.google.common.collect.Lists)1 ReactiveClassicGenericQueryExecutor (io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor)1 QueryResult (io.github.jklingsporn.vertx.jooq.shared.internal.QueryResult)1 Flowable (io.reactivex.Flowable)1 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1