org.camunda.bpm.model.bpmn.BpmnModelInstance Java Examples

The following examples show how to use org.camunda.bpm.model.bpmn.BpmnModelInstance. 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: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInStartListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .userTask(TASK_WITH_CONDITION_ID)
    .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_START, specifier.getDelegateClass().getName())
    .name(TASK_WITH_CONDITION)
    .endEvent()
    .done();
  deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), false);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());

  //when task is completed
  taskService.complete(taskQuery.singleResult().getId());

  //then start listener sets variable
  //non interrupting boundary event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(1 + specifier.getExpectedNonInterruptingCount(), tasksAfterVariableIsSet.size());
  assertEquals(specifier.getExpectedNonInterruptingCount(), taskQuery.taskName(TASK_AFTER_CONDITION).count());
}
 
Example #2
Source File: GetRunningHistoricProcessInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void startedAfterAndStartedAtParameterWorks() {
   // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent()
    .userTask()
    .endEvent()
    .done();
  testHelper.deploy(simpleDefinition);
  Date now = new Date();
  ClockUtil.setCurrentTime(now);
  ProcessInstance processInstance =
    runtimeService.startProcessInstanceByKey("process");
  Date nowPlus2Seconds = new Date(now.getTime() + 2000L);
  ClockUtil.setCurrentTime(nowPlus2Seconds);
  runtimeService.startProcessInstanceByKey("process");

  // when
  List<HistoricProcessInstance> runningHistoricProcessInstances =
    optimizeService.getRunningHistoricProcessInstances(now, now, 10);

  // then
  assertThat(runningHistoricProcessInstances.size(), is(0));
}
 
Example #3
Source File: MultiTenancyCallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testStartCaseInstanceWithDeploymentBinding() {

    BpmnModelInstance callingProcess = Bpmn.createExecutableProcess("callingProcess")
      .startEvent()
      .callActivity()
        .camundaCaseRef("Case_1")
        .camundaCaseBinding("deployment")
      .endEvent()
      .done();

    deploymentForTenant(TENANT_ONE, CMMN, callingProcess);
    deploymentForTenant(TENANT_TWO, CMMN, callingProcess);

    runtimeService.createProcessInstanceByKey("callingProcess").processDefinitionTenantId(TENANT_ONE).execute();
    runtimeService.createProcessInstanceByKey("callingProcess").processDefinitionTenantId(TENANT_TWO).execute();

    CaseInstanceQuery query = caseService.createCaseInstanceQuery().caseDefinitionKey("Case_1");
    assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
    assertThat(query.tenantIdIn(TENANT_TWO).count(), is(1L));
  }
 
Example #4
Source File: BpmnDeploymentTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testDeployAndGetProcessDefinition() throws Exception {

    // given process model
    final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("foo").startEvent().userTask().endEvent().done();

    // when process model is deployed
    DeploymentWithDefinitions deployment = repositoryService.createDeployment()
      .addModelInstance("foo.bpmn", modelInstance).deployWithResult();
    deploymentIds.add(deployment.getId());

    // then deployment contains deployed process definitions
    List<ProcessDefinition> deployedProcessDefinitions = deployment.getDeployedProcessDefinitions();
    assertEquals(1, deployedProcessDefinitions.size());
    assertNull(deployment.getDeployedCaseDefinitions());
    assertNull(deployment.getDeployedDecisionDefinitions());
    assertNull(deployment.getDeployedDecisionRequirementsDefinitions());

    // and persisted process definition is equal to deployed process definition
    ProcessDefinition persistedProcDef = repositoryService.createProcessDefinitionQuery()
                                                          .processDefinitionResourceName("foo.bpmn")
                                                          .singleResult();
    assertEquals(persistedProcDef.getId(), deployedProcessDefinitions.get(0).getId());
  }
 
Example #5
Source File: MultiTenancyHistoricVariableInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  runtimeService = engineRule.getRuntimeService();
  historyService = engineRule.getHistoryService();
  taskService = engineRule.getTaskService();
  identityService = engineRule.getIdentityService();

  BpmnModelInstance oneTaskProcess = Bpmn.createExecutableProcess("testProcess")
    .startEvent()
    .endEvent()
  .done();

  // given
  testRule.deployForTenant(TENANT_NULL, oneTaskProcess);
  testRule.deployForTenant(TENANT_ONE, oneTaskProcess);
  testRule.deployForTenant(TENANT_TWO, oneTaskProcess);

  startProcessInstanceForTenant(TENANT_NULL, TENANT_NULL_VAR);
  startProcessInstanceForTenant(TENANT_ONE, TENANT_ONE_VAR);
  startProcessInstanceForTenant(TENANT_TWO, TENANT_TWO_VAR);
}
 
