Search in sources :

Example 1 with ProcessInstanceWithVariables

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

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

Example 3 with ProcessInstanceWithVariables

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;
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.RestartProcessInstanceDto) ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) StartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.StartProcessInstanceDto) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 4 with ProcessInstanceWithVariables

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

Example 5 with ProcessInstanceWithVariables

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

Aggregations

ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)16 VariableMap (org.camunda.bpm.engine.variable.VariableMap)10 Test (org.junit.Test)10 Deployment (org.camunda.bpm.engine.test.Deployment)7 ProcessInstantiationBuilder (org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder)4 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Response (com.jayway.restassured.response.Response)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 URI (java.net.URI)1 Map (java.util.Map)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 RepositoryService (org.camunda.bpm.engine.RepositoryService)1 RuntimeService (org.camunda.bpm.engine.RuntimeService)1 StartProcessInstanceAtActivitiesCmd (org.camunda.bpm.engine.impl.cmd.StartProcessInstanceAtActivitiesCmd)1 StartProcessInstanceCmd (org.camunda.bpm.engine.impl.cmd.StartProcessInstanceCmd)1 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)1 ProcessDefinitionQuery (org.camunda.bpm.engine.repository.ProcessDefinitionQuery)1