org.camunda.bpm.engine.repository.ProcessDefinition Java Examples

The following examples show how to use org.camunda.bpm.engine.repository.ProcessDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MigrationGatewayTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testCannotMigrateParallelToInclusiveGateway() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(GatewayModels.PARALLEL_GW);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(GatewayModels.INCLUSIVE_GW);

  try {
    rule.getRuntimeService()
      .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
      .mapActivities("join", "join")
      .build();
    Assert.fail("exception expected");
  } catch (MigrationPlanValidationException e) {
    // then
    assertThat(e.getValidationReport())
    .hasInstructionFailures("join",
      "Activities have incompatible types "
      + "(ParallelGatewayActivityBehavior is not compatible with InclusiveGatewayActivityBehavior)"
    );
  }
}
 
Example #2
Source File: CompetingSuspensionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures that suspending a process definition and its process instances will also increase the revision of the executions
 * such that concurrent updates fail with an OptimisticLockingException.
 */
@Deployment
public void testCompetingSuspension() {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("CompetingSuspensionProcess").singleResult();

  ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
  Execution execution = runtimeService
      .createExecutionQuery()
      .processInstanceId(processInstance.getId())
      .activityId("wait1")
      .singleResult();

  SuspendProcessDefinitionThread suspensionThread = new SuspendProcessDefinitionThread(processDefinition.getId());
  suspensionThread.startAndWaitUntilControlIsReturned();

  SignalThread signalExecutionThread = new SignalThread(execution.getId());
  signalExecutionThread.startAndWaitUntilControlIsReturned();

  suspensionThread.proceedAndWaitTillDone();
  assertNull(suspensionThread.exception);

  signalExecutionThread.proceedAndWaitTillDone();
  assertNotNull(signalExecutionThread.exception);
}
 
Example #3
Source File: MigrationPlanCreationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMigrateNullSourceActivityId() {
  ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
  ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

  try {
    runtimeService
      .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId())
      .mapActivities(null, "userTask")
      .build();
    fail("Should not succeed");
  } catch (MigrationPlanValidationException e) {
    assertThat(e.getValidationReport())
      .hasInstructionFailures(null, "Source activity id is null");
  }
}
 
Example #4
Source File: BatchModificationHistoryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistoricBatchJobLogIncidentDeletion() {
  // given
  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance);
  Batch batch = helper.startAfterAsync("process1", 3, "user1", processDefinition.getId());

  helper.completeSeedJobs(batch);
  helper.failExecutionJobs(batch, 3);

  rule.getManagementService().deleteBatch(batch.getId(), false);

  // when
  rule.getHistoryService().deleteHistoricBatch(batch.getId());

  // then the historic incident was deleted
  long historicIncidents = rule.getHistoryService().createHistoricIncidentQuery().count();
  assertEquals(0, historicIncidents);
}
 
Example #5
Source File: MigrationAddBoundaryEventsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddMessageBoundaryEventToUserTaskAndCorrelateMessage() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS)
    .activityBuilder("userTask")
      .boundaryEvent("boundary").message(MESSAGE_NAME)
      .userTask(AFTER_BOUNDARY_TASK)
      .endEvent()
    .done()
  );

  MigrationPlan migrationPlan = rule.getRuntimeService()
    .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapActivities("userTask", "userTask")
    .build();

  // when
  testHelper.createProcessInstanceAndMigrate(migrationPlan);

  // then it is possible to correlate the message and successfully complete the migrated instance
  testHelper.correlateMessage(MESSAGE_NAME);
  testHelper.completeTask(AFTER_BOUNDARY_TASK);
  testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
 
Example #6
Source File: ModificationExecutionAsyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchWithFailedModificationJobDeletionWithCascade() {
  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance);
  Batch batch = helper.startAfterAsync("process1", 2, "user1", processDefinition.getId());
  helper.completeSeedJobs(batch);

  // create incidents
  List<Job> modificationJobs = helper.getExecutionJobs(batch);
  for (Job modificationJob : modificationJobs) {
    rule.getManagementService().setJobRetries(modificationJob.getId(), 0);
  }

  // when
  rule.getManagementService().deleteBatch(batch.getId(), true);

  // then the no historic incidents exists
  long historicIncidents = rule.getHistoryService().createHistoricIncidentQuery().count();
  assertEquals(0, historicIncidents);
}
 
