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