use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceQueryTest method testInstanceRetrievalByListWithDuplicate.
@Test
public void testInstanceRetrievalByListWithDuplicate() {
List<ProcessInstance> mockProcessInstanceList = new ArrayList<ProcessInstance>();
mockProcessInstanceList.add(MockProvider.createMockInstance());
mockProcessInstanceList.add(MockProvider.createAnotherMockInstance());
ProcessInstanceQuery instanceQuery = mock(ProcessInstanceQuery.class);
when(instanceQuery.list()).thenReturn(mockProcessInstanceList);
when(processEngine.getRuntimeService().createProcessInstanceQuery()).thenReturn(instanceQuery);
Response response = given().queryParam("processInstanceIds", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID_LIST_WITH_DUP).then().expect().statusCode(Status.OK.getStatusCode()).when().get(PROCESS_INSTANCE_QUERY_URL);
// assert query invocation
InOrder inOrder = Mockito.inOrder(instanceQuery);
Set<String> expectedSet = MockProvider.createMockSetFromList(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID_LIST);
inOrder.verify(instanceQuery).processInstanceIds(expectedSet);
inOrder.verify(instanceQuery).list();
String content = response.asString();
List<String> instances = from(content).getList("");
Assert.assertEquals("There should be two process definitions returned.", 2, instances.size());
String returnedInstanceId1 = from(content).getString("[0].id");
String returnedInstanceId2 = from(content).getString("[1].id");
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID, returnedInstanceId1);
Assert.assertEquals(MockProvider.ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID, returnedInstanceId2);
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceQueryTest method testInstanceRetrievalByList.
@Test
public void testInstanceRetrievalByList() {
List<ProcessInstance> mockProcessInstanceList = new ArrayList<ProcessInstance>();
mockProcessInstanceList.add(MockProvider.createMockInstance());
mockProcessInstanceList.add(MockProvider.createAnotherMockInstance());
ProcessInstanceQuery instanceQuery = mock(ProcessInstanceQuery.class);
when(processEngine.getRuntimeService().createProcessInstanceQuery()).thenReturn(instanceQuery);
when(instanceQuery.list()).thenReturn(mockProcessInstanceList);
Response response = given().queryParam("processInstanceIds", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID_LIST).then().expect().statusCode(Status.OK.getStatusCode()).when().get(PROCESS_INSTANCE_QUERY_URL);
// assert query invocation
InOrder inOrder = Mockito.inOrder(instanceQuery);
Set<String> expectedSet = MockProvider.createMockSetFromList(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID_LIST);
inOrder.verify(instanceQuery).processInstanceIds(expectedSet);
inOrder.verify(instanceQuery).list();
String content = response.asString();
List<String> instances = from(content).getList("");
Assert.assertEquals("There should be two process definitions returned.", 2, instances.size());
String returnedInstanceId1 = from(content).getString("[0].id");
String returnedInstanceId2 = from(content).getString("[1].id");
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID, returnedInstanceId1);
Assert.assertEquals(MockProvider.ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID, returnedInstanceId2);
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class BusinessProcess method startProcessById.
public ProcessInstance startProcessById(String processDefinitionId, Map<String, Object> variables) {
assertCommandContextNotActive();
VariableMap cachedVariables = getAndClearCachedVariableMap();
cachedVariables.putAll(variables);
ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId, cachedVariables);
if (!instance.isEnded()) {
setExecution(instance);
}
return instance;
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class MockProvider method createMockInstance.
public static ProcessInstance createMockInstance(String tenantId) {
ProcessInstance mock = mock(ProcessInstance.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);
return mock;
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class CorrelateStartMessageCmd method execute.
public ProcessInstance execute(final CommandContext commandContext) {
ensureNotNull("messageName", messageName);
final CorrelationHandler correlationHandler = Context.getProcessEngineConfiguration().getCorrelationHandler();
final CorrelationSet correlationSet = new CorrelationSet(builder);
List<CorrelationHandlerResult> correlationResults = commandContext.runWithoutAuthorization(new Callable<List<CorrelationHandlerResult>>() {
public List<CorrelationHandlerResult> call() throws Exception {
return correlationHandler.correlateStartMessages(commandContext, messageName, correlationSet);
}
});
if (correlationResults.isEmpty()) {
throw new MismatchingMessageCorrelationException(messageName, "No process definition matches the parameters");
} else if (correlationResults.size() > 1) {
throw LOG.exceptionCorrelateMessageToSingleProcessDefinition(messageName, correlationResults.size(), correlationSet);
} else {
CorrelationHandlerResult correlationResult = correlationResults.get(0);
checkAuthorization(correlationResult);
ProcessInstance processInstance = instantiateProcess(commandContext, correlationResult);
return processInstance;
}
}
Aggregations