Example #7
Source File: MigrationIntermediateConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMigrateEventSubscription() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ONE_CONDITION_PROCESS);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ONE_CONDITION_PROCESS);

  MigrationPlan migrationPlan = rule.getRuntimeService()
    .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapActivities(CONDITION_ID, CONDITION_ID).updateEventTrigger()
    .build();

  //when
  ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan);

  testHelper.assertEventSubscriptionMigrated(CONDITION_ID, CONDITION_ID, null);

  //then it is possible to trigger the conditional event
  testHelper.setVariable(processInstance.getId(), VAR_NAME, "1");

  testHelper.completeTask(USER_TASK_ID);
  testHelper.assertProcessEnded(processInstance.getId());
}
 
Example #8
Source File: MigrationExternalTaskTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testChangeTaskConfiguration() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ExternalTaskModels.ONE_EXTERNAL_TASK_PROCESS);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(ExternalTaskModels.ONE_EXTERNAL_TASK_PROCESS)
      .serviceTaskBuilder("externalTask")
      .camundaTopic("new" + ExternalTaskModels.TOPIC)
      .camundaTaskPriority(Integer.toString(ExternalTaskModels.PRIORITY * 2))
      .done());

  MigrationPlan migrationPlan = rule.getRuntimeService()
    .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapActivities("externalTask", "externalTask")
    .build();

  ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then the task's topic and priority have not changed
  ExternalTask externalTaskAfterMigration = rule.getExternalTaskService().createExternalTaskQuery().singleResult();
  Assert.assertEquals(ExternalTaskModels.PRIORITY.longValue(), externalTaskAfterMigration.getPriority());
  Assert.assertEquals(ExternalTaskModels.TOPIC, externalTaskAfterMigration.getTopicName());

}
 
Example #9
Source File: MigrationCompensationRemoveSubProcessTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testCase2AssertExecutionTree() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.ONE_COMPENSATION_TASK_MODEL);

  MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
      .mapActivities("userTask2", "userTask2")
      .mapActivities("compensationBoundary", "compensationBoundary")
      .build();

  ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
  testHelper.completeTask("userTask1");

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then
  testHelper.assertExecutionTreeAfterMigration()
    .hasProcessDefinitionId(targetProcessDefinition.getId())
    .matches(
      describeExecutionTree("userTask2").scope().id(testHelper.snapshotBeforeMigration.getProcessInstanceId())
      .done());
}
 
Example #10
Source File: MultiTenancyProcessInstantiationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testFailToStartProcessInstanceAtActivityByIdAndTenantId() {
  deploymentForTenant(TENANT_ONE, PROCESS);

  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();

  try {
    runtimeService.createProcessInstanceById(processDefinition.getId())
      .processDefinitionTenantId(TENANT_ONE)
      .startBeforeActivity("userTask")
      .execute();

    fail("expected exception");
  } catch (BadUserRequestException e) {
    assertThat(e.getMessage(), containsString("Cannot specify a tenant-id"));
  }
}
 
