Search in sources :

Example 6 with ProcessInstanceWithVariables

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

the class DeleteProcessDefinitionTest method testDeleteProcessDefinitionAndRefillDeploymentCache.

@Test
public void testDeleteProcessDefinitionAndRefillDeploymentCache() {
    // given a deployment with two process definitions in one xml model file
    deployment = repositoryService.createDeployment().addClasspathResource("org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml").deploy();
    ProcessDefinition processDefinitionOne = repositoryService.createProcessDefinitionQuery().processDefinitionKey("one").singleResult();
    ProcessDefinition processDefinitionTwo = repositoryService.createProcessDefinitionQuery().processDefinitionKey("two").singleResult();
    String idOne = processDefinitionOne.getId();
    // one is deleted from the deployment
    repositoryService.deleteProcessDefinition(idOne);
    // when clearing the deployment cache
    processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache();
    // then creating process instance from the existing process definition
    ProcessInstanceWithVariables procInst = runtimeService.createProcessInstanceByKey("two").executeWithVariablesInReturn();
    assertNotNull(procInst);
    assertTrue(procInst.getProcessDefinitionId().contains("two"));
    // should refill the cache
    Cache cache = processEngineConfiguration.getDeploymentCache().getProcessDefinitionCache();
    assertNotNull(cache.get(processDefinitionTwo.getId()));
    // The deleted process definition should not be recreated after the cache is refilled
    assertNull(cache.get(processDefinitionOne.getId()));
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) Cache(org.camunda.commons.utils.cache.Cache) Test(org.junit.Test)

Example 7 with ProcessInstanceWithVariables

use of org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables 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 8 with ProcessInstanceWithVariables

use of org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables 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)

Example 9 with ProcessInstanceWithVariables

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

the class AbstractEmptyBodyFilterTest method setUpHttpClientAndRuntimeData.

@Before
public void setUpHttpClientAndRuntimeData() {
    client = HttpClients.createDefault();
    reqConfig = RequestConfig.custom().setConnectTimeout(3 * 60 * 1000).setSocketTimeout(10 * 60 * 1000).build();
    ProcessDefinition mockDefinition = MockProvider.createMockDefinition();
    runtimeServiceMock = mock(RuntimeService.class);
    when(processEngine.getRuntimeService()).thenReturn(runtimeServiceMock);
    mockInstantiationBuilder = mock(ProcessInstantiationBuilder.class);
    when(mockInstantiationBuilder.setVariables(any(Map.class))).thenReturn(mockInstantiationBuilder);
    when(mockInstantiationBuilder.businessKey(anyString())).thenReturn(mockInstantiationBuilder);
    when(mockInstantiationBuilder.caseInstanceId(anyString())).thenReturn(mockInstantiationBuilder);
    when(runtimeServiceMock.createProcessInstanceById(anyString())).thenReturn(mockInstantiationBuilder);
    ProcessInstanceWithVariables resultInstanceWithVariables = MockProvider.createMockInstanceWithVariables();
    when(mockInstantiationBuilder.executeWithVariablesInReturn(anyBoolean(), anyBoolean())).thenReturn(resultInstanceWithVariables);
    ProcessDefinitionQuery processDefinitionQueryMock = mock(ProcessDefinitionQuery.class);
    when(processDefinitionQueryMock.processDefinitionKey(MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY)).thenReturn(processDefinitionQueryMock);
    when(processDefinitionQueryMock.withoutTenantId()).thenReturn(processDefinitionQueryMock);
    when(processDefinitionQueryMock.latestVersion()).thenReturn(processDefinitionQueryMock);
    when(processDefinitionQueryMock.singleResult()).thenReturn(mockDefinition);
    RepositoryService repositoryServiceMock = mock(RepositoryService.class);
    when(processEngine.getRepositoryService()).thenReturn(repositoryServiceMock);
    when(repositoryServiceMock.createProcessDefinitionQuery()).thenReturn(processDefinitionQueryMock);
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessDefinitionQuery(org.camunda.bpm.engine.repository.ProcessDefinitionQuery) Map(java.util.Map) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) ProcessInstantiationBuilder(org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder) RepositoryService(org.camunda.bpm.engine.RepositoryService) Before(org.junit.Before)

Example 10 with ProcessInstanceWithVariables

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

the class ProcessInstantiationBuilderImpl method executeWithVariablesInReturn.

@Override
public ProcessInstanceWithVariables executeWithVariablesInReturn(boolean skipCustomListeners, boolean skipIoMappings) {
    ensureOnlyOneNotNull("either process definition id or key must be set", processDefinitionId, processDefinitionKey);
    if (isProcessDefinitionTenantIdSet && processDefinitionId != null) {
        throw LOG.exceptionStartProcessInstanceByIdAndTenantId();
    }
    Command<ProcessInstanceWithVariables> command;
    if (modificationBuilder.getModificationOperations().isEmpty()) {
        if (skipCustomListeners || skipIoMappings) {
            throw LOG.exceptionStartProcessInstanceAtStartActivityAndSkipListenersOrMapping();
        }
        // start at the default start activity
        command = new StartProcessInstanceCmd(this);
    } else {
        // start at any activity using the instructions
        modificationBuilder.setSkipCustomListeners(skipCustomListeners);
        modificationBuilder.setSkipIoMappings(skipIoMappings);
        command = new StartProcessInstanceAtActivitiesCmd(this);
    }
    return commandExecutor.execute(command);
}
Also used : StartProcessInstanceAtActivitiesCmd(org.camunda.bpm.engine.impl.cmd.StartProcessInstanceAtActivitiesCmd) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) StartProcessInstanceCmd(org.camunda.bpm.engine.impl.cmd.StartProcessInstanceCmd)

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