Search in sources :

Example 6 with ProcessInstantiationBuilder

use of org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method startProcessInstanceAtActivities.

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());
}
Also used : ProcessInstanceModificationInstructionDto(org.camunda.bpm.engine.rest.dto.runtime.modification.ProcessInstanceModificationInstructionDto) ProcessInstantiationBuilder(org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder)

Example 7 with ProcessInstantiationBuilder

use of org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder in project camunda-bpm-platform by camunda.

the class ProcessDefinitionRestServiceInteractionTest method testProcessInstantiationAtActivitiesByKey.

@Test
public void testProcessInstantiationAtActivitiesByKey() {
    ProcessInstantiationBuilder mockInstantiationBuilder = setUpMockInstantiationBuilder();
    when(runtimeServiceMock.createProcessInstanceById(anyString())).thenReturn(mockInstantiationBuilder);
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("variables", VariablesBuilder.create().variable("processVariable", "aString", "String").getVariables());
    json.put("businessKey", "aBusinessKey");
    json.put("caseInstanceId", "aCaseInstanceId");
    List<Map<String, Object>> startInstructions = new ArrayList<Map<String, Object>>();
    startInstructions.add(ModificationInstructionBuilder.startBefore().activityId("activityId").variables(VariablesBuilder.create().variable("var", "value", "String", false).variable("varLocal", "valueLocal", "String", true).getVariables()).getJson());
    startInstructions.add(ModificationInstructionBuilder.startAfter().activityId("activityId").variables(VariablesBuilder.create().variable("var", 52, "Integer", false).variable("varLocal", 74, "Integer", true).getVariables()).getJson());
    startInstructions.add(ModificationInstructionBuilder.startTransition().transitionId("transitionId").variables(VariablesBuilder.create().variable("var", 53, "Integer", false).variable("varLocal", 75, "Integer", true).getVariables()).getJson());
    json.put("startInstructions", startInstructions);
    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));
    InOrder inOrder = inOrder(mockInstantiationBuilder);
    inOrder.verify(mockInstantiationBuilder).businessKey("aBusinessKey");
    inOrder.verify(mockInstantiationBuilder).caseInstanceId("aCaseInstanceId");
    inOrder.verify(mockInstantiationBuilder).setVariables(argThat(EqualsVariableMap.matches().matcher("processVariable", EqualsPrimitiveValue.stringValue("aString"))));
    inOrder.verify(mockInstantiationBuilder).startBeforeActivity("activityId");
    verify(mockInstantiationBuilder).setVariableLocal(eq("varLocal"), argThat(EqualsPrimitiveValue.stringValue("valueLocal")));
    verify(mockInstantiationBuilder).setVariable(eq("var"), argThat(EqualsPrimitiveValue.stringValue("value")));
    inOrder.verify(mockInstantiationBuilder).startAfterActivity("activityId");
    verify(mockInstantiationBuilder).setVariable(eq("var"), argThat(EqualsPrimitiveValue.integerValue(52)));
    verify(mockInstantiationBuilder).setVariableLocal(eq("varLocal"), argThat(EqualsPrimitiveValue.integerValue(74)));
    inOrder.verify(mockInstantiationBuilder).startTransition("transitionId");
    verify(mockInstantiationBuilder).setVariable(eq("var"), argThat(EqualsPrimitiveValue.integerValue(53)));
    verify(mockInstantiationBuilder).setVariableLocal(eq("varLocal"), argThat(EqualsPrimitiveValue.integerValue(75)));
    inOrder.verify(mockInstantiationBuilder).executeWithVariablesInReturn(false, false);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Matchers.anyString(org.mockito.Matchers.anyString) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessInstantiationBuilder(org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder) Test(org.junit.Test)

Example 8 with ProcessInstantiationBuilder

use of org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder in project camunda-bpm-platform by camunda.

the class ProcessDefinitionRestServiceInteractionTest method testProcessInstantiationWithTransientVariables.

@Test
public void testProcessInstantiationWithTransientVariables() throws IOException {
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("variables", VariablesBuilder.create().variableTransient("foo", "bar", "string").getVariables());
    final VariableMap varMap = new VariableMapImpl();
    when(mockInstantiationBuilder.setVariables(anyMapOf(String.class, Object.class))).thenAnswer(new Answer<ProcessInstantiationBuilder>() {

        @Override
        public ProcessInstantiationBuilder answer(InvocationOnMock invocation) throws Throwable {
            varMap.putAll((VariableMap) invocation.getArguments()[0]);
            return mockInstantiationBuilder;
        }
    });
    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);
    VariableMap expectedVariables = Variables.createVariables().putValueTyped("foo", Variables.stringValue("bar", true));
    verify(runtimeServiceMock).createProcessInstanceById(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID));
    verify(mockInstantiationBuilder).setVariables(expectedVariables);
    assertEquals(expectedVariables.getValueTyped("foo").isTransient(), varMap.getValueTyped("foo").isTransient());
    verify(mockInstantiationBuilder).executeWithVariablesInReturn(anyBoolean(), anyBoolean());
}
Also used : VariableMapImpl(org.camunda.bpm.engine.variable.impl.VariableMapImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) ProcessInstantiationBuilder(org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder) Test(org.junit.Test)

Aggregations

ProcessInstantiationBuilder (org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder)8 VariableMap (org.camunda.bpm.engine.variable.VariableMap)6 Test (org.junit.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)3 InOrder (org.mockito.InOrder)2 Response (com.jayway.restassured.response.Response)1 ProcessInstanceModificationInstructionDto (org.camunda.bpm.engine.rest.dto.runtime.modification.ProcessInstanceModificationInstructionDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 VariableMapImpl (org.camunda.bpm.engine.variable.impl.VariableMapImpl)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1