Example #11
Source File: MultiTenancyProcessDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCascadeProcessDefinitionDisabledTenantCheck() {
  //given deployment with a process definition and process instances
  BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("process").startEvent().userTask().endEvent().done();
  testRule.deployForTenant(TENANT_ONE, bpmnModel);
  //tenant check disabled
  processEngineConfiguration.setTenantCheckEnabled(false);
  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
  ProcessDefinition processDefinition = processDefinitionQuery.processDefinitionKey("process").singleResult();
  engineRule.getRuntimeService().createProcessInstanceByKey("process").executeWithVariablesInReturn();
  //user with no authentication
  identityService.setAuthentication("user", null, null);

  //when the corresponding process definition is cascading deleted from the deployment
  repositoryService.deleteProcessDefinition(processDefinition.getId(), true);

  //then exist no process instance and one definition, because test case deployes per default one definition
  identityService.clearAuthentication();
  assertEquals(0, engineRule.getRuntimeService().createProcessInstanceQuery().count());
  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_ACTIVITY.getId()) {
    assertEquals(0, engineRule.getHistoryService().createHistoricActivityInstanceQuery().count());
  }
  assertThat(repositoryService.createProcessDefinitionQuery().count(), is(1L));
  assertThat(repositoryService.createProcessDefinitionQuery().tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example #12
Source File: ActivityStatisticsQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testActivityStatisticsQueryWithIntermediateTimer.bpmn20.xml")
public void testActivityStatisticsQueryWithIntermediateTimer() {
  runtimeService.startProcessInstanceByKey("ExampleProcess");
  ProcessDefinition definition = repositoryService.createProcessDefinitionQuery()
      .processDefinitionKey("ExampleProcess").singleResult();

  List<ActivityStatistics> statistics =
      managementService
      .createActivityStatisticsQuery(definition.getId())
      .includeFailedJobs()
      .includeIncidents()
      .list();

  Assert.assertEquals(1, statistics.size());

  ActivityStatistics activityResult = statistics.get(0);
  Assert.assertEquals(1, activityResult.getInstances());
  Assert.assertEquals("theTimer", activityResult.getId());
  Assert.assertEquals(0, activityResult.getFailedJobs());
  assertTrue(activityResult.getIncidentStatistics().isEmpty());
}
 
Example #13
Source File: MigrationEventBasedGatewayTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMigrateGatewayWithMessageEvent() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS);

  MigrationPlan migrationPlan = rule.getRuntimeService()
    .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapActivities("eventBasedGateway", "eventBasedGateway")
    .build();

  // when
  ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan);

  // then
  testHelper.assertEventSubscriptionRemoved("messageCatch", EventBasedGatewayModels.MESSAGE_NAME);
  testHelper.assertEventSubscriptionCreated("messageCatch", EventBasedGatewayModels.MESSAGE_NAME);

  rule.getRuntimeService().correlateMessage(EventBasedGatewayModels.MESSAGE_NAME);

  testHelper.completeTask("afterMessageCatch");
  testHelper.assertProcessEnded(processInstance.getId());
}
 
Example #14
Source File: MigrationEventBasedGatewayTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMigrateGatewayWithSignalEvent() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.SIGNAL_EVENT_BASED_GW_PROCESS);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.SIGNAL_EVENT_BASED_GW_PROCESS);

  MigrationPlan migrationPlan = rule.getRuntimeService()
    .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapActivities("eventBasedGateway", "eventBasedGateway")
    .build();

  // when
  ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan);

  // then
  testHelper.assertEventSubscriptionRemoved("signalCatch", EventBasedGatewayModels.SIGNAL_NAME);
  testHelper.assertEventSubscriptionCreated("signalCatch", EventBasedGatewayModels.SIGNAL_NAME);

  rule.getRuntimeService().signalEventReceived(EventBasedGatewayModels.SIGNAL_NAME);

  testHelper.completeTask("afterSignalCatch");
  testHelper.assertProcessEnded(processInstance.getId());
}
 
Example #15
Source File: MigrationCompensationAddSubProcessTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Ignore("CAM-6035")
@Test
public void testNoInputMappingExecuted() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.ONE_COMPENSATION_TASK_MODEL);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL)
    .activityBuilder("subProcess")
      .camundaInputParameter("foo", "bar")
    .done());

  MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
      .mapActivities("userTask2", "userTask2")
      .mapActivities("compensationBoundary", "compensationBoundary")
      .build();

  ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
  testHelper.completeTask("userTask1");

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then
  Assert.assertEquals(0, testHelper.snapshotAfterMigration.getVariables().size());
}
 
