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());
}
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();
}
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);
}
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;
}
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));
}
Aggregations