Search in sources :

Example 11 with StatusDto

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

the class EventDrivenChunkProcessingServiceImplTest method shouldSendEventsWithSuccessfullyParsedRecords.

@Test
public void shouldSendEventsWithSuccessfullyParsedRecords(TestContext context) {
    Async async = context.async();
    RawRecordsDto rawRecordsDto = new RawRecordsDto().withRecordsMetadata(new RecordsMetadata().withLast(false).withCounter(1).withContentType(RecordsMetadata.ContentType.MARC_RAW)).withInitialRecords(Arrays.asList(new InitialRecord().withRecord(CORRECT_RAW_RECORD), new InitialRecord().withRecord(CORRECT_RAW_RECORD), new InitialRecord().withRecord(RAW_RECORD_RESULTING_IN_PARSING_ERROR)));
    Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).compose(jobExecution -> chunkProcessingService.processChunk(rawRecordsDto, jobExecution.getId(), params));
    future.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        ArgumentCaptor<StatusDto> captor = ArgumentCaptor.forClass(StatusDto.class);
        Mockito.verify(jobExecutionService).updateJobExecutionStatus(anyString(), captor.capture(), isA(OkapiConnectionParams.class));
        context.assertTrue(PARSING_IN_PROGRESS.equals(captor.getValue().getStatus()));
        verify(1, postRequestedFor(urlPathEqualTo(SNAPSHOT_SERVICE_URL)));
        async.complete();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) Arrays(java.util.Arrays) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) MockitoAnnotations(org.mockito.MockitoAnnotations) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) After(org.junit.After) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) StatusDto(org.folio.rest.jaxrs.model.StatusDto) MappingRulesSnapshotDaoImpl(org.folio.dao.MappingRulesSnapshotDaoImpl) WireMock.put(com.github.tomakehurst.wiremock.client.WireMock.put) UUID(java.util.UUID) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) Optional(java.util.Optional) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) JobExecutionSourceChunkDaoImpl(org.folio.dao.JobExecutionSourceChunkDaoImpl) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Async(io.vertx.ext.unit.Async) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Record(org.folio.Record) RunWith(org.junit.runner.RunWith) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) HashMap(java.util.HashMap) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) JobExecutionProgressServiceImpl(org.folio.services.progress.JobExecutionProgressServiceImpl) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) WireMock.ok(com.github.tomakehurst.wiremock.client.WireMock.ok) WireMock(com.github.tomakehurst.wiremock.client.WireMock) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) DataType(org.folio.rest.jaxrs.model.JobProfileInfo.DataType) ArgumentCaptor(org.mockito.ArgumentCaptor) TestUtil(org.folio.TestUtil) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) InjectMocks(org.mockito.InjectMocks) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) JobExecutionProgressDaoImpl(org.folio.dao.JobExecutionProgressDaoImpl) Vertx(io.vertx.core.Vertx) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MappingParamsSnapshotDaoImpl(org.folio.dao.MappingParamsSnapshotDaoImpl) Mockito.when(org.mockito.Mockito.when) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) File(org.folio.rest.jaxrs.model.File) WireMock.created(com.github.tomakehurst.wiremock.client.WireMock.created) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) PARSING_IN_PROGRESS(org.folio.rest.jaxrs.model.StatusDto.Status.PARSING_IN_PROGRESS) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Collections(java.util.Collections) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) KafkaConfig(org.folio.kafka.KafkaConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatusDto(org.folio.rest.jaxrs.model.StatusDto) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) Async(io.vertx.ext.unit.Async) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 12 with StatusDto

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

the class EventDrivenChunkProcessingServiceImplTest method shouldReturnSucceededFutureWhenFailedPostSnapshotsToRecordsStorage.