Example #16
Source File: ModificationExecutionSyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testCancelWithoutFlag() {
  // given
  this.instance = Bpmn.createExecutableProcess("process1")
      .startEvent("start")
      .serviceTask("ser").camundaExpression("${true}")
      .userTask("user")
      .endEvent("end")
      .done();

  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance);

  List<String> processInstanceIds = helper.startInstances("process1", 1);

  // when
  runtimeService.createModification(processDefinition.getId())
    .startBeforeActivity("ser")
    .cancelAllForActivity("user")
    .processInstanceIds(processInstanceIds)
    .execute();

  // then
  assertEquals(0, runtimeService.createExecutionQuery().list().size());
}
 
Example #17
Source File: MigrationNestedEventSubProcessTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapUserTaskSiblingOfEventSubProcessAndTriggerEvent() {
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(configuration.getSourceProcess());
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(configuration.getSourceProcess());

  MigrationPlan migrationPlan = rule.getRuntimeService()
    .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapActivities(USER_TASK_ID, USER_TASK_ID)
    .build();

  // when
  testHelper.createProcessInstanceAndMigrate(migrationPlan);

  // then it is possible to trigger event sub process and successfully complete the migrated instance
  configuration.triggerEventSubProcess(testHelper);
  testHelper.completeTask(EVENT_SUB_PROCESS_TASK_ID);
  testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
 
Example #18
Source File: SingleProcessInstanceModificationAsyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = PARALLEL_GATEWAY_PROCESS)
public void testTheDeploymentIdIsSet() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallelGateway");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();

  ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());

  Batch modificationBatch = runtimeService
      .createProcessInstanceModification(processInstance.getId())
      .cancelActivityInstance(getInstanceIdForActivity(tree, "task1"))
      .executeAsync();
  assertNotNull(modificationBatch);
  Job job = managementService.createJobQuery().jobDefinitionId(modificationBatch.getSeedJobDefinitionId()).singleResult();
  // seed job
  managementService.executeJob(job.getId());

  for (Job pending : managementService.createJobQuery().jobDefinitionId(modificationBatch.getBatchJobDefinitionId()).list()) {
    managementService.executeJob(pending.getId());
    assertEquals(processDefinition.getDeploymentId(), pending.getDeploymentId());
  }
}
 
Example #19
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseProcessDefinitionWithoutTtlWithConfigDefault() {
  processEngineConfiguration.setHistoryTimeToLive("6");
  try {
    String resource = TestHelper.getBpmnProcessDefinitionResource(getClass(), "testParseProcessDefinitionWithoutTtl");
    repositoryService.createDeployment().name(resource).addClasspathResource(resource).deploy();
    List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();
    assertNotNull(processDefinitions);
    assertEquals(1, processDefinitions.size());

    Integer timeToLive = processDefinitions.get(0).getHistoryTimeToLive();
    assertNotNull(timeToLive);
    assertEquals(6, timeToLive.intValue());
  } finally {
    processEngineConfiguration.setHistoryTimeToLive(null);
    repositoryService.deleteDeployment(repositoryService.createDeploymentQuery().singleResult().getId(), true);
  }
}
 
Example #20
Source File: ModificationExecutionSyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartTransition() {
  DeploymentWithDefinitions deployment = testRule.deploy(instance);
  ProcessDefinition definition = deployment.getDeployedProcessDefinitions().get(0);

  List<String> processInstanceIds = helper.startInstances("process1", 2);

  runtimeService.createModification(definition.getId()).startTransition("seq").processInstanceIds(processInstanceIds).execute();

  for (String processInstanceId : processInstanceIds) {
    ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId);
    assertNotNull(updatedTree);
    assertEquals(processInstanceId, updatedTree.getProcessInstanceId());

    assertThat(updatedTree).hasStructure(describeActivityInstanceTree(definition.getId()).activity("user1").activity("user2").done());
  }
}
 