Example #6
Source File: GetCompletedHistoricActivityInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void fishedAtParameterWorks() {
   // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent("startEvent")
    .userTask("userTask")
    .endEvent("endEvent")
    .done();
  testHelper.deploy(simpleDefinition);
  Date now = new Date();
  Date nowPlus2Seconds = new Date(now.getTime() + 2000L);
  ClockUtil.setCurrentTime(now);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");

  // when
  ClockUtil.setCurrentTime(nowPlus2Seconds);
  completeAllUserTasks();
  List<HistoricActivityInstance> completedHistoricActivityInstances =
    optimizeService.getCompletedHistoricActivityInstances(null, now, 10);

  // then
  assertThat(completedHistoricActivityInstances.size(), is(1));
  assertThat(completedHistoricActivityInstances.get(0).getActivityId(), is("startEvent"));
}
 
Example #7
Source File: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/subProcessWithVersionTag.bpmn20.xml" })
public void testCallProcessByVersionTagTwoSubprocesses() {
  // given
  BpmnModelInstance modelInstance = getModelWithCallActivityVersionTagBinding("ver_tag_1");

  deployment(modelInstance);
  deployment("org/camunda/bpm/engine/test/bpmn/callactivity/subProcessWithVersionTag.bpmn20.xml");

  try {
    // when
    runtimeService.startProcessInstanceByKey("process");
    fail("expected exception");
  } catch (ProcessEngineException e) {
    // then
    assertTrue(e.getMessage().contains("There are '2' results for a process definition with key 'subProcess', versionTag 'ver_tag_1' and tenant-id '{}'."));
  }

  // clean up
  cleanupDeployments();
}
 
Example #8
Source File: MultiEngineCommandContextTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldOpenNewCommandContextWhenInteractingAccrossEngines() {

  BpmnModelInstance process1 = Bpmn.createExecutableProcess("process1")
      .startEvent()
      .serviceTask()
        .camundaInputParameter("engineName", "engine2")
        .camundaInputParameter("processKey", "process2")
        .camundaClass(StartProcessInstanceOnEngineDelegate.class.getName())
      .endEvent()
      .done();

  BpmnModelInstance process2 = Bpmn.createExecutableProcess("process2")
      .startEvent()
      .endEvent()
      .done();

  // given
  engine1.getRepositoryService().createDeployment().addModelInstance("process1.bpmn", process1).deploy();
  engine2.getRepositoryService().createDeployment().addModelInstance("process2.bpmn", process2).deploy();

  // if
  engine1.getRuntimeService().startProcessInstanceByKey("process1");
}
 
Example #9
Source File: ProcessInstanceModificationInTransactionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldBeAbleToPerformModification() {

  // given
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("TestProcess")
    .startEvent()
    .intermediateCatchEvent("TimerEvent")
      .timerWithDate("${calculateTimerDate.execute(execution)}")
      .camundaExecutionListenerDelegateExpression("end", "${deleteVariableListener}")
    .endEvent()
    .done();

  deployModelInstance(modelInstance);
  final ProcessInstance procInst = runtimeService.startProcessInstanceByKey("TestProcess");

  // when
  userBean.completeUserTaskAndModifyInstanceInOneTransaction(procInst);

  // then
  VariableInstance variable = rule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(procInst.getId()).variableName("createDate").singleResult();
  assertNotNull(variable);
  HistoricVariableInstance historicVariable = rule.getHistoryService().createHistoricVariableInstanceQuery().singleResult();
  assertEquals(variable.getName(), historicVariable.getName());
  assertEquals(HistoricVariableInstance.STATE_CREATED, historicVariable.getState());
}
 
Example #10
Source File: GetCompletedHistoricActivityInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void fishedAfterParameterWorks() {
   // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent()
    .userTask("userTask")
    .endEvent("endEvent")
    .done();
  testHelper.deploy(simpleDefinition);
  Date now = new Date();
  Date nowPlus2Seconds = new Date(now.getTime() + 2000L);
  ClockUtil.setCurrentTime(now);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");

  // when
  ClockUtil.setCurrentTime(nowPlus2Seconds);
  completeAllUserTasks();
  List<HistoricActivityInstance> completedHistoricActivityInstances =
    optimizeService.getCompletedHistoricActivityInstances(now, null, 10);

  // then
  Set<String> allowedActivityIds = new HashSet<>(Arrays.asList("userTask", "endEvent"));
  assertThat(completedHistoricActivityInstances.size(), is(2));
  assertTrue(allowedActivityIds.contains(completedHistoricActivityInstances.get(0).getActivityId()));
  assertTrue(allowedActivityIds.contains(completedHistoricActivityInstances.get(1).getActivityId()));
}
 
