Search in sources :

Example 21 with MigrationExecutionDtoBuilder

use of org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder in project camunda-bpm-platform by camunda.

the class MigrationRestServiceInteractionTest method executeMigratingProcessInstanceValidationException.

@Test
public void executeMigratingProcessInstanceValidationException() {
    MigrationInstruction migrationInstruction = mock(MigrationInstruction.class);
    when(migrationInstruction.getSourceActivityId()).thenReturn(EXAMPLE_ACTIVITY_ID);
    when(migrationInstruction.getTargetActivityId()).thenReturn(ANOTHER_EXAMPLE_ACTIVITY_ID);
    MigratingActivityInstanceValidationReport instanceReport1 = mock(MigratingActivityInstanceValidationReport.class);
    when(instanceReport1.getActivityInstanceId()).thenReturn(EXAMPLE_ACTIVITY_INSTANCE_ID);
    when(instanceReport1.getMigrationInstruction()).thenReturn(migrationInstruction);
    when(instanceReport1.getSourceScopeId()).thenReturn(EXAMPLE_ACTIVITY_ID);
    when(instanceReport1.getFailures()).thenReturn(Arrays.asList("failure1", "failure2"));
    MigratingTransitionInstanceValidationReport instanceReport2 = mock(MigratingTransitionInstanceValidationReport.class);
    when(instanceReport2.getTransitionInstanceId()).thenReturn("transitionInstanceId");
    when(instanceReport2.getMigrationInstruction()).thenReturn(migrationInstruction);
    when(instanceReport2.getSourceScopeId()).thenReturn(EXAMPLE_ACTIVITY_ID);
    when(instanceReport2.getFailures()).thenReturn(Arrays.asList("failure1", "failure2"));
    MigratingProcessInstanceValidationReport processInstanceReport = mock(MigratingProcessInstanceValidationReport.class);
    when(processInstanceReport.getProcessInstanceId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID);
    when(processInstanceReport.getFailures()).thenReturn(Arrays.asList("failure1", "failure2"));
    when(processInstanceReport.getActivityInstanceReports()).thenReturn(Arrays.asList(instanceReport1));
    when(processInstanceReport.getTransitionInstanceReports()).thenReturn(Arrays.asList(instanceReport2));
    doThrow(new MigratingProcessInstanceValidationException("fooo", processInstanceReport)).when(migrationPlanExecutionBuilderMock).execute();
    Map<String, Object> migrationExecution = new MigrationExecutionDtoBuilder().migrationPlan(EXAMPLE_PROCESS_DEFINITION_ID, ANOTHER_EXAMPLE_PROCESS_DEFINITION_ID).instruction(EXAMPLE_ACTIVITY_ID, ANOTHER_EXAMPLE_ACTIVITY_ID).done().processInstances(EXAMPLE_PROCESS_INSTANCE_ID, ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID).build();
    given().contentType(POST_JSON_CONTENT_TYPE).body(migrationExecution).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("type", equalTo(MigratingProcessInstanceValidationException.class.getSimpleName())).body("message", is("fooo")).body("validationReport.processInstanceId", is(EXAMPLE_PROCESS_INSTANCE_ID)).body("validationReport.failures", hasSize(2)).body("validationReport.failures[0]", is("failure1")).body("validationReport.failures[1]", is("failure2")).body("validationReport.activityInstanceValidationReports", hasSize(1)).body("validationReport.activityInstanceValidationReports[0].migrationInstruction.sourceActivityIds", hasSize(1)).body("validationReport.activityInstanceValidationReports[0].migrationInstruction.sourceActivityIds[0]", is(EXAMPLE_ACTIVITY_ID)).body("validationReport.activityInstanceValidationReports[0].migrationInstruction.targetActivityIds", hasSize(1)).body("validationReport.activityInstanceValidationReports[0].migrationInstruction.targetActivityIds[0]", is(ANOTHER_EXAMPLE_ACTIVITY_ID)).body("validationReport.activityInstanceValidationReports[0].activityInstanceId", is(EXAMPLE_ACTIVITY_INSTANCE_ID)).body("validationReport.activityInstanceValidationReports[0].sourceScopeId", is(EXAMPLE_ACTIVITY_ID)).body("validationReport.activityInstanceValidationReports[0].failures", hasSize(2)).body("validationReport.activityInstanceValidationReports[0].failures[0]", is("failure1")).body("validationReport.activityInstanceValidationReports[0].failures[1]", is("failure2")).body("validationReport.transitionInstanceValidationReports", hasSize(1)).body("validationReport.transitionInstanceValidationReports[0].migrationInstruction.sourceActivityIds", hasSize(1)).body("validationReport.transitionInstanceValidationReports[0].migrationInstruction.sourceActivityIds[0]", is(EXAMPLE_ACTIVITY_ID)).body("validationReport.transitionInstanceValidationReports[0].migrationInstruction.targetActivityIds", hasSize(1)).body("validationReport.transitionInstanceValidationReports[0].migrationInstruction.targetActivityIds[0]", is(ANOTHER_EXAMPLE_ACTIVITY_ID)).body("validationReport.transitionInstanceValidationReports[0].transitionInstanceId", is("transitionInstanceId")).body("validationReport.transitionInstanceValidationReports[0].sourceScopeId", is(EXAMPLE_ACTIVITY_ID)).body("validationReport.transitionInstanceValidationReports[0].failures", hasSize(2)).body("validationReport.transitionInstanceValidationReports[0].failures[0]", is("failure1")).body("validationReport.transitionInstanceValidationReports[0].failures[1]", is("failure2")).when().post(EXECUTE_MIGRATION_URL);
}
Also used : MigrationExecutionDtoBuilder(org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder) MigratingActivityInstanceValidationReport(org.camunda.bpm.engine.migration.MigratingActivityInstanceValidationReport) MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) MigratingProcessInstanceValidationReport(org.camunda.bpm.engine.migration.MigratingProcessInstanceValidationReport) MigratingProcessInstanceValidationException(org.camunda.bpm.engine.migration.MigratingProcessInstanceValidationException) Matchers.anyString(org.mockito.Matchers.anyString) MigratingTransitionInstanceValidationReport(org.camunda.bpm.engine.migration.MigratingTransitionInstanceValidationReport) Test(org.junit.Test)

