Search in sources :

Example 1 with InitJobExecutionsRqDto

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"));
}
Also used : InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(org.folio.rest.jaxrs.model.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 2 with InitJobExecutionsRqDto

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());
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.containsString(org.hamcrest.Matchers.containsString) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 3 with InitJobExecutionsRqDto

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));
}
Also used : DeleteJobExecutionsReq(org.folio.rest.jaxrs.model.DeleteJobExecutionsReq) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(org.folio.rest.jaxrs.model.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 4 with InitJobExecutionsRqDto

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());
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.containsString(org.hamcrest.Matchers.containsString) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 5 with InitJobExecutionsRqDto

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();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) JournalServiceImpl(org.folio.services.journal.JournalServiceImpl) MockitoAnnotations(org.mockito.MockitoAnnotations) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) ERROR(org.folio.rest.jaxrs.model.JobExecution.Status.ERROR) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) MappingRulesSnapshotDaoImpl(org.folio.dao.MappingRulesSnapshotDaoImpl) DataImportEventPayload(org.folio.DataImportEventPayload) UUID(java.util.UUID) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) MarcImportEventsHandler(org.folio.verticle.consumers.util.MarcImportEventsHandler) 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) Json(io.vertx.core.json.Json) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RunWith(org.junit.runner.RunWith) PARSING_IN_PROGRESS(org.folio.rest.jaxrs.model.JobExecution.Status.PARSING_IN_PROGRESS) HashMap(java.util.HashMap) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) JobExecutionProgressServiceImpl(org.folio.services.progress.JobExecutionProgressServiceImpl) 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) TestUtil(org.folio.TestUtil) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) InjectMocks(org.mockito.InjectMocks) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) JobExecutionProgressDaoImpl(org.folio.dao.JobExecutionProgressDaoImpl) RUNNING_COMPLETE(org.folio.rest.jaxrs.model.JobExecution.UiStatus.RUNNING_COMPLETE) Vertx(io.vertx.core.Vertx) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) IOException(java.io.IOException) Test(org.junit.Test) COMMITTED(org.folio.rest.jaxrs.model.JobExecution.Status.COMMITTED) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MappingParamsSnapshotDaoImpl(org.folio.dao.MappingParamsSnapshotDaoImpl) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.putRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) JsonArray(io.vertx.core.json.JsonArray) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) Rule(org.junit.Rule) WireMock.created(com.github.tomakehurst.wiremock.client.WireMock.created) File(org.folio.rest.jaxrs.model.File) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) DataImportEventTypes(org.folio.rest.jaxrs.model.DataImportEventTypes) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) Collections(java.util.Collections) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) KafkaConfig(org.folio.kafka.KafkaConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataImportEventPayload(org.folio.DataImportEventPayload) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Aggregations

InitJobExecutionsRqDto (org.folio.rest.jaxrs.model.InitJobExecutionsRqDto)25 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)24 Test (org.junit.Test)24 File (org.folio.rest.jaxrs.model.File)22 Future (io.vertx.core.Future)17 Vertx (io.vertx.core.Vertx)17 Async (io.vertx.ext.unit.Async)17 TestContext (io.vertx.ext.unit.TestContext)17 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)17 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)17 HashMap (java.util.HashMap)17 UUID (java.util.UUID)17 PostgresClientFactory (org.folio.dao.util.PostgresClientFactory)17 OkapiConnectionParams (org.folio.dataimport.util.OkapiConnectionParams)17 OKAPI_URL_HEADER (org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER)17 OKAPI_TENANT_HEADER (org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER)17 OKAPI_TOKEN_HEADER (org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER)17 Before (org.junit.Before)17 Rule (org.junit.Rule)17 RunWith (org.junit.runner.RunWith)17