use of org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables 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.ProcessInstanceWithVariables in project camunda-bpm-platform by camunda.
the class MockProvider method createMockInstanceWithVariables.
public static ProcessInstanceWithVariables createMockInstanceWithVariables(String tenantId) {
ProcessInstanceWithVariables mock = mock(ProcessInstanceWithVariables.class);
when(mock.getId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID);
when(mock.getBusinessKey()).thenReturn(EXAMPLE_PROCESS_INSTANCE_BUSINESS_KEY);
when(mock.getCaseInstanceId()).thenReturn(EXAMPLE_CASE_INSTANCE_ID);
when(mock.getProcessDefinitionId()).thenReturn(EXAMPLE_PROCESS_DEFINITION_ID);
when(mock.getProcessInstanceId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID);
when(mock.isSuspended()).thenReturn(EXAMPLE_PROCESS_INSTANCE_IS_SUSPENDED);
when(mock.isEnded()).thenReturn(EXAMPLE_PROCESS_INSTANCE_IS_ENDED);
when(mock.getTenantId()).thenReturn(tenantId);
when(mock.getVariables()).thenReturn(createMockSerializedVariables());
return mock;
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables in project camunda-bpm-platform by camunda.
the class ProcessDefinitionResourceImpl method startProcessInstance.
@Override
public ProcessInstanceDto startProcessInstance(UriInfo context, StartProcessInstanceDto parameters) {
ProcessInstanceWithVariables instance = null;
try {
instance = startProcessInstanceAtActivities(parameters);
} catch (AuthorizationException e) {
throw e;
} catch (ProcessEngineException e) {
String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
} catch (RestException e) {
String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
throw new InvalidRequestException(e.getStatus(), e, errorMessage);
}
ProcessInstanceDto result;
if (parameters.isWithVariablesInReturn()) {
result = ProcessInstanceWithVariablesDto.fromProcessInstance(instance);
} else {
result = ProcessInstanceDto.fromProcessInstance(instance);
}
URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(ProcessInstanceRestService.PATH).path(instance.getId()).build();
result.addReflexiveLink(uri, HttpMethod.GET, "self");
return result;
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables in project camunda-bpm-platform by camunda.
the class ProcessInstantiationWithVariablesInReturnTest method testReturnVariablesFromStartWithWaitstate.
@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);
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables in project camunda-bpm-platform by camunda.
the class ProcessInstantiationWithVariablesInReturnTest method testReturnVariablesFromStartAndExecution.
@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);
}
Aggregations