Example #11
Source File: SetBusinessKeyTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateKeyInEndTaskListener() {
  // given
  String listener = TaskListener.EVENTNAME_COMPLETE;
  BpmnModelInstance process = createModelTaskListener(listener);
  testRule.deploy(process);

  String newBusinessKeyValue = "newBusinessKey";
  runtimeService.startProcessInstanceByKey(PROCESS_KEY, "aBusinessKey", Variables.createVariables().putValue(BUSINESS_KEY_VARIABLE, newBusinessKeyValue));

  // when
  completeTask("userTask1");

  // assume
  assertNotNull(taskService.createTaskQuery().taskDefinitionKey("userTask2").singleResult());

  // then
  checkBusinessKeyChanged(newBusinessKeyValue);
}
 
Example #12
Source File: GetRunningHistoricTaskInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void startedAtParameterWorks() {
  // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent()
    .userTask()
    .endEvent()
    .done();
  testHelper.deploy(simpleDefinition);
  Date now = new Date();
  ClockUtil.setCurrentTime(now);
  ProcessInstance processInstance1 = engineRule.getRuntimeService().startProcessInstanceByKey("process");

  Date nowPlus2Seconds = new Date(now.getTime() + 2000L);
  ClockUtil.setCurrentTime(nowPlus2Seconds);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");

  // when
  List<HistoricTaskInstance> runningHistoricTaskInstances =                                               
    optimizeService.getRunningHistoricTaskInstances(null, now, 10);

  // then
  assertThat(runningHistoricTaskInstances.size(), is(1));
  assertThat(runningHistoricTaskInstances.get(0).getProcessInstanceId(), is(processInstance1.getId()));
}
 
Example #13
Source File: HistoryByteArrayTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistoricExceptionStacktraceBinary() {
  // given
  BpmnModelInstance instance = createFailingProcess();
  testRule.deploy(instance);
  runtimeService.startProcessInstanceByKey("Process");
  String jobId = managementService.createJobQuery().singleResult().getId();

  // when
  try {
    managementService.executeJob(jobId);
    fail();
  } catch (Exception e) {
    // expected
  }

  HistoricJobLogEventEntity entity = (HistoricJobLogEventEntity) historyService
      .createHistoricJobLogQuery()
      .failureLog()
      .singleResult();
  assertNotNull(entity);

  ByteArrayEntity byteArrayEntity = configuration.getCommandExecutorTxRequired().execute(new GetByteArrayCommand(entity.getExceptionByteArrayId()));

  checkBinary(byteArrayEntity);
}
 
Example #14
Source File: SetBusinessKeyTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testNewKeyInAssignTaskListener() {
  // given
  String listener = TaskListener.EVENTNAME_ASSIGNMENT;
  BpmnModelInstance process = createModelTaskListener(listener);
  testRule.deploy(process);

  String newBusinessKeyValue = "newBusinessKey";
  runtimeService.startProcessInstanceByKey(PROCESS_KEY, Variables.createVariables().putValue(BUSINESS_KEY_VARIABLE, newBusinessKeyValue));

  // when
  taskService.setAssignee(taskService.createTaskQuery().singleResult().getId(), "newUserId");

  // then
  checkBusinessKeyChanged(newBusinessKeyValue);
}
 
Example #15
Source File: TaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryWithCandidateUsers() {
  BpmnModelInstance process = Bpmn.createExecutableProcess("process")
    .startEvent()
    .userTask()
      .camundaCandidateUsers("anna")
    .endEvent()
    .done();

  deployment(process);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

  List<Task> tasks = taskService.createTaskQuery()
      .processInstanceId(processInstance.getId())
      .withCandidateUsers()
      .list();
  assertEquals(1, tasks.size());
}
 