Example 22 with MigrationExecutionDtoBuilder

use of org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder in project camunda-bpm-platform by camunda.

the class MigrationRestServiceInteractionTest method executeMigrationPlanWithNullSourceActivityId.

@Test
public void executeMigrationPlanWithNullSourceActivityId() {
    String message = "sourceActivityId is null";
    when(migrationPlanBuilderMock.mapActivities(isNull(String.class), anyString())).thenThrow(new BadUserRequestException(message));
    Map<String, Object> migrationExecution = new MigrationExecutionDtoBuilder().migrationPlan(EXAMPLE_PROCESS_DEFINITION_ID, ANOTHER_EXAMPLE_PROCESS_DEFINITION_ID).instruction(null, ANOTHER_EXAMPLE_ACTIVITY_ID).instruction(ANOTHER_EXAMPLE_ACTIVITY_ID, EXAMPLE_ACTIVITY_ID).done().processInstances(EXAMPLE_PROCESS_INSTANCE_ID, ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID).build();
    given().contentType(POST_JSON_CONTENT_TYPE).body(migrationExecution).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("message", is(message)).when().post(EXECUTE_MIGRATION_URL);
}
Also used : MigrationExecutionDtoBuilder(org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder) Matchers.anyString(org.mockito.Matchers.anyString) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) Test(org.junit.Test)

Example 23 with MigrationExecutionDtoBuilder

use of org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder in project camunda-bpm-platform by camunda.

the class MigrationRestServiceInteractionTest method executeMigrationPlanWithNonExistingTargetProcessInstanceId.