Example #21
Source File: RestartProcessInstanceSyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRetainTenantIdOfSharedProcessDefinition() {
  // given
  engineRule.getProcessEngineConfiguration()
    .setTenantIdProvider(new TestTenantIdProvider());

  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
  ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
  assertEquals(processInstance.getTenantId(), TestTenantIdProvider.TENANT_ID);
  runtimeService.deleteProcessInstance(processInstance.getId(), "test");

  // when
  runtimeService.restartProcessInstances(processDefinition.getId())
      .startBeforeActivity(ProcessModels.USER_TASK_ID)
      .processInstanceIds(processInstance.getId())
      .execute();

  // then
  ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active()
      .processDefinitionId(processDefinition.getId()).singleResult();

  assertNotNull(restartedInstance);
  assertEquals(restartedInstance.getTenantId(), TestTenantIdProvider.TENANT_ID);
}
 
Example #22
Source File: RestartProcessInstanceAsyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void createBatchRestart() {
  // given
  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS);
  ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process");
  ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process");

  runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
  runtimeService.deleteProcessInstance(processInstance2.getId(), "test");

  List<String> processInstanceIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());

  // when
  Batch batch = runtimeService.restartProcessInstances(processDefinition.getId())
      .startAfterActivity("userTask2")
      .processInstanceIds(processInstanceIds)
      .executeAsync();

  // then
  assertBatchCreated(batch, 2);
}
 
Example #23
Source File: PathCoverageExecutionListener.java    From camunda-bpm-process-test-coverage with Apache License 2.0 6 votes vote down vote up
@Override
public void notify(DelegateExecution execution) throws Exception {

    if (coverageTestRunState == null) {
        logger.warning("Coverage execution listener in use but no coverage run state assigned!");
        return;
    }

    final RepositoryService repositoryService = execution.getProcessEngineServices().getRepositoryService();

    // Get the process definition in order to obtain the key
    final ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(
            execution.getProcessDefinitionId()).singleResult();

    final String transitionId = execution.getCurrentTransitionId();

    // Record sequence flow coverage
    final CoveredSequenceFlow coveredSequenceFlow = new CoveredSequenceFlow(processDefinition.getKey(),
            transitionId);
    coverageTestRunState.addCoveredElement(coveredSequenceFlow);

    // Record possible event coverage
    handleEvent(transitionId, processDefinition, repositoryService);

}
 
Example #24
Source File: MigrationSignalCatchEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMigrateEventSubscriptionChangeActivityId() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(SignalCatchModels.ONE_SIGNAL_CATCH_PROCESS);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(SignalCatchModels.ONE_SIGNAL_CATCH_PROCESS)
      .changeElementId("signalCatch", "newSignalCatch"));

  MigrationPlan migrationPlan = rule.getRuntimeService()
    .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapActivities("signalCatch", "newSignalCatch")
    .build();

  // when
  ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan);

  // then
  testHelper.assertEventSubscriptionMigrated("signalCatch", "newSignalCatch", SignalCatchModels.SIGNAL_NAME);

  // and it is possible to trigger the event
  rule.getRuntimeService().signalEventReceived(SignalCatchModels.SIGNAL_NAME);

  testHelper.completeTask("userTask");
  testHelper.assertProcessEnded(processInstance.getId());
}
 
Example #25
Source File: BatchModificationHistoryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistoricMonitorJobLogForBatchDeletion() {
  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance);
  Batch batch = helper.startAfterAsync("process1", 1, "user1", processDefinition.getId());
  helper.completeSeedJobs(batch);

  // when
  Date deletionDate = helper.addSecondsToClock(12);
  rule.getManagementService().deleteBatch(batch.getId(), false);

  // then a deletion historic job log was added
  HistoricJobLog jobLog = helper.getHistoricMonitorJobLog(batch).get(1);
  assertNotNull(jobLog);
  assertTrue(jobLog.isDeletionLog());
  assertEquals(deletionDate, jobLog.getTimestamp());
}
 