Example #16
Source File: MultiTenancyCallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testFailStartProcessInstanceFromOtherTenantWithLatestBinding() {

    BpmnModelInstance callingProcess = Bpmn.createExecutableProcess("callingProcess")
      .startEvent()
      .callActivity()
        .calledElement("subProcess")
        .camundaCalledElementBinding("latest")
      .endEvent()
      .done();

    deploymentForTenant(TENANT_ONE, callingProcess);
    deploymentForTenant(TENANT_TWO, SUB_PROCESS);

    try {
      runtimeService.createProcessInstanceByKey("callingProcess")
        .processDefinitionTenantId(TENANT_ONE)
        .execute();

      fail("expected exception");
    } catch (ProcessEngineException e) {
      assertThat(e.getMessage(), containsString("no processes deployed with key 'subProcess'"));
    }
  }
 
Example #17
Source File: PurgeDatabaseTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testPurgeWithExistingProcessInstance() {
  //given process with variable and staying process instance in second user task
  BpmnModelInstance test = Bpmn.createExecutableProcess(PROCESS_DEF_KEY)
                               .startEvent()
                               .userTask()
                               .userTask()
                               .endEvent()
                               .done();
  engineRule.getRepositoryService().createDeployment().addModelInstance(PROCESS_MODEL_NAME, test).deploy();

  VariableMap variables = Variables.createVariables();
  variables.put("key", "value");
  engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEF_KEY, variables);
  Task task = engineRule.getTaskService().createTaskQuery().singleResult();
  engineRule.getTaskService().complete(task.getId());

  // when purge is executed
  ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
  managementService.purge();

  // then no more data exist
  assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
}
 
Example #18
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInSeqMultiInstance() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                              .startEvent()
                                              .userTask(TASK_BEFORE_CONDITION_ID)
                                              .name(TASK_BEFORE_CONDITION)
                                              .userTask(TASK_WITH_CONDITION_ID)
                                              .multiInstance()
                                              .cardinality("3")
                                              .sequential()
                                              .done();
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_ID, "${true}", false);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then multi instance is created
  //and boundary event is triggered for each multi instance creation and also from the default evaluation behavior
  //since the condition is true. That means one time from the default behavior and 4 times for the variables which are set:
  //nrOfInstances, nrOfCompletedInstances, nrOfActiveInstances, loopCounter
  for (int i = 0; i < 3; i++) {
    Task multiInstanceTask = taskQuery.taskDefinitionKey(TASK_WITH_CONDITION_ID).singleResult();
    assertNotNull(multiInstanceTask);
    assertEquals(i == 0 ? 5 : 5 + i * 2, taskService.createTaskQuery().taskName(TASK_AFTER_CONDITION).count());
    taskService.complete(multiInstanceTask.getId());
  }

  //then non boundary events are triggered 9 times
  tasksAfterVariableIsSet = taskService.createTaskQuery().list();
  assertEquals(9, tasksAfterVariableIsSet.size());
  assertEquals(0, conditionEventSubscriptionQuery.list().size());
}
 
Example #19
Source File: CallActivityModels.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static BpmnModelInstance oneBpmnCallActivityProcessAsExpressionAsync(int processNumber){
  return ProcessModels.newModel(processNumber)
      .startEvent()
        .camundaAsyncBefore(true)
      .callActivity()
        .calledElement("${NextProcess}")
        .camundaIn("NextProcess", "NextProcess")
      .endEvent()
      .done();
}
 
Example #20
Source File: MigrationPlanGenerationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapEqualActivitiesToSubProcessScope() {
  BpmnModelInstance sourceProcess = ProcessModels.ONE_TASK_PROCESS;
  BpmnModelInstance targetProcess = ProcessModels.SUBPROCESS_PROCESS;

  assertGeneratedMigrationPlan(sourceProcess, targetProcess)
    .hasEmptyInstructions();
}
 
Example #21
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableOnParentScopeInStartListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .subProcess()
    .embeddedSubProcess()
      .startEvent()
      .userTask(TASK_BEFORE_CONDITION_ID)
        .name(TASK_BEFORE_CONDITION)
      .userTask(TASK_WITH_CONDITION_ID)
        .name(TASK_WITH_CONDITION)
        .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_START, EXPR_SET_VARIABLE_ON_PARENT)
      .endEvent()
    .subProcessDone()
    .endEvent(END_EVENT_ID)
    .done();
  modelInstance = specifier.specifyConditionalProcess(modelInstance, false);
  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then start listener sets variable
  //non interrupting boundary event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  specifier.assertTaskNames(tasksAfterVariableIsSet, false, false);
}
 
