Search in sources :

Example 1 with DELETE

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

the class JournalRecordDaoTest method shouldReturnSortedJournalRecordListByActionType.

@Test
public void shouldReturnSortedJournalRecordListByActionType(TestContext testContext) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    Assert.assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    JournalRecord journalRecord1 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.MARC_BIBLIOGRAPHIC).withEntityId(UUID.randomUUID().toString()).withActionType(CREATE).withActionDate(new Date()).withActionStatus(COMPLETED);
    JournalRecord journalRecord2 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(MODIFY).withActionDate(new Date()).withActionStatus(COMPLETED);
    JournalRecord journalRecord3 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(DELETE).withActionDate(new Date()).withActionStatus(COMPLETED);
    Async async = testContext.async();
    Future<List<JournalRecord>> getFuture = journalRecordDao.save(journalRecord1, TENANT_ID).compose(ar -> journalRecordDao.save(journalRecord2, TENANT_ID)).compose(ar -> journalRecordDao.save(journalRecord3, TENANT_ID)).compose(ar -> journalRecordDao.getByJobExecutionId(jobExec.getId(), "action_type", "asc", TENANT_ID));
    getFuture.onComplete(ar -> {
        testContext.verify(v -> {
            Assert.assertTrue(ar.succeeded());
            List<JournalRecord> journalRecords = ar.result();
            Assert.assertEquals(3, journalRecords.size());
            Assert.assertThat(journalRecords.get(0).getActionType(), lessThan(journalRecords.get(1).getActionType()));
            Assert.assertThat(journalRecords.get(1).getActionType(), lessThan(journalRecords.get(2).getActionType()));
        });
        async.complete();
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Date(java.util.Date) RunWith(org.junit.runner.RunWith) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.lessThan(org.hamcrest.Matchers.lessThan) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) DELETE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.DELETE) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) Future(io.vertx.core.Future) List(java.util.List) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Assert(org.junit.Assert) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) Async(io.vertx.ext.unit.Async) List(java.util.List) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Date(java.util.Date) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 2 with DELETE

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

the class JournalRecordDaoTest method shouldReturnSortedJournalRecordListByErrorMessage.

@Test
public void shouldReturnSortedJournalRecordListByErrorMessage(TestContext testContext) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    Assert.assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    JournalRecord journalRecord1 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.MARC_BIBLIOGRAPHIC).withEntityId(UUID.randomUUID().toString()).withActionType(CREATE).withActionDate(new Date()).withActionStatus(ERROR).withError("Record creation error");
    JournalRecord journalRecord2 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(MODIFY).withActionDate(new Date()).withActionStatus(ERROR).withError("Instance was not updated");
    JournalRecord journalRecord3 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(DELETE).withActionDate(new Date()).withActionStatus(ERROR).withError("No action taken");
    Async async = testContext.async();
    Future<List<JournalRecord>> getFuture = journalRecordDao.save(journalRecord1, TENANT_ID).compose(ar -> journalRecordDao.save(journalRecord2, TENANT_ID)).compose(ar -> journalRecordDao.save(journalRecord3, TENANT_ID)).compose(ar -> journalRecordDao.getByJobExecutionId(jobExec.getId(), "error", "desc", TENANT_ID));
    getFuture.onComplete(ar -> {
        testContext.verify(v -> {
            Assert.assertTrue(ar.succeeded());
            List<JournalRecord> journalRecords = ar.result();
            Assert.assertEquals(3, journalRecords.size());
            Assert.assertThat(journalRecords.get(0).getError(), greaterThan(journalRecords.get(1).getError()));
            Assert.assertThat(journalRecords.get(1).getError(), greaterThan(journalRecords.get(2).getError()));
        });
        async.complete();
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Date(java.util.Date) RunWith(org.junit.runner.RunWith) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.lessThan(org.hamcrest.Matchers.lessThan) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) DELETE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.DELETE) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) Future(io.vertx.core.Future) List(java.util.List) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Assert(org.junit.Assert) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) Async(io.vertx.ext.unit.Async) List(java.util.List) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Date(java.util.Date) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Aggregations

Future (io.vertx.core.Future)2 Vertx (io.vertx.core.Vertx)2 Async (io.vertx.ext.unit.Async)2 TestContext (io.vertx.ext.unit.TestContext)2 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)2 IOException (java.io.IOException)2 Date (java.util.Date)2 List (java.util.List)2 UUID (java.util.UUID)2 PostgresClientFactory (org.folio.dao.util.PostgresClientFactory)2 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)2 InitJobExecutionsRsDto (org.folio.rest.jaxrs.model.InitJobExecutionsRsDto)2 JobExecution (org.folio.rest.jaxrs.model.JobExecution)2 JournalRecord (org.folio.rest.jaxrs.model.JournalRecord)2 COMPLETED (org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED)2 ERROR (org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR)2 CREATE (org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE)2 DELETE (org.folio.rest.jaxrs.model.JournalRecord.ActionType.DELETE)2 MODIFY (org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY)2 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)2