protected BpmnModelInstance createProcess(String scriptFormat, String scriptText) { return Bpmn.createExecutableProcess("testProcess") .startEvent() .scriptTask() .scriptFormat(scriptFormat) .scriptText(scriptText) .userTask() .endEvent() .done(); }
protected BpmnModelInstance createProcessWithScriptTask(String key) { return Bpmn.createExecutableProcess(key) .startEvent() .scriptTask() .scriptFormat("javascript") .scriptText("return true") .userTask() .endEvent() .done(); }
private BpmnModelInstance prepareFailingScriptTask() { BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .scriptTask() .scriptFormat("groovy") .scriptText("x = 5 / 0") .camundaAsyncBefore() .userTask() .endEvent() .done(); return bpmnModelInstance; }
public void testShouldNotDeployProcessWithMissingScriptElementAndResource() { try { deployProcess(Bpmn.createExecutableProcess("testProcess") .startEvent() .scriptTask() .scriptFormat(RUBY) .userTask() .endEvent() .done()); fail("this process should not be deployable"); } catch (ProcessEngineException e) { // happy path } }
protected static StringAsset createScriptTaskProcess(String scriptFormat, String scriptText, String pdk) { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(pdk) .startEvent() .scriptTask() .scriptFormat(scriptFormat) .scriptText(scriptText) .userTask() .endEvent() .done(); return new StringAsset(Bpmn.convertToString(modelInstance)); }
protected static StringAsset createScriptTaskProcess(String scriptFormat, String scriptText) { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .scriptTask() .scriptFormat(scriptFormat) .scriptText(scriptText) .userTask() .endEvent() .done(); return new StringAsset(Bpmn.convertToString(modelInstance)); }
protected static StringAsset createScriptTaskProcess(String scriptFormat, String scriptText, String pdk) { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(pdk) .startEvent() .scriptTask() .scriptFormat(scriptFormat) .scriptText(scriptText) .userTask() .endEvent() .done(); return new StringAsset(Bpmn.convertToString(modelInstance)); }
protected static StringAsset createScriptTaskProcess(String scriptFormat, String scriptText) { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .scriptTask() .scriptFormat(scriptFormat) .scriptText(scriptText) .camundaResultVariable("scriptValue") .userTask() .endEvent() .done(); return new StringAsset(Bpmn.convertToString(modelInstance)); }
protected static StringAsset createScriptTaskProcess(String scriptFormat, String scriptText) { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .scriptTask() .scriptFormat(scriptFormat) .scriptText(scriptText) .camundaResultVariable(RESULT_VARIABLE) .userTask() .endEvent() .done(); return new StringAsset(Bpmn.convertToString(modelInstance)); }
.scriptTask() .camundaAsyncBefore() .scriptFormat("groovy") .scriptText("if(execution.getIncidents().size() == 0) throw new RuntimeException()") .userTask()
/** * See https://app.camunda.com/jira/browse/CAM-9505 */ @Test public void shouldResolveIncidentWithPreservedCreateTime() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(Bpmn.createExecutableProcess(CALLED_PROCESS_KEY) .startEvent() .scriptTask() .camundaAsyncBefore() .scriptFormat("groovy") .scriptText("if(execution.getIncidents().size() == 0) throw new RuntimeException()") .userTask() .endEvent().done()); ClockUtil.setCurrentTime(START_DATE); runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String jobId = managementService.createJobQuery().singleResult().getId(); managementService.setJobRetries(jobId, 0); try { managementService.executeJob(jobId); } catch (Exception ignored) { } String taskId = historyService.createHistoricTaskInstanceQuery().singleResult().getId(); // when taskService.complete(taskId); List<HistoricIncident> historicIncidents = historyService.createHistoricIncidentQuery().list(); // then assertThat(historicIncidents.get(0).getCreateTime(), is(START_DATE)); assertThat(historicIncidents.get(1).getCreateTime(), is(START_DATE)); }
protected void assertStartProcessInstanceFails() { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CALLED_PROCESS_DEF_ID) .startEvent() .scriptTask("scriptTask") .scriptFormat("groovy") .scriptText("throw new RuntimeException(\"BOOOM!\")") .endEvent() .done(); deployModel(modelInstance); // if try { runtimeService.startProcessInstanceByKey(PROCESS_DEF_KEY); fail("exception expected"); } catch(RuntimeException e) { assertTextPresent("BOOOM", e.getMessage()); } // then // starting the process fails and everything is rolled back: assertEquals(0, runtimeService.createExecutionQuery().count()); }
@Test public void testStartMessageCorrelationWithTransientVariable() { // given BpmnModelInstance instance = Bpmn.createExecutableProcess("process") .startEvent() .message("message") .scriptTask("scriptTask") .scriptFormat("javascript") .camundaResultVariable("abc") .scriptText("execution.setVariable('abc', foo);") .endEvent() .done(); testRule.deploy(instance); // when runtimeService.createMessageCorrelation("message") .setVariable("foo", Variables.stringValue("bar", true)) .correlate(); // then List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list(); assertEquals(0, variableInstances.size()); List<HistoricVariableInstance> historicInstances = historyService.createHistoricVariableInstanceQuery().list(); assertEquals(1, historicInstances.size()); assertEquals("abc", historicInstances.get(0).getName()); assertEquals("bar", historicInstances.get(0).getValue()); }
@Test public void testParallelExecutions() { // given BpmnModelInstance instance = Bpmn.createExecutableProcess("Process") .startEvent() .parallelGateway() .scriptTask() .scriptFormat("javascript") .camundaResultVariable("abc") .scriptText("execution.setVariableLocal('abc', foo);") .endEvent() .moveToLastGateway() .scriptTask() .scriptFormat("javascript") .camundaResultVariable("abc") .scriptText("execution.setVariableLocal('abc', foo);") .endEvent() .done(); testRule.deploy(instance); // when runtimeService.startProcessInstanceByKey("Process", Variables.createVariables().putValueTyped("foo", Variables.stringValue("bar", true))); // then List<VariableInstance> variables = runtimeService.createVariableInstanceQuery().list(); assertEquals(0, variables.size()); List<HistoricVariableInstance> historicVariables = historyService.createHistoricVariableInstanceQuery().variableName("abc").list(); assertEquals(2, historicVariables.size()); }
@Test public void testSignalWithTransientVariables() { // given BpmnModelInstance instance = Bpmn.createExecutableProcess("Process") .startEvent() .intermediateCatchEvent("signalCatch") .signal("signal") .scriptTask("scriptTask") .scriptFormat("javascript") .camundaResultVariable("abc") .scriptText("execution.setVariable('abc', foo);") .endEvent() .done(); testRule.deploy(instance); runtimeService.startProcessInstanceByKey("Process"); // when runtimeService.signalEventReceived("signal", Variables.createVariables().putValue("foo", Variables.stringValue("bar", true))); // then List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list(); assertEquals(1, variables.size()); assertEquals("abc", variables.get(0).getName()); }
@Test public void testSateOfScriptTaskProcessWithTransactionCommitAndException() { BpmnModelInstance instance = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() //add wait state .camundaAsyncAfter() .scriptTask() .scriptText("throw new RuntimeException()") .scriptFormat("groovy") .endEvent() .done(); ProcessDefinition processDefinition = processEngineTestRule.deployAndGetDefinition(instance); try { ProcessInstance pi = processEngineRule.getRuntimeService() .startProcessInstanceById(processDefinition.getId()); processEngineRule.getManagementService().executeJob( processEngineRule.getManagementService().createJobQuery().executable().singleResult().getId()); fail("exception expected"); } catch (Exception e) { //expected } assertThat(processEngineRule.getRuntimeService().createProcessInstanceQuery().active().list().size(), is(1)); HistoricProcessInstance entity = getHistoricProcessInstanceWithAssertion(processDefinition); assertThat(entity.getState(), is(HistoricProcessInstance.STATE_ACTIVE)); assertEquals(1, processEngineRule.getHistoryService().createHistoricProcessInstanceQuery().active().count()); }
.scriptTask() .camundaAsyncBefore() .scriptFormat("groovy") .scriptText("if(execution.getIncidents().size() == 0) throw new RuntimeException(\"I'm supposed to fail!\")") .endEvent().done());
@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()); }
.startEvent() .scriptTask("scriptTaskInSubprocess") .scriptFormat("groovy") .scriptText("throw new org.camunda.bpm.engine.delegate.BpmnError(\"anErrorCode\");") .userTask()
private BpmnModelInstance prepareFailingScriptTask() { BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .scriptTask() .scriptFormat("groovy") .scriptText("x = 5 / 0") .camundaAsyncBefore() .userTask() .endEvent() .done(); return bpmnModelInstance; }