Example #22
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInInputMappingOfSubProcess() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask().name(TASK_BEFORE_CONDITION)
                                                .subProcess(SUB_PROCESS_ID)
                                                  .camundaInputParameter(VARIABLE_NAME, "1")
                                                  .embeddedSubProcess()
                                                  .startEvent()
                                                  .userTask().name(TASK_IN_SUB_PROCESS_ID)
                                                  .endEvent()
                                                .subProcessDone()
                                                .endEvent()
                                                .done();
  deployConditionalBoundaryEventProcess(modelInstance, SUB_PROCESS_ID, true);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  // Then input mapping from sub process sets variable,
  // interrupting conditional event is triggered by default evaluation behavior
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITION, tasksAfterVariableIsSet.get(0).getName());
  assertEquals(0, conditionEventSubscriptionQuery.list().size());
}
 
Example #23
Source File: MigrationEventSubProcessTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testMigrateNonInterruptingEventSubprocessMessageTrigger() {
  BpmnModelInstance nonInterruptingModel = modify(EventSubProcessModels.MESSAGE_EVENT_SUBPROCESS_PROCESS)
    .startEventBuilder(EVENT_SUB_PROCESS_START_ID)
    .interrupting(false)
    .done();

  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(nonInterruptingModel);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(nonInterruptingModel);

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

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

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

  // then
  testHelper.assertEventSubscriptionMigrated(EVENT_SUB_PROCESS_START_ID, EVENT_SUB_PROCESS_START_ID, EventSubProcessModels.MESSAGE_NAME);

  // and it is possible to trigger the event subprocess
  rule.getRuntimeService().correlateMessage(EventSubProcessModels.MESSAGE_NAME);
  Assert.assertEquals(2, rule.getTaskService().createTaskQuery().count());

  // and complete the process instance
  testHelper.completeTask(EVENT_SUB_PROCESS_TASK_ID);
  testHelper.completeTask(USER_TASK_ID);
  testHelper.assertProcessEnded(processInstance.getId());
}
 
Example #24
Source File: GetRunningHistoricActivityInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void fetchOnlyRunningActivities() {
  // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent("startEvent")
    .userTask("userTask")
    .endEvent()
    .done();
  testHelper.deploy(simpleDefinition);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");

  // when
  List<HistoricActivityInstance> runningHistoricActivityInstances =
    optimizeService.getRunningHistoricActivityInstances(pastDate(), null, 10);

  // then
  assertThat(runningHistoricActivityInstances.size(), is(1));
  assertThat(runningHistoricActivityInstances.get(0).getActivityId(), is("userTask"));

  // when
  completeAllUserTasks();
  runningHistoricActivityInstances =
    optimizeService.getRunningHistoricActivityInstances(pastDate(), null, 10);

  // then
  assertThat(runningHistoricActivityInstances.size(), is(0));
}
 
Example #25
Source File: HistoricProcessInstanceStateTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompletionWithSuspension() {
  BpmnModelInstance instance = Bpmn.createExecutableProcess(PROCESS_ID)
      .startEvent()
      .userTask()
      .endEvent()
      .done();
  ProcessDefinition processDefinition = processEngineTestRule.deployAndGetDefinition(instance);
  ProcessInstance processInstance = processEngineRule.getRuntimeService()
      .startProcessInstanceById(processDefinition.getId());
  HistoricProcessInstance entity = getHistoricProcessInstanceWithAssertion(processDefinition);
  assertThat(entity.getState(), is(HistoricProcessInstance.STATE_ACTIVE));

  //suspend
  processEngineRule.getRuntimeService().updateProcessInstanceSuspensionState()
      .byProcessInstanceId(processInstance.getId()).suspend();

  entity = getHistoricProcessInstanceWithAssertion(processDefinition);
  assertThat(entity.getState(), is(HistoricProcessInstance.STATE_SUSPENDED));

  //activate
  processEngineRule.getRuntimeService().updateProcessInstanceSuspensionState()
      .byProcessInstanceId(processInstance.getId()).activate();

  entity = getHistoricProcessInstanceWithAssertion(processDefinition);
  assertThat(entity.getState(), is(HistoricProcessInstance.STATE_ACTIVE));

  //complete task
  processEngineRule.getTaskService().complete(
      processEngineRule.getTaskService().createTaskQuery().active().singleResult().getId());

  //make sure happy path ended
  entity = getHistoricProcessInstanceWithAssertion(processDefinition);
  assertThat(entity.getState(), is(HistoricProcessInstance.STATE_COMPLETED));
}
 