Example #26
Source File: ProcessDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleProcessInstantiation_ByKeyAndTenantId() {
  ProcessDefinition mockDefinition = MockProvider.mockDefinition().tenantId(MockProvider.EXAMPLE_TENANT_ID).build();
  setUpRuntimeDataForDefinition(mockDefinition);

  given()
    .pathParam("key", MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY)
    .pathParam("tenant-id", MockProvider.EXAMPLE_TENANT_ID)
    .contentType(POST_JSON_CONTENT_TYPE).body(EMPTY_JSON_OBJECT)
  .then().expect()
    .statusCode(Status.OK.getStatusCode())
    .body("id", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID))
  .when().post(START_PROCESS_INSTANCE_BY_KEY_AND_TENANT_ID_URL);

  verify(processDefinitionQueryMock).tenantIdIn(MockProvider.EXAMPLE_TENANT_ID);
}
 
Example #27
Source File: LegacyUserOperationLogTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDontWriteDuplicateLogOnBatchDeletionJobExecution() {
  ProcessDefinition definition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
  ProcessInstance processInstance = runtimeService.startProcessInstanceById(definition.getId());
  batch = runtimeService.deleteProcessInstancesAsync(
      Arrays.asList(processInstance.getId()), null, "test reason");

  Job seedJob = managementService
      .createJobQuery()
      .singleResult();
  managementService.executeJob(seedJob.getId());

  for (Job pending : managementService.createJobQuery().list()) {
    managementService.executeJob(pending.getId());
  }

  assertEquals(5, userOperationLogQuery().entityTypeIn(EntityTypes.PROCESS_INSTANCE, EntityTypes.DEPLOYMENT).count());
}
 
Example #28
Source File: RestartProcessInstanceAsyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRestartProcessInstanceWithTenant() {
  // given
  ProcessDefinition processDefinition = testRule.deployForTenantAndGetDefinition("tenantId", ProcessModels.TWO_TASKS_PROCESS);
  ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process");
  ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process");


  runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
  runtimeService.deleteProcessInstance(processInstance2.getId(), "test");

  // when
  Batch batch = runtimeService.restartProcessInstances(processDefinition.getId())
  .startBeforeActivity("userTask1")
  .processInstanceIds(processInstance1.getId(), processInstance2.getId())
  .executeAsync();

  helper.completeBatch(batch);
  // then
  List<ProcessInstance> restartedProcessInstances = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().list();
  assertNotNull(restartedProcessInstances.get(0).getTenantId());
  assertNotNull(restartedProcessInstances.get(1).getTenantId());
  assertEquals("tenantId", restartedProcessInstances.get(0).getTenantId());
  assertEquals("tenantId", restartedProcessInstances.get(1).getTenantId());
}
 
Example #29
Source File: MigrationHistoricActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoricActivityInstanceAddScope() {
  //given
  ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
  ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.SUBPROCESS_PROCESS);

  MigrationPlan migrationPlan = rule.getRuntimeService()
      .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId())
      .mapActivities("userTask", "userTask")
      .build();

  ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId());

  // when
  rule.getRuntimeService().newMigration(migrationPlan)
    .processInstanceIds(Arrays.asList(processInstance.getId()))
    .execute();

  // then
  List<HistoricActivityInstance> historicInstances = historyService
      .createHistoricActivityInstanceQuery()
      .processInstanceId(processInstance.getId())
      .unfinished()
      .orderByActivityId()
      .asc()
      .list();

  Assert.assertEquals(2, historicInstances.size());

  assertMigratedTo(historicInstances.get(0), targetDefinition, "subProcess");
  assertMigratedTo(historicInstances.get(1), targetDefinition, "userTask");
  assertEquals(processInstance.getId(), historicInstances.get(0).getParentActivityInstanceId());
  assertEquals(historicInstances.get(0).getId(), historicInstances.get(1).getParentActivityInstanceId());
}
 
Example #30
Source File: MultiTenancyProcessDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void getProcessDefinitionWithAuthenticatedTenant() {
  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  ProcessDefinition definition = repositoryService.getProcessDefinition(processDefinitionId);

  assertThat(definition.getTenantId(), is(TENANT_ONE));
}