Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanChernetskyi committed Feb 5, 2024
1 parent f20ff53 commit 5f8943d
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ public Future<Void> deleteRecordById(String id, IdType idType, String tenantId)
.map(recordOptional -> recordOptional.orElseThrow(() -> new NotFoundException(format(NOT_FOUND_MESSAGE, Record.class.getSimpleName(), id))))
.map(record -> {
record.withState(Record.State.DELETED);
record.setDeleted(true);
record.setAdditionalInfo(record.getAdditionalInfo().withSuppressDiscovery(true));
ParsedRecordDaoUtil.updateLeaderStatus(record.getParsedRecord(), DELETED_LEADER_RECORD_STATUS);
return record;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.apache.http.HttpStatus;
import org.folio.dao.util.ParsedRecordDaoUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -760,7 +761,7 @@ public void shouldReturnNotFoundOnDeleteWhenRecordDoesNotExist() {
}

@Test
public void shouldDeleteExistingMarcRecordOnDelete(TestContext testContext) {
public void shouldDeleteExistingMarcRecordOnDeleteByRecordId(TestContext testContext) {
postSnapshots(testContext, snapshot_2);

Async async = testContext.async();
Expand All @@ -783,13 +784,19 @@ public void shouldDeleteExistingMarcRecordOnDelete(TestContext testContext) {
async.complete();

async = testContext.async();
RestAssured.given()
Response deletedResponse = RestAssured.given()
.spec(spec)
.when()
.get(SOURCE_STORAGE_RECORDS_PATH + "/" + parsed.getId())
.then()
.statusCode(HttpStatus.SC_OK)
.body("deleted", is(true));
.get(SOURCE_STORAGE_RECORDS_PATH + "/" + parsed.getId());
Assert.assertEquals(deletedResponse.getStatusCode(), HttpStatus.SC_OK);
Record deletedRecord = deletedResponse.body().as(Record.class);

Assert.assertEquals(deletedRecord.getDeleted(), true);
Assert.assertEquals(deletedRecord.getState(), Record.State.DELETED);
Assert.assertEquals(deletedRecord.getLeaderRecordStatus(), "d");
Assert.assertEquals(deletedRecord.getAdditionalInfo().getSuppressDiscovery(), true);
Assert.assertEquals(ParsedRecordDaoUtil.getLeaderStatus(deletedRecord.getParsedRecord()), "d");

async.complete();

async = testContext.async();
Expand Down Expand Up @@ -818,10 +825,131 @@ public void shouldDeleteExistingMarcRecordOnDelete(TestContext testContext) {
.get(SOURCE_STORAGE_RECORDS_PATH + "/" + errorRecord.getId())
.then()
.statusCode(HttpStatus.SC_OK)
.body("deleted", is(true));
.body("deleted", is(true))
.body("state", is("DELETED"))
.body("additionalInfo.suppressDiscovery", is(true));
async.complete();
}

@Test
public void shouldDeleteExistingMarcRecordOnDeleteByInstanceId(TestContext testContext) {
postSnapshots(testContext, snapshot_1);

String srsId = UUID.randomUUID().toString();
String instanceId = UUID.randomUUID().toString();

ParsedRecord parsedRecord = new ParsedRecord().withId(srsId)
.withContent(new JsonObject().put("leader", "01542ccm a2200361 4500")
.put("fields", new JsonArray().add(new JsonObject().put("999", new JsonObject()
.put("subfields", new JsonArray().add(new JsonObject().put("s", srsId)).add(new JsonObject().put("i", instanceId)))))));

Record newRecord = new Record()
.withId(srsId)
.withSnapshotId(snapshot_1.getJobExecutionId())
.withRecordType(Record.RecordType.MARC_BIB)
.withRawRecord(rawMarcRecord)
.withParsedRecord(parsedRecord)
.withState(Record.State.ACTUAL)
.withExternalIdsHolder(new ExternalIdsHolder()
.withInstanceId(instanceId))
.withMatchedId(UUID.randomUUID().toString());

Async async = testContext.async();
Response createParsed = RestAssured.given()
.spec(spec)
.body(newRecord)
.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 + "/" + instanceId + "?idType=INSTANCE")
.then()
.statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();

async = testContext.async();
Response deletedResponse = RestAssured.given()
.spec(spec)
.when()
.get(SOURCE_STORAGE_RECORDS_PATH + "/" + parsed.getId());
Assert.assertEquals(deletedResponse.getStatusCode(), HttpStatus.SC_OK);
Record deletedRecord = deletedResponse.body().as(Record.class);

Assert.assertEquals(deletedRecord.getDeleted(), true);
Assert.assertEquals(deletedRecord.getState(), Record.State.DELETED);
Assert.assertEquals(deletedRecord.getLeaderRecordStatus(), "d");
Assert.assertEquals(deletedRecord.getAdditionalInfo().getSuppressDiscovery(), true);
Assert.assertEquals(ParsedRecordDaoUtil.getLeaderStatus(deletedRecord.getParsedRecord()), "d");

async.complete();
}

@Test
public void shouldReturnNotFoundIfTryingToDeleteRecordWithStateNotActual(TestContext testContext) {
postSnapshots(testContext, snapshot_1);

Record newRecord1 = new Record()
.withId(UUID.randomUUID().toString())
.withSnapshotId(snapshot_1.getJobExecutionId())
.withRecordType(Record.RecordType.MARC_BIB)
.withRawRecord(rawMarcRecord)
.withParsedRecord(parsedMarcRecord)
.withState(Record.State.OLD)
.withMatchedId(UUID.randomUUID().toString());

Async async = testContext.async();
Response createParsed = RestAssured.given()
.spec(spec)
.body(newRecord1)
.when()
.post(SOURCE_STORAGE_RECORDS_PATH);
assertThat(createParsed.statusCode(), is(HttpStatus.SC_CREATED));
async.complete();

async = testContext.async();
RestAssured.given()
.spec(spec)
.when()
.delete(SOURCE_STORAGE_RECORDS_PATH + "/" + newRecord1.getId())
.then()
.statusCode(HttpStatus.SC_NOT_FOUND);
async.complete();

Record newRecord2 = new Record()
.withId(UUID.randomUUID().toString())
.withSnapshotId(snapshot_1.getJobExecutionId())
.withRecordType(Record.RecordType.MARC_BIB)
.withRawRecord(rawMarcRecord)
.withParsedRecord(parsedMarcRecord)
.withState(Record.State.DELETED)
.withMatchedId(UUID.randomUUID().toString());

async = testContext.async();
Response createParsed2 = RestAssured.given()
.spec(spec)
.body(newRecord2)
.when()
.post(SOURCE_STORAGE_RECORDS_PATH);
assertThat(createParsed2.statusCode(), is(HttpStatus.SC_CREATED));
async.complete();

async = testContext.async();
RestAssured.given()
.spec(spec)
.when()
.delete(SOURCE_STORAGE_RECORDS_PATH + "/" + newRecord2.getId())
.then()
.statusCode(HttpStatus.SC_NOT_FOUND);
async.complete();
}


@Test
public void shouldDeleteExistingEdifactRecordOnDelete(TestContext testContext) {
postSnapshots(testContext, snapshot_3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,8 @@ public void shouldReturnIdOnSearchMarcRecordIdsWhenRecordWasDeleted(TestContext
.statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();
MarcRecordSearchRequest searchRequest = new MarcRecordSearchRequest();
searchRequest.setLeaderSearchExpression("p_05 = 'c' and p_06 = 'c' and p_07 = 'm'");
searchRequest.setLeaderSearchExpression("p_05 = 'd' and p_06 = 'c' and p_07 = 'm'");
searchRequest.setSuppressFromDiscovery(true);
searchRequest.setFieldsSearchExpression("001.value = '393893' and 005.value ^= '2014110' and 035.ind1 = '#'");
searchRequest.setDeleted(true);
// when
Expand Down

0 comments on commit 5f8943d

Please sign in to comment.