@SuppressWarnings("unchecked") protected ProcessInstantiationBuilder setUpMockInstantiationBuilder() { ProcessInstanceWithVariables resultInstanceWithVariables = MockProvider.createMockInstanceWithVariables(); ProcessInstantiationBuilder mockInstantiationBuilder = mock(ProcessInstantiationBuilder.class); when(mockInstantiationBuilder.startAfterActivity(anyString())).thenReturn(mockInstantiationBuilder); when(mockInstantiationBuilder.startBeforeActivity(anyString())).thenReturn(mockInstantiationBuilder); when(mockInstantiationBuilder.startTransition(anyString())).thenReturn(mockInstantiationBuilder); when(mockInstantiationBuilder.setVariables(any(Map.class))).thenReturn(mockInstantiationBuilder); when(mockInstantiationBuilder.setVariablesLocal(any(Map.class))).thenReturn(mockInstantiationBuilder); when(mockInstantiationBuilder.businessKey(anyString())).thenReturn(mockInstantiationBuilder); when(mockInstantiationBuilder.caseInstanceId(anyString())).thenReturn(mockInstantiationBuilder); when(mockInstantiationBuilder.execute(anyBoolean(), anyBoolean())).thenReturn(resultInstanceWithVariables); when(mockInstantiationBuilder.executeWithVariablesInReturn(anyBoolean(), anyBoolean())).thenReturn(resultInstanceWithVariables); return mockInstantiationBuilder; }
@Test public void testProcessInstantiationWithBusinessKey() throws IOException { Map<String, Object> json = new HashMap<String, Object>(); json.put("businessKey", "myBusinessKey"); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(POST_JSON_CONTENT_TYPE).body(json) .then().expect() .statusCode(Status.OK.getStatusCode()) .body("id", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)) .when().post(START_PROCESS_INSTANCE_URL); verify(runtimeServiceMock).createProcessInstanceById(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)); verify(mockInstantiationBuilder).businessKey("myBusinessKey"); verify(mockInstantiationBuilder).executeWithVariablesInReturn(anyBoolean(), anyBoolean()); }
@Test public void testProcessInstantiationWithBusinessKey_ByKey() throws IOException { Map<String, Object> json = new HashMap<String, Object>(); json.put("businessKey", "myBusinessKey"); given().pathParam("key", MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY) .contentType(POST_JSON_CONTENT_TYPE).body(json) .then().expect() .statusCode(Status.OK.getStatusCode()) .body("id", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)) .when().post(START_PROCESS_INSTANCE_BY_KEY_URL); verify(runtimeServiceMock).createProcessInstanceById(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)); verify(mockInstantiationBuilder).businessKey("myBusinessKey"); verify(mockInstantiationBuilder).executeWithVariablesInReturn(anyBoolean(), anyBoolean()); }
@Test public void testProcessInstantiationWithCaseInstanceId() throws IOException { Map<String, Object> json = new HashMap<String, Object>(); json.put("caseInstanceId", "myCaseInstanceId"); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(POST_JSON_CONTENT_TYPE).body(json) .then().expect() .statusCode(Status.OK.getStatusCode()) .body("id", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)) .when().post(START_PROCESS_INSTANCE_URL); verify(runtimeServiceMock).createProcessInstanceById(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)); verify(mockInstantiationBuilder).caseInstanceId("myCaseInstanceId"); verify(mockInstantiationBuilder).executeWithVariablesInReturn(anyBoolean(), anyBoolean()); }
@Test public void testProcessInstantiationWithCaseInstanceIdAndBusinessKey() throws IOException { Map<String, Object> json = new HashMap<String, Object>(); json.put("caseInstanceId", "myCaseInstanceId"); json.put("businessKey", "myBusinessKey"); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(POST_JSON_CONTENT_TYPE).body(json) .then().expect() .statusCode(Status.OK.getStatusCode()) .body("id", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)) .when().post(START_PROCESS_INSTANCE_URL); verify(runtimeServiceMock).createProcessInstanceById(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)); verify(mockInstantiationBuilder).businessKey("myBusinessKey"); verify(mockInstantiationBuilder).caseInstanceId("myCaseInstanceId"); verify(mockInstantiationBuilder).executeWithVariablesInReturn(anyBoolean(), anyBoolean()); }
/** * {@link RuntimeService#startProcessInstanceById(String, Map)} throws an {@link ProcessEngineException}, if a definition with the given id does not exist. */ @Test public void testUnsuccessfulInstantiation() { when(mockInstantiationBuilder.executeWithVariablesInReturn(anyBoolean(), anyBoolean())) .thenThrow(new ProcessEngineException("expected exception")); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(POST_JSON_CONTENT_TYPE).body(EMPTY_JSON_OBJECT) .then().expect() .statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON) .body("type", equalTo(RestException.class.getSimpleName())) .body("message", containsString("Cannot instantiate process definition")) .when().post(START_PROCESS_INSTANCE_URL); }
/** * {@link RuntimeService#startProcessInstanceById(String, Map)} throws an {@link ProcessEngineException}, if a definition with the given id does not exist. */ @Test public void testUnsuccessfulInstantiation_ByKey() { when(mockInstantiationBuilder.executeWithVariablesInReturn(anyBoolean(), anyBoolean())) .thenThrow(new ProcessEngineException("expected exception")); given().pathParam("key", MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY) .contentType(POST_JSON_CONTENT_TYPE).body(EMPTY_JSON_OBJECT) .then().expect() .statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON) .body("type", equalTo(RestException.class.getSimpleName())) .body("message", containsString("Cannot instantiate process definition")) .when().post(START_PROCESS_INSTANCE_BY_KEY_URL); }
protected ProcessInstanceWithVariables startProcessInstanceAtActivities(StartProcessInstanceDto dto) { Map<String, Object> processInstanceVariables = VariableValueDto.toMap(dto.getVariables(), engine, objectMapper); String businessKey = dto.getBusinessKey(); String caseInstanceId = dto.getCaseInstanceId(); ProcessInstantiationBuilder instantiationBuilder = engine.getRuntimeService() .createProcessInstanceById(processDefinitionId) .businessKey(businessKey) .caseInstanceId(caseInstanceId) .setVariables(processInstanceVariables); if (dto.getStartInstructions() != null && !dto.getStartInstructions().isEmpty()) { for (ProcessInstanceModificationInstructionDto instruction : dto.getStartInstructions()) { instruction.applyTo(instantiationBuilder, engine, objectMapper); } } return instantiationBuilder.executeWithVariablesInReturn(dto.isSkipCustomListeners(), dto.isSkipIoMappings()); }
@Test public void testStartProcessInstanceByKeyThrowsAuthorizationException() { String message = "expected exception"; when(mockInstantiationBuilder.executeWithVariablesInReturn(anyBoolean(), anyBoolean())) .thenThrow(new AuthorizationException(message)); given() .pathParam("key", MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY) .contentType(POST_JSON_CONTENT_TYPE) .body(EMPTY_JSON_OBJECT) .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo(message)) .when() .post(START_PROCESS_INSTANCE_BY_KEY_URL); }
protected ProcessInstanceWithVariables startProcessInstanceAtActivities(StartProcessInstanceDto dto) { Map<String, Object> processInstanceVariables = VariableValueDto.toMap(dto.getVariables(), engine, objectMapper); String businessKey = dto.getBusinessKey(); String caseInstanceId = dto.getCaseInstanceId(); ProcessInstantiationBuilder instantiationBuilder = engine.getRuntimeService() .createProcessInstanceById(processDefinitionId) .businessKey(businessKey) .caseInstanceId(caseInstanceId) .setVariables(processInstanceVariables); if (dto.getStartInstructions() != null && !dto.getStartInstructions().isEmpty()) { for (ProcessInstanceModificationInstructionDto instruction : dto.getStartInstructions()) { instruction.applyTo(instantiationBuilder, engine, objectMapper); } } return instantiationBuilder.executeWithVariablesInReturn(dto.isSkipCustomListeners(), dto.isSkipIoMappings()); }
@Test public void testStartProcessInstanceByIdThrowsAuthorizationException() { String message = "expected exception"; when(mockInstantiationBuilder.executeWithVariablesInReturn(anyBoolean(), anyBoolean())) .thenThrow(new AuthorizationException(message)); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(POST_JSON_CONTENT_TYPE) .body(EMPTY_JSON_OBJECT) .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo(message)) .when() .post(START_PROCESS_INSTANCE_URL); }
@Test public void testTriggerGlobalEventSubProcess() { //given deployConditionalEventSubProcess(TASK_MODEL, CONDITIONAL_EVENT_PROCESS_KEY, true); //when runtimeService.createProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY) .startBeforeActivity(TASK_BEFORE_CONDITION_ID) .setVariable(VARIABLE_NAME, "1") .executeWithVariablesInReturn(); //then tasksAfterVariableIsSet = taskService.createTaskQuery().list(); assertEquals(1, tasksAfterVariableIsSet.size()); assertEquals(TASK_AFTER_CONDITION_ID, tasksAfterVariableIsSet.get(0).getTaskDefinitionKey()); }
@Test public void testTriggerBoundaryEvent() { //given deployConditionalBoundaryEventProcess(TASK_MODEL, TASK_BEFORE_CONDITION_ID, true); //when runtimeService.createProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY) .startBeforeActivity(TASK_BEFORE_CONDITION_ID) .setVariable(VARIABLE_NAME, "1") .executeWithVariablesInReturn(); //then tasksAfterVariableIsSet = taskService.createTaskQuery().list(); assertEquals(1, tasksAfterVariableIsSet.size()); assertEquals(TASK_AFTER_CONDITION_ID, tasksAfterVariableIsSet.get(0).getTaskDefinitionKey()); }
@Test @Deployment(resources = SET_VARIABLE_IN_DELEGATE_PROCESS) public void testReturnVariablesFromExecution() { //given executed process which sets variables in java delegate ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService().createProcessInstanceByKey("variableProcess") .executeWithVariablesInReturn(); //when returned instance contains variables VariableMap map = procInstance.getVariables(); assertNotNull(map); // then variables equal to variables which are accessible via query checkVariables(map, 8); }
@Test @Deployment(resources = SET_VARIABLE_IN_DELEGATE_WITH_WAIT_STATE_PROCESS) public void testReturnVariablesFromExecutionWithWaitstate() { //given executed process which sets variables in java delegate ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService().createProcessInstanceByKey("variableProcess") .executeWithVariablesInReturn(); //when returned instance contains variables VariableMap map = procInstance.getVariables(); assertNotNull(map); // then variables equal to variables which are accessible via query checkVariables(map, 8); }
@Test public void testNonInterruptingTriggerGlobalEventSubProcess() { //given deployConditionalEventSubProcess(TASK_MODEL, CONDITIONAL_EVENT_PROCESS_KEY, false); //when runtimeService.createProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY) .startBeforeActivity(TASK_BEFORE_CONDITION_ID) .setVariable(VARIABLE_NAME, "1") .executeWithVariablesInReturn(); //then tasksAfterVariableIsSet = taskService.createTaskQuery().list(); assertEquals(2, tasksAfterVariableIsSet.size()); assertEquals(1, taskService.createTaskQuery().taskName(TASK_AFTER_CONDITION).count()); assertEquals(1, conditionEventSubscriptionQuery.count()); }
@Test public void testNonInterruptingTriggerBoundaryEvent() { //given deployConditionalBoundaryEventProcess(TASK_MODEL, TASK_BEFORE_CONDITION_ID, false); //when runtimeService.createProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY) .startBeforeActivity(TASK_BEFORE_CONDITION_ID) .setVariable(VARIABLE_NAME, "1") .executeWithVariablesInReturn(); //then tasksAfterVariableIsSet = taskService.createTaskQuery().list(); assertEquals(2, tasksAfterVariableIsSet.size()); assertEquals(1, taskService.createTaskQuery().taskName(TASK_AFTER_CONDITION).count()); assertEquals(1, conditionEventSubscriptionQuery.count()); }
@Test @Deployment(resources = SET_VARIABLE_IN_DELEGATE_PROCESS) public void testReturnVariablesFromStartAndExecution() { //given executed process which sets variables in java delegate ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService().createProcessInstanceByKey("variableProcess") .setVariable("aVariable1", "aValue1") .setVariableLocal("aVariable2", "aValue2") .setVariables(Variables.createVariables().putValue("aVariable3", "aValue3")) .setVariablesLocal(Variables.createVariables().putValue("aVariable4", new byte[]{127, 34, 64})) .executeWithVariablesInReturn(); //when returned instance contains variables VariableMap map = procInstance.getVariables(); assertNotNull(map); // then variables equal to variables which are accessible via query checkVariables(map, 12); }
@Test @Deployment(resources = SIMPLE_PROCESS) public void testReturnVariablesFromStart() { //given execute process with variables ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService() .createProcessInstanceByKey("simpleProcess") .setVariable("aVariable1", "aValue1") .setVariableLocal("aVariable2", "aValue2") .setVariables(Variables.createVariables().putValue("aVariable3", "aValue3")) .setVariablesLocal(Variables.createVariables().putValue("aVariable4", new byte[]{127, 34, 64})) .executeWithVariablesInReturn(false, false); //when returned instance contains variables VariableMap map = procInstance.getVariables(); assertNotNull(map); // then variables equal to variables which are accessible via query checkVariables(map, 4); }
@Test @Deployment(resources = SUBPROCESS_PROCESS) public void testReturnVariablesFromStartWithWaitstate() { //given execute process with variables and wait state ProcessInstanceWithVariables procInstance = engineRule.getRuntimeService() .createProcessInstanceByKey("subprocess") .setVariable("aVariable1", "aValue1") .setVariableLocal("aVariable2", "aValue2") .setVariables(Variables.createVariables().putValue("aVariable3", "aValue3")) .setVariablesLocal(Variables.createVariables().putValue("aVariable4", new byte[]{127, 34, 64})) .executeWithVariablesInReturn(false, false); //when returned instance contains variables VariableMap map = procInstance.getVariables(); assertNotNull(map); // then variables equal to variables which are accessible via query checkVariables(map, 4); }