Search in sources :

Example 1 with DeleteJobExecutionsReq

use of org.folio.rest.jaxrs.model.DeleteJobExecutionsReq in project mod-source-record-manager by folio-org.

the class ChangeManagerAPITest method testDeleteChangeManagerJobExecutionsSingleEntity.

@Test
public void testDeleteChangeManagerJobExecutionsSingleEntity() {
    // given
    String jsonFiles;
    List<File> filesList;
    try {
        jsonFiles = TestUtil.readFileFromPath(FILES_PATH);
        filesList = new ObjectMapper().readValue(jsonFiles, new TypeReference<>() {
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    List<File> limitedFilesList = filesList.stream().limit(1).collect(Collectors.toList());
    String stubUserId = UUID.randomUUID().toString();
    WireMock.stubFor(get(GET_USER_URL + stubUserId).willReturn(okJson(userResponse.toString())));
    InitJobExecutionsRqDto requestDto = new InitJobExecutionsRqDto();
    requestDto.getFiles().addAll(limitedFilesList);
    requestDto.setUserId(stubUserId);
    requestDto.setSourceType(InitJobExecutionsRqDto.SourceType.FILES);
    // when
    String parentJobExecutionId = RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().post(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_CREATED).extract().path("parentJobExecutionId");
    DeleteJobExecutionsReq deleteJobExecutionsReq = new DeleteJobExecutionsReq().withIds(Arrays.asList(parentJobExecutionId));
    RestAssured.given().spec(spec).body(deleteJobExecutionsReq).when().delete(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_OK).body("jobExecutionDetails.isDeleted.get(0)", is(true)).body("jobExecutionDetails.jobExecutionId.get(0)", is(parentJobExecutionId));
}
Also used : DeleteJobExecutionsReq(org.folio.rest.jaxrs.model.DeleteJobExecutionsReq) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(org.folio.rest.jaxrs.model.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 2 with DeleteJobExecutionsReq

use of org.folio.rest.jaxrs.model.DeleteJobExecutionsReq in project mod-source-record-manager by folio-org.

the class ChangeManagerAPITest method testDeleteChangeManagerJobExecutionsMultipleIds.

@Test
public void testDeleteChangeManagerJobExecutionsMultipleIds() {
    // given
    String jsonFiles;
    List<File> filesList;
    try {
        jsonFiles = TestUtil.readFileFromPath(FILES_PATH);
        filesList = new ObjectMapper().readValue(jsonFiles, new TypeReference<>() {
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    List<File> limitedFilesList = filesList.stream().limit(1).collect(Collectors.toList());
    String stubUserId = UUID.randomUUID().toString();
    WireMock.stubFor(get(GET_USER_URL + stubUserId).willReturn(okJson(userResponse.toString())));
    InitJobExecutionsRqDto requestDto = new InitJobExecutionsRqDto();
    requestDto.getFiles().addAll(limitedFilesList);
    requestDto.setUserId(stubUserId);
    requestDto.setSourceType(InitJobExecutionsRqDto.SourceType.FILES);
    // when
    String parentJobExecutionId = RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().post(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_CREATED).extract().path("parentJobExecutionId");
    // when
    String parentJobExecutionId_2 = RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().post(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_CREATED).extract().path("parentJobExecutionId");
    DeleteJobExecutionsReq deleteJobExecutionsReq = new DeleteJobExecutionsReq().withIds(Arrays.asList(parentJobExecutionId, parentJobExecutionId_2));
    RestAssured.given().spec(spec).body(deleteJobExecutionsReq).when().delete(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_OK).body("jobExecutionDetails.jobExecutionId.get(0)", is(parentJobExecutionId)).body("jobExecutionDetails.isDeleted.get(0)", is(true)).body("jobExecutionDetails.jobExecutionId.get(1)", is(parentJobExecutionId_2)).body("jobExecutionDetails.isDeleted.get(1)", is(true));
}
Also used : DeleteJobExecutionsReq(org.folio.rest.jaxrs.model.DeleteJobExecutionsReq) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(org.folio.rest.jaxrs.model.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)2 DeleteJobExecutionsReq (org.folio.rest.jaxrs.model.DeleteJobExecutionsReq)2 File (org.folio.rest.jaxrs.model.File)2 InitJobExecutionsRqDto (org.folio.rest.jaxrs.model.InitJobExecutionsRqDto)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2