@Test
public void executeMigrationPlanWithNonExistingTargetProcessInstanceId() {
    String message = "target process definition with id " + NON_EXISTING_PROCESS_DEFINITION_ID + " does not exist";
    JoinedMigrationPlanBuilderMock migrationPlanBuilder = mock(JoinedMigrationPlanBuilderMock.class, new FluentAnswer());
    when(runtimeServiceMock.createMigrationPlan(anyString(), eq(NON_EXISTING_PROCESS_DEFINITION_ID))).thenReturn(migrationPlanBuilder);
    when(migrationPlanBuilder.build()).thenThrow(new BadUserRequestException(message));
    Map<String, Object> migrationExecution = new MigrationExecutionDtoBuilder().migrationPlan(EXAMPLE_PROCESS_DEFINITION_ID, NON_EXISTING_PROCESS_DEFINITION_ID).instruction(EXAMPLE_ACTIVITY_ID, ANOTHER_EXAMPLE_ACTIVITY_ID).instruction(ANOTHER_EXAMPLE_ACTIVITY_ID, EXAMPLE_ACTIVITY_ID).done().processInstances(EXAMPLE_PROCESS_INSTANCE_ID, ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID).build();
    given().contentType(POST_JSON_CONTENT_TYPE).body(migrationExecution).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("message", is(message)).when().post(EXECUTE_MIGRATION_URL);
}
Also used : MigrationExecutionDtoBuilder(org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder) FluentAnswer(org.camunda.bpm.engine.rest.helper.FluentAnswer) JoinedMigrationPlanBuilderMock(org.camunda.bpm.engine.rest.helper.MockMigrationPlanBuilder.JoinedMigrationPlanBuilderMock) Matchers.anyString(org.mockito.Matchers.anyString) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) Test(org.junit.Test)

Example 24 with MigrationExecutionDtoBuilder

use of org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder in project camunda-bpm-platform by camunda.

the class MigrationRestServiceInteractionTest method executeMigrationPlanAsyncWithNullSourceActivityId.

@Test
public void executeMigrationPlanAsyncWithNullSourceActivityId() {
    String message = "sourceActivityId is null";
    when(migrationPlanBuilderMock.mapActivities(isNull(String.class), anyString())).thenThrow(new BadUserRequestException(message));
    Map<String, Object> migrationExecution = new MigrationExecutionDtoBuilder().migrationPlan(EXAMPLE_PROCESS_DEFINITION_ID, ANOTHER_EXAMPLE_PROCESS_DEFINITION_ID).instruction(null, ANOTHER_EXAMPLE_ACTIVITY_ID).instruction(ANOTHER_EXAMPLE_ACTIVITY_ID, EXAMPLE_ACTIVITY_ID).done().processInstances(EXAMPLE_PROCESS_INSTANCE_ID, ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID).build();
    given().contentType(POST_JSON_CONTENT_TYPE).body(migrationExecution).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("message", is(message)).when().post(EXECUTE_MIGRATION_ASYNC_URL);
}
Also used : MigrationExecutionDtoBuilder(org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder) Matchers.anyString(org.mockito.Matchers.anyString) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) Test(org.junit.Test)

Example 25 with MigrationExecutionDtoBuilder

use of org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder in project camunda-bpm-platform by camunda.

the class MigrationRestServiceInteractionTest method executeMigrationPlanAsyncWithProcessInstanceQuery.

