use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method shouldNotOverride_999_ff_s_Subfield.
@Test
public void shouldNotOverride_999_ff_s_Subfield(TestContext testContext) throws InterruptedException {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
Async async = testContext.async();
RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(DEFAULT_JOB_PROFILE_ID).withDataType(DataType.MARC)).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).body(rawRecordsDto_3).when().post(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();
String topicToObserve = formatToKafkaTopicName(DI_RAW_RECORDS_CHUNK_PARSED.value());
List<String> observedValues = kafkaCluster.observeValues(ObserveKeyValues.on(topicToObserve, 1).observeFor(30, TimeUnit.SECONDS).build());
Event obtainedEvent = Json.decodeValue(observedValues.get(6), Event.class);
assertEquals(DI_RAW_RECORDS_CHUNK_PARSED.value(), obtainedEvent.getEventType());
RecordCollection recordCollection = Json.decodeValue(obtainedEvent.getEventPayload(), RecordCollection.class);
assertEquals(1, recordCollection.getRecords().size());
Assert.assertEquals("e27a5374-0857-462e-ac84-fb4795229c7a", recordCollection.getRecords().get(0).getMatchedId());
Assert.assertEquals("e27a5374-0857-462e-ac84-fb4795229c7a", AdditionalFieldsUtil.getValue(recordCollection.getRecords().get(0), "999", 's'));
}
use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method testInitJobExecutionsWithJobProfile.
@Test
public void testInitJobExecutionsWithJobProfile() {
// given
int expectedJobExecutionsNumber = 1;
// when
InitJobExecutionsRqDto requestDto = new InitJobExecutionsRqDto();
requestDto.setUserId(okapiUserIdHeader);
requestDto.setSourceType(InitJobExecutionsRqDto.SourceType.ONLINE);
requestDto.setJobProfileInfo(new JobProfileInfo().withId(DEFAULT_JOB_PROFILE_ID).withDataType(JobProfileInfo.DataType.MARC).withName("Test Profile"));
InitJobExecutionsRsDto response = RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().log().all().post(JOB_EXECUTION_PATH).body().as(InitJobExecutionsRsDto.class);
// then
String actualParentJobExecutionId = response.getParentJobExecutionId();
List<JobExecution> actualJobExecutions = response.getJobExecutions();
Assert.assertNotNull(actualParentJobExecutionId);
assertEquals(expectedJobExecutionsNumber, actualJobExecutions.size());
JobExecution parentSingle = actualJobExecutions.get(0);
Assert.assertNotNull(parentSingle);
assertEquals(JobExecution.SubordinationType.PARENT_SINGLE, parentSingle.getSubordinationType());
Assert.assertNotNull(parentSingle.getId());
Assert.assertNotNull(parentSingle.getParentJobId());
Assert.assertTrue(parentTypes.contains(parentSingle.getSubordinationType()));
assertEquals(parentSingle.getId(), parentSingle.getParentJobId());
assertEquals(JobExecution.Status.NEW, parentSingle.getStatus());
Assert.assertNotNull(parentSingle.getJobProfileInfo());
Assert.assertNotNull(parentSingle.getRunBy().getFirstName());
Assert.assertNotNull(parentSingle.getRunBy().getLastName());
}
use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class RawMarcChunkConsumersVerticleTest method emulateJobExecutionIdRequest.
private String emulateJobExecutionIdRequest(JobProfileInfo.DataType dataType) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExecution = createdJobExecutions.get(0);
RestAssured.given().spec(spec).body(new JobProfileInfo().withName("Records name").withId(JOB_PROFILE_ID).withDataType(dataType)).when().put(JOB_EXECUTION_PATH + jobExecution.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
return jobExecution.getId();
}
use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class RecordProcessedEventHandlingServiceImplTest method shouldIncrementCurrentlySucceededAndUpdateProgressOnHandleEvent.
@Test
public void shouldIncrementCurrentlySucceededAndUpdateProgressOnHandleEvent(TestContext context) {
// given
Async async = context.async();
HashMap<String, String> payloadContext = new HashMap<>();
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DataImportEventTypes.DI_COMPLETED.value()).withContext(payloadContext);
Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).compose(jobExecution -> {
dataImportEventPayload.setJobExecutionId(jobExecution.getId());
return chunkProcessingService.processChunk(rawRecordsDto, jobExecution.getId(), params);
});
// when
Future<JobExecutionProgress> jobFuture = future.compose(ar -> recordProcessedEventHandlingService.handle(Json.encode(dataImportEventPayload), params)).compose(ar -> jobExecutionProgressService.getByJobExecutionId(dataImportEventPayload.getJobExecutionId(), TENANT_ID));
// then
jobFuture.onComplete(ar -> {
context.assertTrue(ar.succeeded());
JobExecutionProgress updatedProgress = ar.result();
context.assertEquals(1, updatedProgress.getCurrentlySucceeded());
context.assertEquals(0, updatedProgress.getCurrentlyFailed());
context.assertEquals(rawRecordsDto.getRecordsMetadata().getTotal(), updatedProgress.getTotal());
jobMonitoringService.getByJobExecutionId(updatedProgress.getJobExecutionId(), params.getTenantId()).onSuccess(optionalJobMonitoring -> {
context.assertTrue(optionalJobMonitoring.isEmpty());
async.complete();
});
async.complete();
});
}
use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class RecordProcessedEventHandlingServiceImplTest method shouldMarkJobExecutionAsErrorOnHandleDIErrorEventWhenAllRecordsProcessed.
@Test
public void shouldMarkJobExecutionAsErrorOnHandleDIErrorEventWhenAllRecordsProcessed(TestContext context) {
// given
Async async = context.async();
RawRecordsDto rawRecordsDto = new RawRecordsDto().withInitialRecords(Collections.singletonList(new InitialRecord().withRecord(CORRECT_RAW_RECORD))).withRecordsMetadata(new RecordsMetadata().withLast(true).withCounter(2).withTotal(2).withContentType(RecordsMetadata.ContentType.MARC_RAW));
HashMap<String, String> payloadContext = new HashMap<>();
DataImportEventPayload datImpErrorEventPayload = new DataImportEventPayload().withEventType(DataImportEventTypes.DI_ERROR.value()).withContext(payloadContext);
DataImportEventPayload datImpCompletedEventPayload = new DataImportEventPayload().withEventType(DataImportEventTypes.DI_COMPLETED.value()).withContext(payloadContext);
Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).map(jobExecution -> {
datImpErrorEventPayload.withJobExecutionId(jobExecution.getId());
return datImpCompletedEventPayload.withJobExecutionId(jobExecution.getId());
}).compose(ar -> chunkProcessingService.processChunk(rawRecordsDto, datImpErrorEventPayload.getJobExecutionId(), params));
// when
Future<Optional<JobExecution>> jobFuture = future.compose(ar -> recordProcessedEventHandlingService.handle(Json.encode(datImpErrorEventPayload), params)).compose(ar -> recordProcessedEventHandlingService.handle(Json.encode(datImpCompletedEventPayload), params)).compose(ar -> jobExecutionService.getJobExecutionById(datImpCompletedEventPayload.getJobExecutionId(), TENANT_ID));
// then
jobFuture.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertTrue(ar.result().isPresent());
JobExecution jobExecution = ar.result().get();
context.assertEquals(ERROR, jobExecution.getStatus());
context.assertEquals(JobExecution.UiStatus.ERROR, jobExecution.getUiStatus());
context.assertEquals(rawRecordsDto.getRecordsMetadata().getTotal(), jobExecution.getProgress().getTotal());
context.assertNotNull(jobExecution.getStartedDate());
context.assertNotNull(jobExecution.getCompletedDate());
verify(2, putRequestedFor(new UrlPathPattern(new RegexPattern(SNAPSHOT_SERVICE_URL + "/.*"), true)));
async.complete();
});
}
Aggregations