Search in sources :

Example 1 with ProcessInstantiationBuilder

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

the class ProcessDefinitionRestServiceInteractionTest method testSimpleProcessInstantiationWithVariables.

@Test
public void testSimpleProcessInstantiationWithVariables() {
    // mock process instance
    ProcessInstanceWithVariables mockInstance = MockProvider.createMockInstanceWithVariables();
    ProcessInstantiationBuilder mockInstantiationBuilder = setUpMockInstantiationBuilder();
    when(mockInstantiationBuilder.executeWithVariablesInReturn(anyBoolean(), anyBoolean())).thenReturn(mockInstance);
    when(runtimeServiceMock.createProcessInstanceById(anyString())).thenReturn(mockInstantiationBuilder);
    // given request with parameter withVariables to get variables in return
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("withVariablesInReturn", true);
    // when request then return process instance with serialized variables
    Response response = 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)).body("variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".value", equalTo(MockProvider.EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE)).body("variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".type", equalTo("Object")).body("variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".valueInfo.objectTypeName", equalTo(ArrayList.class.getName())).body("variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".valueInfo.serializationDataFormat", equalTo(MockProvider.FORMAT_APPLICATION_JSON)).body("variables." + MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".value", equalTo(MockProvider.EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE)).body("variables." + MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".type", equalTo("Object")).body("variables." + MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".valueInfo.objectTypeName", equalTo(Object.class.getName())).body("variables." + MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".valueInfo.serializationDataFormat", equalTo(MockProvider.FORMAT_APPLICATION_JSON)).when().post(START_PROCESS_INSTANCE_URL);
    verify(runtimeServiceMock).createProcessInstanceById(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID));
    verify(mockInstantiationBuilder).executeWithVariablesInReturn(anyBoolean(), anyBoolean());
}
Also used : Response(com.jayway.restassured.response.Response) Matchers.anyString(org.mockito.Matchers.anyString) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) ProcessInstantiationBuilder(org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder) Test(org.junit.Test)

Example 2 with ProcessInstantiationBuilder

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

the class ProcessDefinitionRestServiceInteractionTest method testProcessInstantiationAtActivitiesSkipIoMappingsAndListeners.

@Test
public void testProcessInstantiationAtActivitiesSkipIoMappingsAndListeners() {
    ProcessInstantiationBuilder mockInstantiationBuilder = setUpMockInstantiationBuilder();
    when(runtimeServiceMock.createProcessInstanceById(anyString())).thenReturn(mockInstantiationBuilder);
    Map<String, Object> json = new HashMap<String, Object>();
    List<Map<String, Object>> startInstructions = new ArrayList<Map<String, Object>>();
    startInstructions.add(ModificationInstructionBuilder.startBefore().activityId("activityId").getJson());
    json.put("startInstructions", startInstructions);
    json.put("skipIoMappings", true);
    json.put("skipCustomListeners", true);
    given().pathParam("id", 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(EXAMPLE_PROCESS_DEFINITION_ID));
    InOrder inOrder = inOrder(mockInstantiationBuilder);
    inOrder.verify(mockInstantiationBuilder).startBeforeActivity("activityId");
    inOrder.verify(mockInstantiationBuilder).executeWithVariablesInReturn(true, true);
    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 3 with ProcessInstantiationBuilder

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

the class ProcessDefinitionRestServiceInteractionTest method testInvalidInstantiationAtActivities.

@Test
public void testInvalidInstantiationAtActivities() {
    ProcessInstantiationBuilder mockInstantiationBuilder = setUpMockInstantiationBuilder();
    when(runtimeServiceMock.createProcessInstanceById(anyString())).thenReturn(mockInstantiationBuilder);
    Map<String, Object> json = new HashMap<String, Object>();
    // start before: missing activity id
    List<Map<String, Object>> instructions = new ArrayList<Map<String, Object>>();
    instructions.add(ModificationInstructionBuilder.startBefore().getJson());
    json.put("startInstructions", instructions);
    given().pathParam("id", EXAMPLE_PROCESS_DEFINITION_ID).contentType(ContentType.JSON).body(json).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("type", is(InvalidRequestException.class.getSimpleName())).body("message", containsString("'activityId' must be set")).when().post(START_PROCESS_INSTANCE_URL);
    // start after: missing ancestor activity instance id
    instructions = new ArrayList<Map<String, Object>>();
    instructions.add(ModificationInstructionBuilder.startAfter().getJson());
    json.put("startInstructions", instructions);
    given().pathParam("id", EXAMPLE_PROCESS_DEFINITION_ID).contentType(ContentType.JSON).body(json).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("type", is(InvalidRequestException.class.getSimpleName())).body("message", containsString("'activityId' must be set")).when().post(START_PROCESS_INSTANCE_URL);
    // start transition: missing ancestor activity instance id
    instructions = new ArrayList<Map<String, Object>>();
    instructions.add(ModificationInstructionBuilder.startTransition().getJson());
    json.put("startInstructions", instructions);
    given().pathParam("id", EXAMPLE_PROCESS_DEFINITION_ID).contentType(ContentType.JSON).body(json).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("type", is(InvalidRequestException.class.getSimpleName())).body("message", containsString("'transitionId' must be set")).when().post(START_PROCESS_INSTANCE_URL);
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) 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 4 with ProcessInstantiationBuilder

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

the class ProcessDefinitionRestServiceInteractionTest method setUpMockInstantiationBuilder.

@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;
}
Also used : ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessInstantiationBuilder(org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder)