Example #26
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInOutputMappingOfCallActivity() {
  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, DELEGATED_PROCESS).deploy());

  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                .callActivity(TASK_WITH_CONDITION_ID)
                                                  .calledElement(DELEGATED_PROCESS_KEY)
                                                  .camundaOutputParameter(VARIABLE_NAME, "1")
                                                .userTask().name(TASK_AFTER_OUTPUT_MAPPING)
                                                .endEvent()
                                                .done();
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_ID, false);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

  //when task before service task is completed
  taskService.complete(task.getId());

  //then out mapping of call activity sets a variable
  //-> non interrupting conditional event is not triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_OUTPUT_MAPPING, tasksAfterVariableIsSet.get(0).getName());
}
 
Example #27
Source File: RuntimeByteArrayTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected BpmnModelInstance createFailingProcess() {
  return Bpmn.createExecutableProcess("Process")
    .startEvent()
    .serviceTask("failing")
    .camundaAsyncAfter()
    .camundaAsyncBefore()
    .camundaClass(FailingDelegate.class)
    .endEvent()
    .done();
}
 
Example #28
Source File: MixedConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableOnEndExecutionListenerInSubProcessWithBoundary() {

  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .subProcess(SUB_PROCESS_ID)
    .embeddedSubProcess()
    .startEvent()
    .userTask(TASK_WITH_CONDITION_ID)
    .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_END, EXPR_SET_VARIABLE)
    .name(TASK_WITH_CONDITION)
    .endEvent()
    .subProcessDone()
    .endEvent()
    .done();

  modelInstance = addEventSubProcess(modelInstance, SUB_PROCESS_ID, TASK_AFTER_COND_START_EVENT_IN_SUB_PROCESS, true);
  deployMixedProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, SUB_PROCESS_ID, true);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();

  //when task before is completed
  taskService.complete(task.getId());

  //then conditional boundary should not triggered but conditional start event
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITIONAL_START_EVENT, tasksAfterVariableIsSet.get(0).getName());
}
 
Example #29
Source File: TransactionTest.java    From camunda-bpmn-model with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldWriteTransaction() throws ParserConfigurationException, SAXException, IOException {
  // given a model
  BpmnModelInstance newModel = Bpmn.createProcess("process").done();

  Process process = newModel.getModelElementById("process");

  Transaction transaction = newModel.newInstance(Transaction.class);
  transaction.setId("transaction");
  transaction.setMethod(TransactionMethod.Store);
  process.addChildElement(transaction);

  // that is written to a stream
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  Bpmn.writeModelToStream(outStream, newModel);

  // when reading from that stream
  ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());

  DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
  Document actualDocument = docBuilder.parse(inStream);

  // then it possible to traverse to the transaction element and assert its attributes
  NodeList transactionElements = actualDocument.getElementsByTagName("transaction");
  assertThat(transactionElements.getLength()).isEqualTo(1);

  Node transactionElement = transactionElements.item(0);
  assertThat(transactionElement).isNotNull();
  Node methodAttribute = transactionElement.getAttributes().getNamedItem("method");
  assertThat(methodAttribute.getNodeValue()).isEqualTo("##Store");

}
 
Example #30
Source File: TriggerConditionalEventOnStartAtActivityTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
public void testSubProcessInterruptingTriggerGlobalEventSubProcess() {
  // given
  BpmnModelInstance modelInstance =  Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent("start")
    .userTask("beforeSubProcess")
    .subProcess(SUB_PROCESS_ID)
    .embeddedSubProcess()
      .startEvent()
      .userTask(TASK_BEFORE_CONDITION_ID)
      .name(TASK_BEFORE_CONDITION)
      .endEvent()
    .subProcessDone()
    .endEvent()
    .done();

  modelInstance = addConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, TASK_AFTER_CONDITION_ID, true);

  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());

  // when
  runtimeService.createProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY)
  .startBeforeActivity(TASK_BEFORE_CONDITION_ID)
  .setVariable(VARIABLE_NAME, "1")
  .executeWithVariablesInReturn();

  // then
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().count());
  assertEquals("variable", historyService.createHistoricVariableInstanceQuery().singleResult().getName());

  tasksAfterVariableIsSet = taskService.createTaskQuery().list();
  assertEquals(1, tasksAfterVariableIsSet.size());
  assertEquals(TASK_AFTER_CONDITION_ID, tasksAfterVariableIsSet.get(0).getTaskDefinitionKey());
}