@Override public IntermediateCatchEventBuilder builder() { return new IntermediateCatchEventBuilder((BpmnModelInstance) modelInstance, this); } }
public void testIntermediateCatchEvent() throws Exception { BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent() .message("foo") .camundaAsyncBefore() .camundaFailedJobRetryTimeCycle("R5/PT5M") .camundaExecutionListenerClass("start", "foo") .endEvent() .done(); deployment(bpmnModelInstance); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date startDate = simpleDateFormat.parse("2018-01-01T10:00:00"); ClockUtil.setCurrentTime(startDate); runtimeService.startProcessInstanceByKey("process"); Job job = managementService.createJobQuery().singleResult(); // assume Assert.assertEquals(3, job.getRetries()); // when job fails try { managementService.executeJob(job.getId()); } catch (Exception e) { // ignore } // then job = managementService.createJobQuery().singleResult(); Assert.assertEquals(4, job.getRetries()); Date expectedDate = simpleDateFormat.parse("2018-01-01T10:05:00"); assertEquals(expectedDate, ((JobEntity) job).getLockExpirationTime()); }
public void testPropagateTenantIdToIntermediateTimerJob() { deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY) .startEvent() .intermediateCatchEvent() .timerWithDuration("PT1M") .endEvent() .done()); startProcessInstance(PROCESS_DEFINITION_KEY); // the job is created when the timer event is reached Job job = managementService.createJobQuery().singleResult(); assertThat(job, is(notNullValue())); // inherit the tenant id from job definition assertThat(job.getTenantId(), is(TENANT_ID)); }
public void testPropagateTenantIdToIntermediateMessageEventSubscription() { deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY) .startEvent() .intermediateCatchEvent() .message("start") .endEvent() .done()); startProcessInstance(PROCESS_DEFINITION_KEY); EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult(); assertThat(eventSubscription, is(notNullValue())); // inherit the tenant id from process instance assertThat(eventSubscription.getTenantId(), is(TENANT_ID)); }
.startEvent() .intermediateCatchEvent("message_1") .message("1") .camundaOutputParameter(outputVarName, "${testLocalVar}") .userTask("UserTask_1") .endEvent() .done();
.startEvent() .intermediateCatchEvent("timerCatch") .timerWithDuration("PT50M") .userTask("userTask") .endEvent() .done());
@Test public void testMigrateEventSubscriptionPreserveMessageName() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(MessageReceiveModels.ONE_MESSAGE_CATCH_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.newModel() .startEvent() .intermediateCatchEvent("messageCatch") .message("new" + MessageReceiveModels.MESSAGE_NAME) .userTask("userTask") .endEvent() .done()); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("messageCatch", "messageCatch") .build(); // when ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan); // then the message event subscription's event name has not changed testHelper.assertEventSubscriptionMigrated("messageCatch", "messageCatch", MessageReceiveModels.MESSAGE_NAME); // and it is possible to trigger the receive task rule.getRuntimeService().correlateMessage(MessageReceiveModels.MESSAGE_NAME); testHelper.completeTask("userTask"); testHelper.assertProcessEnded(processInstance.getId()); }
@Test public void testIntermediateCatchEventMessageCorrelation() { //given BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1") .startEvent() .subProcess("SubProcess_1").embeddedSubProcess() .startEvent() .intermediateCatchEvent("MessageReceiver_1").message(TEST_MESSAGE_NAME) .camundaInputParameter("localVar", "${loopVar}") .userTask("UserTask_1") .endEvent() .subProcessDone() .multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone() .endEvent().done(); testHelper.deploy(model); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("vars", Arrays.asList(1, 2, 3)); ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables); //when correlated by local variables String messageName = TEST_MESSAGE_NAME; int correlationKey = 1; MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName) .localVariableEquals("localVar", correlationKey).setVariables(Variables.createVariables().putValue("newVar", "newValue")).correlateWithResult(); //then one message is correlated, two others continue waiting checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "MessageReceiver_1"); //uncorrelated executions List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list(); assertEquals(2, uncorrelatedExecutions.size()); }
@Test public void triggerConditionalEventWithTransientVariable() { // given BpmnModelInstance instance = Bpmn.createExecutableProcess(CONDITIONAL_PROCESS_KEY) .startEvent() .serviceTask() .camundaClass(SetVariableTransientDelegate.class.getName()) .intermediateCatchEvent(CONDITION_ID) .conditionalEventDefinition() .condition(VAR_CONDITION) .conditionalEventDefinitionDone() .endEvent() .done(); testRule.deploy(instance); // when ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CONDITIONAL_PROCESS_KEY); // then assertEquals(true, processInstance.isEnded()); }
@Test public void setAuthenticatedTenantForIntermediateTimerEvent() { testRule.deployForTenant(TENANT_ID, Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent() .timerWithDuration("PT1M") .serviceTask() .camundaClass(AssertingJavaDelegate.class.getName()) .endEvent() .done()); ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("process"); AssertingJavaDelegate.addAsserts(hasAuthenticatedTenantId(TENANT_ID)); ClockUtil.setCurrentTime(tomorrow()); testRule.waitForJobExecutorToProcessAllJobs(); testRule.assertProcessEnded(processInstance.getId()); }
@Test public void testMessageCorrelationWithTransientVariable() { // given BpmnModelInstance instance = Bpmn.createExecutableProcess("process") .startEvent() .intermediateCatchEvent() .message("message") .scriptTask("scriptTask") .scriptFormat("javascript") .camundaResultVariable("abc") .scriptText("execution.setVariable('abc', blob);") .endEvent() .done(); testRule.deploy(instance); runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValueTyped("foo", Variables.stringValue("foo", false))); // when VariableMap correlationKeys = Variables.createVariables().putValueTyped("foo", Variables.stringValue("foo", true)); VariableMap variables = Variables.createVariables().putValueTyped("blob", Variables.stringValue("blob", true)); runtimeService.correlateMessage("message", correlationKeys, variables); // then VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult(); assertNull(variableInstance); HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery() .variableName("abc").singleResult(); assertNotNull(historicVariableInstance); assertEquals("blob", historicVariableInstance.getValue()); }
@Test public void testMapIntermediateConditionalEvent() { BpmnModelInstance sourceProcess = Bpmn.createExecutableProcess(CONDITIONAL_PROCESS_KEY) .startEvent() .intermediateCatchEvent(CONDITION_ID) .condition(VAR_CONDITION) .userTask(USER_TASK_ID) .endEvent() .done(); assertGeneratedMigrationPlan(sourceProcess, sourceProcess, false) .hasInstructions( migrate(CONDITION_ID).to(CONDITION_ID).updateEventTrigger(true), migrate(USER_TASK_ID).to(USER_TASK_ID).updateEventTrigger(false) ); }
/** * On execution, the MockProcess will wait for the given message * * @param message * @return */ public CallActivityMock onExecutionWaitForMessage(final String message) { flowNodeBuilder = flowNodeBuilder.intermediateCatchEvent() .message(message); return this; }
/** * On execution, the MockProcess will wait on a timer which is configured with an ISO 8601 duration. * E.g.: PT60S ... will wait for 60 sec * * @param iso8601duration * @return */ public CallActivityMock onExecutionWaitForTimerWithDuration(final String iso8601duration) { flowNodeBuilder = flowNodeBuilder.intermediateCatchEvent() .timerWithDuration(iso8601duration); return this; }
.startEvent() .intermediateCatchEvent("message_1") .message("1") .camundaOutputParameter(outputVarName, "${testLocalVar}") .userTask("UserTask_1") .endEvent() .done();
@Test public void testMigrateJobPreserveTimerConfiguration() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(TimerCatchModels.ONE_TIMER_CATCH_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.newModel() .startEvent() .intermediateCatchEvent("timerCatch") .timerWithDuration("PT50M") .userTask("userTask") .endEvent() .done()); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("timerCatch", "timerCatch") .build(); // when ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan); // then testHelper.assertJobMigrated( // this also asserts that the due has not changed testHelper.snapshotBeforeMigration.getJobs().get(0), "timerCatch"); // and it is possible to trigger the event Job jobAfterMigration = testHelper.snapshotAfterMigration.getJobs().get(0); rule.getManagementService().executeJob(jobAfterMigration.getId()); testHelper.completeTask("userTask"); testHelper.assertProcessEnded(processInstance.getId()); }
@Test public void testMigrateGatewayRemoveMessageEvent() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(modify(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS) .flowNodeBuilder("eventBasedGateway") .intermediateCatchEvent("oldMessageCatch") .message("old" + EventBasedGatewayModels.MESSAGE_NAME) .endEvent() .done()); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("eventBasedGateway", "eventBasedGateway") .mapActivities("messageCatch", "messageCatch") .build(); // when testHelper.createProcessInstanceAndMigrate(migrationPlan); // then testHelper.assertEventSubscriptionRemoved("oldMessageCatch", "old" + EventBasedGatewayModels.MESSAGE_NAME); testHelper.assertEventSubscriptionMigrated("messageCatch", "messageCatch", EventBasedGatewayModels.MESSAGE_NAME); }
@Test public void testMigrateGatewayAddMessageEvent() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(EventBasedGatewayModels.MESSAGE_EVENT_BASED_GW_PROCESS) .flowNodeBuilder("eventBasedGateway") .intermediateCatchEvent("newMessageCatch") .message("new" + EventBasedGatewayModels.MESSAGE_NAME) .userTask("afterNewMessageCatch") .endEvent() .done()); MigrationPlan migrationPlan = rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("eventBasedGateway", "eventBasedGateway") .mapActivities("messageCatch", "messageCatch") .build(); // when ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan); // then testHelper.assertEventSubscriptionCreated("newMessageCatch", "new" + EventBasedGatewayModels.MESSAGE_NAME); testHelper.assertEventSubscriptionMigrated("messageCatch", "messageCatch", EventBasedGatewayModels.MESSAGE_NAME); rule.getRuntimeService().correlateMessage("new" + EventBasedGatewayModels.MESSAGE_NAME); testHelper.completeTask("afterNewMessageCatch"); testHelper.assertProcessEnded(processInstance.getId()); }
@Test public void testIntermediateCatchEventMessageCorrelation() { //given BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1") .startEvent() .subProcess("SubProcess_1").embeddedSubProcess() .startEvent() .intermediateCatchEvent("MessageReceiver_1").message(TEST_MESSAGE_NAME) .camundaInputParameter("localVar", "${loopVar}") .userTask("UserTask_1") .endEvent() .subProcessDone() .multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone() .endEvent().done(); testHelper.deploy(model); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("vars", Arrays.asList(1, 2, 3)); ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables); //when correlated by local variables String messageName = TEST_MESSAGE_NAME; int correlationKey = 1; MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName) .localVariableEquals("localVar", correlationKey).setVariables(Variables.createVariables().putValue("newVar", "newValue")).correlateWithResult(); //then one message is correlated, two others continue waiting checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "MessageReceiver_1"); //uncorrelated executions List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list(); assertEquals(2, uncorrelatedExecutions.size()); }