Java Code Examples for org.camunda.bpm.model.bpmn.BpmnModelInstance#newInstance()

The following examples show how to use org.camunda.bpm.model.bpmn.BpmnModelInstance#newInstance() . 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: TargetVariableScopeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetLocalScopeWithExecutionListenerTake() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process")
    .startEvent().id("activityId")
    .sequenceFlowId("sequenceFlow")
    .endEvent()
    .done();

  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(ExecutionListener.class.getName());
  modelInstance.<SequenceFlow>getModelElementById("sequenceFlow").builder().addExtensionElement(listener);

  testHelper.deploy(modelInstance);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");
}
 
Example 2
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListener() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                .sequenceFlowId(FLOW_ID)
                                                .userTask(TASK_WITH_CONDITION_ID).name(TASK_WITH_CONDITION)
                                                .endEvent()
                                                .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_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 take listener sets variable
  //non interrupting boundary event is triggered with default evaluation behavior
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITION, tasksAfterVariableIsSet.get(0).getName());
}
 
Example 3
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListenerWithAsyncBefore() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .userTask(TASK_BEFORE_CONDITION_ID)
      .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID)
      .name(TASK_WITH_CONDITION)
      .camundaAsyncBefore()
    .endEvent(END_EVENT_ID)
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  modelInstance = specifier.specifyConditionalProcess(modelInstance, true);
  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 take listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  specifier.assertTaskNames(tasksAfterVariableIsSet, true, false);
}
 
Example 4
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInTakeListener() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                .sequenceFlowId(FLOW_ID)
                                                .userTask(TASK_WITH_CONDITION_ID).name(TASK_WITH_CONDITION)
                                                .endEvent()
                                                .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  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 is completed
  taskService.complete(task.getId());

  //then take listener sets variable
  //non interrupting boundary event is triggered with default evaluation behavior
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(2, tasksAfterVariableIsSet.size());
}
 
Example 5
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .userTask(TASK_BEFORE_CONDITION_ID)
      .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID)
      .name(TASK_WITH_CONDITION)
    .endEvent(END_EVENT_ID)
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  modelInstance = specifier.specifyConditionalProcess(modelInstance, true);
  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 take listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  specifier.assertTaskNames(tasksAfterVariableIsSet, true, false);
}
 
Example 6
Source File: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInTakeListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID)
    .endEvent()
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(specifier.getDelegateClass().getName());
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  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());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

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

  //then take 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 7
Source File: ExecutionListenerBpmnModelExecutionContextTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void addMessageEventDefinition(CatchEvent catchEvent) {
  BpmnModelInstance modelInstance = (BpmnModelInstance) catchEvent.getModelInstance();
  Message message = modelInstance.newInstance(Message.class);
  message.setId(MESSAGE_ID);
  message.setName(MESSAGE_NAME);
  modelInstance.getDefinitions().addChildElement(message);
  MessageEventDefinition messageEventDefinition = modelInstance.newInstance(MessageEventDefinition.class);
  messageEventDefinition.setMessage(message);
  catchEvent.getEventDefinitions().add(messageEventDefinition);
}
 
Example 8
Source File: ExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowBpmnErrorInProcessStartListenerShouldNotTriggerPropagation() {
  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess(PROCESS_KEY);
  BpmnModelInstance model = processBuilder
      .startEvent()
      .userTask("afterThrow")
      .endEvent()
      .done();

  processBuilder.eventSubProcess()
      .startEvent("errorEvent").error(ERROR_CODE)
      .userTask("afterCatch")
      .endEvent();

  CamundaExecutionListener listener = model.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_START);
  listener.setCamundaClass(ThrowBPMNErrorDelegate.class.getName());
  model.<org.camunda.bpm.model.bpmn.instance.Process>getModelElementById(PROCESS_KEY).builder().addExtensionElement(listener);

  DeploymentWithDefinitions deployment = testHelper.deploy(model);

  try {
    // when listeners are invoked
    runtimeService.startProcessInstanceByKey(PROCESS_KEY);
    fail("Exception expected");
  } catch (Exception e) {
    // then
    assertTrue(e.getMessage().contains("business error"));
    assertEquals(1, ThrowBPMNErrorDelegate.INVOCATIONS);
  }

  // cleanup
  repositoryService.deleteDeployment(deployment.getId(), true, true);
}
 