Example 5 with ProcessInstantiationBuilder

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

the class ProcessDefinitionRestServiceInteractionTest method testProcessInstantiationAtActivitiesByIdWithVariablesInReturn.

@Test
public void testProcessInstantiationAtActivitiesByIdWithVariablesInReturn() {
    // set up variables and parameters
    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");
    VariableMap variables = createMockSerializedVariables().putValueTyped("processVariable", Variables.stringValue("aString")).putValueTyped("var", Variables.stringValue("value")).putValueTyped("varLocal", Variables.stringValue("valueLocal"));
    // mock process instance and instantiation builder
    ProcessInstanceWithVariables mockInstance = MockProvider.createMockInstanceWithVariables();
    when(mockInstance.getVariables()).thenReturn(variables);
    ProcessInstantiationBuilder mockInstantiationBuilder = setUpMockInstantiationBuilder();
    when(mockInstantiationBuilder.executeWithVariablesInReturn(anyBoolean(), anyBoolean())).thenReturn(mockInstance);
    when(runtimeServiceMock.createProcessInstanceById(anyString())).thenReturn(mockInstantiationBuilder);
    // create instructions
    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());
    json.put("startInstructions", startInstructions);
    json.put("withVariablesInReturn", true);
    // request which response should contain serialized variables of process instance
    given().pathParam("id", 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)).body("variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".value", equalTo(MockProvider.EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE)).body("variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".type", equalTo("Object")).body("variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".valueInfo.objectTypeName", equalTo(ArrayList.class.getName())).body("variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".valueInfo.serializationDataFormat", equalTo(MockProvider.FORMAT_APPLICATION_JSON)).body("variables." + MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".value", equalTo(MockProvider.EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE)).body("variables." + MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".type", equalTo("Object")).body("variables." + MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".valueInfo.objectTypeName", equalTo(Object.class.getName())).body("variables." + MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".valueInfo.serializationDataFormat", equalTo(MockProvider.FORMAT_APPLICATION_JSON)).body("variables.processVariable.type", equalTo("String")).body("variables.processVariable.value", equalTo("aString")).body("variables.var.type", equalTo("String")).body("variables.var.value", equalTo("value")).body("variables.varLocal.type", equalTo("String")).body("variables.varLocal.value", equalTo("valueLocal")).when().post(START_PROCESS_INSTANCE_URL);
    verify(runtimeServiceMock).createProcessInstanceById(eq(EXAMPLE_PROCESS_DEFINITION_ID));
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) Matchers.anyString(org.mockito.Matchers.anyString) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) VariableMap(org.camunda.bpm.engine.variable.VariableMap) 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