use of org.folio.rest.jaxrs.model.InitJobExecutionsRqDto in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method testInitJobExecutionsWithUserWithoutPersonalInformation.
@Test
public void testInitJobExecutionsWithUserWithoutPersonalInformation() {
// 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");
JsonObject jsonUser = userResponse.getJsonArray("users").getJsonObject(0);
RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + parentJobExecutionId).then().statusCode(HttpStatus.SC_OK).body("id", is(parentJobExecutionId)).body("hrId", greaterThanOrEqualTo(0)).body("runBy.firstName", is(jsonUser.getString("username"))).body("runBy.lastName", is("SYSTEM"));
}
use of org.folio.rest.jaxrs.model.InitJobExecutionsRqDto in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method testInitJobExecutionsWithoutJobProfileAndOnline.
@Test
public void testInitJobExecutionsWithoutJobProfileAndOnline() {
// given
int expectedJobExecutionsNumber = 1;
// when
InitJobExecutionsRqDto requestDto = new InitJobExecutionsRqDto();
requestDto.setUserId(okapiUserIdHeader);
requestDto.setSourceType(InitJobExecutionsRqDto.SourceType.ONLINE);
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.getRunBy().getFirstName());
Assert.assertNotNull(parentSingle.getRunBy().getLastName());
}
use of org.folio.rest.jaxrs.model.InitJobExecutionsRqDto 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));
}
use of org.folio.rest.jaxrs.model.InitJobExecutionsRqDto 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.InitJobExecutionsRqDto 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();
});
}
Aggregations