Example 9
Source File: ExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowBpmnErrorInTakeListenerAndEventSubprocessWithCatch() {
  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess(PROCESS_KEY);
  BpmnModelInstance model = processBuilder
      .startEvent()
      .userTask("userTask1")
      .sequenceFlowId("flow1")
      .userTask("afterListener")
      .endEvent()
      .done();

  CamundaExecutionListener listener = model.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(ThrowBPMNErrorDelegate.class.getName());
  model.<SequenceFlow>getModelElementById("flow1").builder().addExtensionElement(listener);

  processBuilder.eventSubProcess()
      .startEvent("errorEvent").error(ERROR_CODE)
      .userTask("afterCatch")
      .endEvent();

  testHelper.deploy(model);

  runtimeService.startProcessInstanceByKey(PROCESS_KEY);
  Task task = taskService.createTaskQuery().taskDefinitionKey("userTask1").singleResult();
  // when the listeners are invoked
  taskService.complete(task.getId());

  // then
  verifyErrorGotCaught();
}
 
Example 10
Source File: ListenerProcessEngineServicesAccessTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Task createModelAccessTask(BpmnModelInstance modelInstance, Class<?> delegateClass) {
  ManualTask task = modelInstance.newInstance(ManualTask.class);
  task.setId("manualTask");
  CamundaExecutionListener executionListener = modelInstance.newInstance(CamundaExecutionListener.class);
  executionListener.setCamundaEvent(ExecutionListener.EVENTNAME_START);
  executionListener.setCamundaClass(delegateClass.getName());
  task.builder().addExtensionElement(executionListener);
  return task;
}
 
Example 11
Source File: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListenerWithAsyncBefore() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID).camundaAsyncBefore()
    .endEvent()
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(specifier.getDelegateClass().getName());
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), 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 take listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(specifier.getExpectedInterruptingCount(), taskQuery.taskName(TASK_AFTER_CONDITION).count());
}
 
Example 12
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableOnParentScopeInTakeListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .subProcess()
    .embeddedSubProcess()
    .startEvent()
      .userTask(TASK_BEFORE_CONDITION_ID)
        .name(TASK_BEFORE_CONDITION)
      .sequenceFlowId(FLOW_ID)
      .userTask(TASK_WITH_CONDITION_ID)
        .name(TASK_WITH_CONDITION)
      .endEvent()
    .subProcessDone()
    .endEvent(END_EVENT_ID)
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE_ON_PARENT);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  modelInstance = specifier.specifyConditionalProcess(modelInstance, true);
  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
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  specifier.assertTaskNames(tasksAfterVariableIsSet, true, false);
}
 
Example 13
Source File: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID)
    .endEvent()
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(specifier.getDelegateClass().getName());
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), 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 take listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(specifier.getExpectedInterruptingCount(), taskQuery.taskName(TASK_AFTER_CONDITION).count());
}
 
Example 14
Source File: TransactionTest.java    From camunda-bpm-platform 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 15
Source File: HistoricProcessInstanceStateTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected static void initEndEvent(BpmnModelInstance modelInstance, String endEventId) {
  EndEvent endEvent = modelInstance.getModelElementById(endEventId);
  TerminateEventDefinition terminateDefinition = modelInstance.newInstance(TerminateEventDefinition.class);
  endEvent.addChildElement(terminateDefinition);
}
 
Example 16
Source File: TransactionModels.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected static void makeCancelEvent(BpmnModelInstance model, String eventId) {
  ModelElementInstance element = model.getModelElementById(eventId);

  CancelEventDefinition eventDefinition = model.newInstance(CancelEventDefinition.class);
  element.addChildElement(eventDefinition);
}
 
