Search in sources :

Example 1 with Status

use of org.folio.services.Status in project mod-source-record-manager by folio-org.

the class MetadataProviderJobExecutionAPITest method shouldNotReturnDiscardedInCollection.

@Test
public void shouldNotReturnDiscardedInCollection() {
    int numberOfFiles = 5;
    int expectedNotDiscardedNumber = 2;
    List<JobExecution> createdJobExecutions = constructAndPostInitJobExecutionRqDto(numberOfFiles).getJobExecutions();
    List<JobExecution> children = createdJobExecutions.stream().filter(jobExec -> jobExec.getSubordinationType().equals(CHILD)).collect(Collectors.toList());
    StatusDto discardedStatus = new StatusDto().withStatus(StatusDto.Status.DISCARDED);
    for (int i = 0; i < children.size() - expectedNotDiscardedNumber; i++) {
        updateJobExecutionStatus(children.get(i), discardedStatus).then().statusCode(HttpStatus.SC_OK);
    }
    RestAssured.given().spec(spec).when().queryParam("statusNot", Status.DISCARDED).get(GET_JOB_EXECUTIONS_PATH).then().statusCode(HttpStatus.SC_OK).body("jobExecutions.size()", is(expectedNotDiscardedNumber)).body("jobExecutions*.status", not(StatusDto.Status.DISCARDED.name())).body("totalRecords", is(expectedNotDiscardedNumber));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) EDIFACT(org.folio.rest.jaxrs.model.JournalRecord.EntityType.EDIFACT) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_BIBLIOGRAPHIC) MARC_AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_AUTHORITY) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) Matchers.not(org.hamcrest.Matchers.not) HttpStatus(org.apache.http.HttpStatus) CHILD(org.folio.rest.jaxrs.model.JobExecution.SubordinationType.CHILD) MockitoAnnotations(org.mockito.MockitoAnnotations) Matchers.everyItem(org.hamcrest.Matchers.everyItem) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) After(org.junit.After) Spy(org.mockito.Spy) Matchers.nullValue(org.hamcrest.Matchers.nullValue) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JsonObject(io.vertx.core.json.JsonObject) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) ZoneOffset(java.time.ZoneOffset) HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.HOLDINGS) JobExecutionDto(org.folio.rest.jaxrs.model.JobExecutionDto) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) StatusDto(org.folio.rest.jaxrs.model.StatusDto) ChangeManagerAPITest(org.folio.rest.impl.changeManager.ChangeManagerAPITest) AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.AUTHORITY) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) UUID(java.util.UUID) Instant(java.time.Instant) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) List(java.util.List) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) RestAssured(io.restassured.RestAssured) Progress(org.folio.rest.jaxrs.model.Progress) Async(io.vertx.ext.unit.Async) RunWith(org.junit.runner.RunWith) PARENT_MULTIPLE(org.folio.rest.jaxrs.model.JobExecution.SubordinationType.PARENT_MULTIPLE) DeleteJobExecutionsResp(org.folio.rest.jaxrs.model.DeleteJobExecutionsResp) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) JournalRecordCollection(org.folio.rest.jaxrs.model.JournalRecordCollection) EntityType(org.folio.rest.jaxrs.model.EntityType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Status(org.folio.services.Status) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) MARC(org.folio.rest.jaxrs.model.JobProfileInfo.DataType.MARC) ITEM(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ITEM) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) UPDATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.UPDATE) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) INSTANCE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INSTANCE) NON_MATCH(org.folio.rest.jaxrs.model.JournalRecord.ActionType.NON_MATCH) RunBy(org.folio.rest.jaxrs.model.RunBy) INVOICE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INVOICE) ChronoUnit(java.time.temporal.ChronoUnit) Matchers.hasItem(org.hamcrest.Matchers.hasItem) JobExecutionsCache(org.folio.services.JobExecutionsCache) DateTimeFormatter(java.time.format.DateTimeFormatter) Assert(org.junit.Assert) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) StatusDto(org.folio.rest.jaxrs.model.StatusDto) ChangeManagerAPITest(org.folio.rest.impl.changeManager.ChangeManagerAPITest) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 2 with Status

use of org.folio.services.Status in project mod-source-record-manager by folio-org.

the class MetadataProviderJobExecutionAPITest method shouldReturnFilteredAndSortedJobExecutionsOnGetWhenConditionAndSortByIsSpecified.