@Test
public void shouldReturnSucceededFutureWhenFailedPostSnapshotsToRecordsStorage(TestContext context) {
    Async async = context.async();
    WireMock.stubFor(put(SNAPSHOT_SERVICE_URL).willReturn(WireMock.serverError()));
    Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).compose(jobExecution -> chunkProcessingService.processChunk(rawRecordsDto, jobExecution.getId(), params));
    future.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        ArgumentCaptor<StatusDto> captor = ArgumentCaptor.forClass(StatusDto.class);
        Mockito.verify(jobExecutionService, times(1)).updateJobExecutionStatus(anyString(), captor.capture(), isA(OkapiConnectionParams.class));
        verify(1, postRequestedFor(urlEqualTo(SNAPSHOT_SERVICE_URL)));
        async.complete();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) Arrays(java.util.Arrays) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) MockitoAnnotations(org.mockito.MockitoAnnotations) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) After(org.junit.After) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) StatusDto(org.folio.rest.jaxrs.model.StatusDto) MappingRulesSnapshotDaoImpl(org.folio.dao.MappingRulesSnapshotDaoImpl) WireMock.put(com.github.tomakehurst.wiremock.client.WireMock.put) UUID(java.util.UUID) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) Optional(java.util.Optional) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) JobExecutionSourceChunkDaoImpl(org.folio.dao.JobExecutionSourceChunkDaoImpl) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Async(io.vertx.ext.unit.Async) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Record(org.folio.Record) RunWith(org.junit.runner.RunWith) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) HashMap(java.util.HashMap) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) JobExecutionProgressServiceImpl(org.folio.services.progress.JobExecutionProgressServiceImpl) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) WireMock.ok(com.github.tomakehurst.wiremock.client.WireMock.ok) WireMock(com.github.tomakehurst.wiremock.client.WireMock) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) DataType(org.folio.rest.jaxrs.model.JobProfileInfo.DataType) ArgumentCaptor(org.mockito.ArgumentCaptor) TestUtil(org.folio.TestUtil) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) InjectMocks(org.mockito.InjectMocks) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) JobExecutionProgressDaoImpl(org.folio.dao.JobExecutionProgressDaoImpl) Vertx(io.vertx.core.Vertx) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MappingParamsSnapshotDaoImpl(org.folio.dao.MappingParamsSnapshotDaoImpl) Mockito.when(org.mockito.Mockito.when) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) File(org.folio.rest.jaxrs.model.File) WireMock.created(com.github.tomakehurst.wiremock.client.WireMock.created) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) PARSING_IN_PROGRESS(org.folio.rest.jaxrs.model.StatusDto.Status.PARSING_IN_PROGRESS) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Collections(java.util.Collections) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) KafkaConfig(org.folio.kafka.KafkaConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatusDto(org.folio.rest.jaxrs.model.StatusDto) Async(io.vertx.ext.unit.Async) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 13 with StatusDto

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

the class ChangeManagerAPITest method shouldReturnNotFoundOnStatusUpdate.

@Test
public void shouldReturnNotFoundOnStatusUpdate() {
    StatusDto status = new StatusDto().withStatus(StatusDto.Status.NEW);
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(status).toString()).when().put(JOB_EXECUTION_PATH + UUID.randomUUID().toString() + STATUS_PATH).then().statusCode(HttpStatus.SC_NOT_FOUND);
}
Also used : StatusDto(org.folio.rest.jaxrs.model.StatusDto) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 14 with StatusDto

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

the class ChangeManagerAPITest method shouldNotUpdateStatusOfDeletedRecords.

@Test
public void shouldNotUpdateStatusOfDeletedRecords() {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(3);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(4));
    JobExecution child = createdJobExecutions.stream().filter(jobExec -> jobExec.getSubordinationType().equals(JobExecution.SubordinationType.CHILD)).findFirst().get();
    DeleteJobExecutionsResp deleteJobExecutionsResp = returnDeletedJobExecutionResponse(new String[] { child.getId() });
    assertThat(deleteJobExecutionsResp.getJobExecutionDetails().get(0).getJobExecutionId(), is(child.getId()));
    assertThat(deleteJobExecutionsResp.getJobExecutionDetails().get(0).getIsDeleted(), is(true));
    StatusDto status = new StatusDto().withStatus(StatusDto.Status.PARSING_IN_PROGRESS);
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(status).toString()).when().put(JOB_EXECUTION_PATH + child.getId() + STATUS_PATH).then().statusCode(HttpStatus.SC_NOT_FOUND);
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) StatusDto(org.folio.rest.jaxrs.model.StatusDto) DeleteJobExecutionsResp(org.folio.rest.jaxrs.model.DeleteJobExecutionsResp) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 15 with StatusDto

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

the class ChangeManagerAPITest method shouldNotUpdateStatusToParent.

@Test
public void shouldNotUpdateStatusToParent() {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    StatusDto status = new StatusDto().withStatus(StatusDto.Status.PARENT);
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(status).toString()).when().put(JOB_EXECUTION_PATH + jobExec.getId() + STATUS_PATH).then().statusCode(HttpStatus.SC_BAD_REQUEST);
    RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(jobExec.getStatus().name())).body("uiStatus", is(jobExec.getUiStatus().name()));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) StatusDto(org.folio.rest.jaxrs.model.StatusDto) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Aggregations

StatusDto (org.folio.rest.jaxrs.model.StatusDto)18 JobExecution (org.folio.rest.jaxrs.model.JobExecution)17 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)14 Test (org.junit.Test)14 InitJobExecutionsRsDto (org.folio.rest.jaxrs.model.InitJobExecutionsRsDto)10 Future (io.vertx.core.Future)8 JsonObject (io.vertx.core.json.JsonObject)7 UUID (java.util.UUID)7 OkapiConnectionParams (org.folio.dataimport.util.OkapiConnectionParams)7 JobProfileInfo (org.folio.rest.jaxrs.model.JobProfileInfo)7 Async (io.vertx.ext.unit.Async)6 Collections (java.util.Collections)6 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)5 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)5 TestContext (io.vertx.ext.unit.TestContext)5 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)5 HashMap (java.util.HashMap)5 WireMock (com.github.tomakehurst.wiremock.client.WireMock)4 WireMock.created (com.github.tomakehurst.wiremock.client.WireMock.created)4 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)4