Example 17
Source File: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInTakeListenerWithAsyncBefore() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID).camundaAsyncBefore()
    .endEvent()
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaClass(specifier.getDelegateClass().getName());
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  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 take listener sets variable
  //non interrupting boundary event is triggered
  assertEquals(specifier.getExpectedNonInterruptingCount(),  taskService.createTaskQuery().taskName(TASK_AFTER_CONDITION).count());

  //and job was created
  Job job = engine.getManagementService().createJobQuery().singleResult();
  assertNotNull(job);


  //when job is executed task is created
  engine.getManagementService().executeJob(job.getId());
  //when all tasks are completed
  assertEquals(specifier.getExpectedNonInterruptingCount() + 1, taskQuery.count());
  for (Task task : taskQuery.list()) {
    taskService.complete(task.getId());
  }

  //then no task exist and process instance is ended
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(0, tasksAfterVariableIsSet.size());
  assertNull(runtimeService.createProcessInstanceQuery().singleResult());
}
 
Example 18
Source File: MultiInstanceVariablesTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void addAllIn(BpmnModelInstance modelInstance, CallActivityBuilder callActivityBuilder) {
  CamundaIn camundaIn = modelInstance.newInstance(CamundaIn.class);
  camundaIn.setCamundaVariables(ALL);
  callActivityBuilder.addExtensionElement(camundaIn);
}
 
Example 19
Source File: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for handing over process variables without target attribute set
 */
public void testSubProcessWithDataInputOutputWithoutTarget() {
  String processId = "subProcessDataInputOutputWithoutTarget";

  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(processId)
          .startEvent()
          .callActivity("callActivity")
          .calledElement("simpleSubProcess")
          .userTask()
          .endEvent()
          .done();

  CallActivityBuilder callActivityBuilder = ((CallActivity) modelInstance.getModelElementById("callActivity")).builder();

  // create camunda:in with source but without target
  CamundaIn camundaIn = modelInstance.newInstance(CamundaIn.class);
  camundaIn.setCamundaSource("superVariable");
  callActivityBuilder.addExtensionElement(camundaIn);

  deployAndExpectException(modelInstance);
  // set target
  camundaIn.setCamundaTarget("subVariable");

  // create camunda:in with sourceExpression but without target
  camundaIn = modelInstance.newInstance(CamundaIn.class);
  camundaIn.setCamundaSourceExpression("${x+5}");
  callActivityBuilder.addExtensionElement(camundaIn);

  deployAndExpectException(modelInstance);
  // set target
  camundaIn.setCamundaTarget("subVariable2");

  // create camunda:out with source but without target
  CamundaOut camundaOut = modelInstance.newInstance(CamundaOut.class);
  camundaOut.setCamundaSource("subVariable");
  callActivityBuilder.addExtensionElement(camundaOut);

  deployAndExpectException(modelInstance);
  // set target
  camundaOut.setCamundaTarget("superVariable");

  // create camunda:out with sourceExpression but without target
  camundaOut = modelInstance.newInstance(CamundaOut.class);
  camundaOut.setCamundaSourceExpression("${y+1}");
  callActivityBuilder.addExtensionElement(camundaOut);

  deployAndExpectException(modelInstance);
  // set target
  camundaOut.setCamundaTarget("superVariable2");

  try {
    String deploymentId = repositoryService.createDeployment().addModelInstance("process.bpmn", modelInstance).deploy().getId();
    repositoryService.deleteDeployment(deploymentId, true);
  } catch (ProcessEngineException e) {
    fail("No exception expected");
  }
}
 
Example 20
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInTakeListenerWithAsyncBefore() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .userTask(TASK_BEFORE_CONDITION_ID)
      .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID)
      .name(TASK_WITH_CONDITION)
      .camundaAsyncBefore()
    .endEvent(END_EVENT_ID)
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  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());

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

  //then take listener sets variable
  //non interrupting boundary event is triggered
  specifier.assertTaskNames(taskQuery.list(), false, true);

  //and job was created
  Job job = engine.getManagementService().createJobQuery().singleResult();
  assertNotNull(job);
  assertEquals(1, conditionEventSubscriptionQuery.list().size());

  //when job is executed task is created
  engine.getManagementService().executeJob(job.getId());
  //when tasks are completed
  for (Task task : taskQuery.list()) {
    taskService.complete(task.getId());
  }

  //then no task exist and process instance is ended
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(0, tasksAfterVariableIsSet.size());
  assertNull(runtimeService.createProcessInstanceQuery().singleResult());
}