@Test
public void shouldReturnFilteredAndSortedJobExecutionsOnGetWhenConditionAndSortByIsSpecified() {
    List<JobExecution> createdJobExecution = constructAndPostInitJobExecutionRqDto(8).getJobExecutions();
    List<JobExecution> childJobsToUpdate = createdJobExecution.stream().filter(jobExecution -> jobExecution.getSubordinationType().equals(CHILD)).collect(Collectors.toList());
    for (int i = 0; i < childJobsToUpdate.size(); i++) {
        if (i % 2 == 0) {
            childJobsToUpdate.get(i).withStatus(JobExecution.Status.COMMITTED).withUiStatus(JobExecution.UiStatus.RUNNING_COMPLETE);
        }
        createdJobExecution.get(i).setCompletedDate(new Date(1234567892000L + i));
        putJobExecution(createdJobExecution.get(i));
    }
    // We do not expect to get JobExecution with subordinationType=PARENT_MULTIPLE
    int expectedJobExecutionsNumber = childJobsToUpdate.size() / 2;
    JobExecutionDtoCollection jobExecutionCollection = RestAssured.given().spec(spec).when().queryParam("uiStatusAny", JobExecution.UiStatus.RUNNING_COMPLETE).queryParam("statusAny", Status.COMMITTED, Status.ERROR).queryParam("sortBy", "completed_date,desc").get(GET_JOB_EXECUTIONS_PATH).then().log().all().statusCode(HttpStatus.SC_OK).body("jobExecutions*.status", everyItem(is(JobExecution.Status.COMMITTED.value()))).body("jobExecutions*.uiStatus", everyItem(is(JobExecution.UiStatus.RUNNING_COMPLETE.value()))).extract().response().body().as(JobExecutionDtoCollection.class);
    List<JobExecutionDto> jobExecutionDtoList = jobExecutionCollection.getJobExecutions();
    Assert.assertEquals(expectedJobExecutionsNumber, jobExecutionDtoList.size());
    Assert.assertTrue(jobExecutionDtoList.get(0).getCompletedDate().after(jobExecutionDtoList.get(1).getCompletedDate()));
    Assert.assertTrue(jobExecutionDtoList.get(1).getCompletedDate().after(jobExecutionDtoList.get(2).getCompletedDate()));
    Assert.assertTrue(jobExecutionDtoList.get(2).getCompletedDate().after(jobExecutionDtoList.get(3).getCompletedDate()));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) EDIFACT(org.folio.rest.jaxrs.model.JournalRecord.EntityType.EDIFACT) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_BIBLIOGRAPHIC) MARC_AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_AUTHORITY) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) Matchers.not(org.hamcrest.Matchers.not) HttpStatus(org.apache.http.HttpStatus) CHILD(org.folio.rest.jaxrs.model.JobExecution.SubordinationType.CHILD) MockitoAnnotations(org.mockito.MockitoAnnotations) Matchers.everyItem(org.hamcrest.Matchers.everyItem) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) After(org.junit.After) Spy(org.mockito.Spy) Matchers.nullValue(org.hamcrest.Matchers.nullValue) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JsonObject(io.vertx.core.json.JsonObject) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) ZoneOffset(java.time.ZoneOffset) HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.HOLDINGS) JobExecutionDto(org.folio.rest.jaxrs.model.JobExecutionDto) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) StatusDto(org.folio.rest.jaxrs.model.StatusDto) ChangeManagerAPITest(org.folio.rest.impl.changeManager.ChangeManagerAPITest) AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.AUTHORITY) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) UUID(java.util.UUID) Instant(java.time.Instant) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) List(java.util.List) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) RestAssured(io.restassured.RestAssured) Progress(org.folio.rest.jaxrs.model.Progress) Async(io.vertx.ext.unit.Async) RunWith(org.junit.runner.RunWith) PARENT_MULTIPLE(org.folio.rest.jaxrs.model.JobExecution.SubordinationType.PARENT_MULTIPLE) DeleteJobExecutionsResp(org.folio.rest.jaxrs.model.DeleteJobExecutionsResp) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) JournalRecordCollection(org.folio.rest.jaxrs.model.JournalRecordCollection) EntityType(org.folio.rest.jaxrs.model.EntityType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Status(org.folio.services.Status) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) MARC(org.folio.rest.jaxrs.model.JobProfileInfo.DataType.MARC) ITEM(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ITEM) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) UPDATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.UPDATE) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) INSTANCE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INSTANCE) NON_MATCH(org.folio.rest.jaxrs.model.JournalRecord.ActionType.NON_MATCH) RunBy(org.folio.rest.jaxrs.model.RunBy) INVOICE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INVOICE) ChronoUnit(java.time.temporal.ChronoUnit) Matchers.hasItem(org.hamcrest.Matchers.hasItem) JobExecutionsCache(org.folio.services.JobExecutionsCache) DateTimeFormatter(java.time.format.DateTimeFormatter) Assert(org.junit.Assert) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) JobExecutionDto(org.folio.rest.jaxrs.model.JobExecutionDto) Date(java.util.Date) ChangeManagerAPITest(org.folio.rest.impl.changeManager.ChangeManagerAPITest) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Aggregations

RestAssured (io.restassured.RestAssured)2 Future (io.vertx.core.Future)2 JsonObject (io.vertx.core.json.JsonObject)2 Async (io.vertx.ext.unit.Async)2 TestContext (io.vertx.ext.unit.TestContext)2 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)2 Instant (java.time.Instant)2 ZoneOffset (java.time.ZoneOffset)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ChronoUnit (java.time.temporal.ChronoUnit)2 Date (java.util.Date)2 List (java.util.List)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 HttpStatus (org.apache.http.HttpStatus)2 JournalRecordDaoImpl (org.folio.dao.JournalRecordDaoImpl)2 PostgresClientFactory (org.folio.dao.util.PostgresClientFactory)2 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)2 ChangeManagerAPITest (org.folio.rest.impl.changeManager.ChangeManagerAPITest)2