@Test
public void executeMigrationPlanAsyncWithProcessInstanceQuery() {
    when(runtimeServiceMock.createProcessInstanceQuery()).thenReturn(new ProcessInstanceQueryImpl());
    ProcessInstanceQueryDto processInstanceQuery = new ProcessInstanceQueryDto();
    processInstanceQuery.setProcessDefinitionId(EXAMPLE_PROCESS_DEFINITION_ID);
    Batch batchMock = createMockBatch();
    when(migrationPlanExecutionBuilderMock.executeAsync()).thenReturn(batchMock);
    Map<String, Object> migrationExecution = new MigrationExecutionDtoBuilder().migrationPlan(EXAMPLE_PROCESS_DEFINITION_ID, ANOTHER_EXAMPLE_PROCESS_DEFINITION_ID).instruction(EXAMPLE_ACTIVITY_ID, ANOTHER_EXAMPLE_ACTIVITY_ID).instruction(ANOTHER_EXAMPLE_ACTIVITY_ID, EXAMPLE_ACTIVITY_ID).done().processInstanceQuery(processInstanceQuery).build();
    given().contentType(POST_JSON_CONTENT_TYPE).body(migrationExecution).then().expect().statusCode(Status.OK.getStatusCode()).body("id", is(EXAMPLE_BATCH_ID)).body("type", is(EXAMPLE_BATCH_TYPE)).body("totalJobs", is(EXAMPLE_BATCH_TOTAL_JOBS)).body("batchJobsPerSeed", is(EXAMPLE_BATCH_JOBS_PER_SEED)).body("invocationsPerBatchJob", is(EXAMPLE_INVOCATIONS_PER_BATCH_JOB)).body("seedJobDefinitionId", is(EXAMPLE_SEED_JOB_DEFINITION_ID)).body("monitorJobDefinitionId", is(EXAMPLE_MONITOR_JOB_DEFINITION_ID)).body("batchJobDefinitionId", is(EXAMPLE_BATCH_JOB_DEFINITION_ID)).body("tenantId", is(EXAMPLE_TENANT_ID)).when().post(EXECUTE_MIGRATION_ASYNC_URL);
    verifyCreateMigrationPlanInteraction(migrationPlanBuilderMock, (Map<String, Object>) migrationExecution.get(MigrationExecutionDtoBuilder.PROP_MIGRATION_PLAN));
    verifyMigrationPlanAsyncExecutionInteraction(migrationExecution);
}
Also used : MigrationExecutionDtoBuilder(org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder) MockProvider.createMockBatch(org.camunda.bpm.engine.rest.helper.MockProvider.createMockBatch) Batch(org.camunda.bpm.engine.batch.Batch) ProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl) ProcessInstanceQueryDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceQueryDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

MigrationExecutionDtoBuilder (org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder)28 Test (org.junit.Test)28 Matchers.anyString (org.mockito.Matchers.anyString)28 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)16 FluentAnswer (org.camunda.bpm.engine.rest.helper.FluentAnswer)8 JoinedMigrationPlanBuilderMock (org.camunda.bpm.engine.rest.helper.MockMigrationPlanBuilder.JoinedMigrationPlanBuilderMock)8 MigrationInstructionValidationReport (org.camunda.bpm.engine.migration.MigrationInstructionValidationReport)6 MigrationPlanValidationException (org.camunda.bpm.engine.migration.MigrationPlanValidationException)6 MigrationPlanValidationReport (org.camunda.bpm.engine.migration.MigrationPlanValidationReport)6 Batch (org.camunda.bpm.engine.batch.Batch)4 MockProvider.createMockBatch (org.camunda.bpm.engine.rest.helper.MockProvider.createMockBatch)4 MigrationInstruction (org.camunda.bpm.engine.migration.MigrationInstruction)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ProcessInstanceQueryImpl (org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl)2 ProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceQueryDto)2 MigratingActivityInstanceValidationReport (org.camunda.bpm.engine.migration.MigratingActivityInstanceValidationReport)1 MigratingProcessInstanceValidationException (org.camunda.bpm.engine.migration.MigratingProcessInstanceValidationException)1 MigratingProcessInstanceValidationReport (org.camunda.bpm.engine.migration.MigratingProcessInstanceValidationReport)1 MigratingTransitionInstanceValidationReport (org.camunda.bpm.engine.migration.MigratingTransitionInstanceValidationReport)1