use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ScopingTest method run.
/**
* this code instantiates a business process that in turn delegates to a few Spring beans that in turn inject a process scoped object, {@link StatefulObject}.
*
* @return the StatefulObject that was injected across different components, that all share the same state.
* @throws Throwable if anythign goes wrong
*/
private StatefulObject run() throws Throwable {
logger.info("----------------------------------------------");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put(customerIdProcVarName, CUSTOMER_ID_PROC_VAR_VALUE);
ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("component-waiter", vars);
StatefulObject scopedObject = (StatefulObject) processEngine.getRuntimeService().getVariable(processInstance.getId(), "scopedTarget.c1");
Assert.assertNotNull("the scopedObject can't be null", scopedObject);
Assert.assertTrue("the 'name' property can't be null.", StringUtils.hasText(scopedObject.getName()));
Assert.assertEquals(scopedObject.getVisitedCount(), 2);
// the process has paused
String procId = processInstance.getProcessInstanceId();
List<Task> tasks = taskService.createTaskQuery().executionId(procId).list();
Assert.assertEquals("there should be 1 (one) task enqueued at this point.", tasks.size(), 1);
Task t = tasks.iterator().next();
this.taskService.claim(t.getId(), "me");
logger.info("sleeping for 10 seconds while a user performs his task. " + "The first transaction has committed. A new one will start in 10 seconds");
Thread.sleep(1000 * 5);
this.taskService.complete(t.getId());
scopedObject = (StatefulObject) processEngine.getRuntimeService().getVariable(processInstance.getId(), "scopedTarget.c1");
Assert.assertEquals(scopedObject.getVisitedCount(), 3);
Assert.assertEquals("the customerId injected should " + "be what was given as a processVariable parameter.", ScopingTest.CUSTOMER_ID_PROC_VAR_VALUE, scopedObject.getCustomerId());
return scopedObject;
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class JPASpringTest method testJpaVariableHappyPath.
@Deployment(resources = { "org/camunda/bpm/engine/spring/test/jpa/JPASpringTest.bpmn20.xml" })
public void testJpaVariableHappyPath() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("customerName", "John Doe");
variables.put("amount", 15000L);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("LoanRequestProcess", variables);
// Variable should be present containing the loanRequest created by the spring bean
Object value = runtimeService.getVariable(processInstance.getId(), "loanRequest");
assertNotNull(value);
assertTrue(value instanceof LoanRequest);
LoanRequest request = (LoanRequest) value;
assertEquals("John Doe", request.getCustomerName());
assertEquals(15000L, request.getAmount().longValue());
assertFalse(request.isApproved());
// We will approve the request, which will update the entity
variables = new HashMap<String, Object>();
variables.put("approvedByManager", Boolean.TRUE);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
taskService.complete(task.getId(), variables);
// If approved, the processsInstance should be finished, gateway based on loanRequest.approved value
assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ProcessStartingMethodInterceptor method invoke.
public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
StartProcess startProcess = AnnotationUtils.getAnnotation(method, StartProcess.class);
String processKey = startProcess.processKey();
Assert.hasText(processKey, "you must provide the name of process to start");
Object result;
try {
result = invocation.proceed();
Map<String, Object> vars = this.processVariablesFromAnnotations(invocation);
String businessKey = this.processBusinessKey(invocation);
log.info("variables for the started process: " + vars.toString());
RuntimeService runtimeService = this.processEngine.getRuntimeService();
ProcessInstance pi;
if (null != businessKey && StringUtils.hasText(businessKey)) {
pi = runtimeService.startProcessInstanceByKey(processKey, businessKey, vars);
log.info("the business key for the started process is '" + businessKey + "' ");
} else {
pi = runtimeService.startProcessInstanceByKey(processKey, vars);
}
String pId = pi.getId();
if (invocation.getMethod().getReturnType().equals(void.class))
return null;
if (shouldReturnProcessInstance(startProcess, invocation, result))
return pi;
if (shouldReturnProcessInstanceId(startProcess, invocation, result))
return pId;
if (shouldReturnAsyncResultWithProcessInstance(startProcess, invocation, result)) {
return new AsyncResult<ProcessInstance>(pi);
}
} catch (Throwable th) {
throw new RuntimeException(th);
}
return result;
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ServiceTaskSpringDelegationTest method testDelegateClassNotABean.
@Deployment
public void testDelegateClassNotABean() {
ProcessInstance procInst = runtimeService.startProcessInstanceByKey("delegateClassToSpringBean");
assertEquals("DelegateClassNotABean was called", runtimeService.getVariable(procInst.getId(), "message"));
assertTrue((Boolean) runtimeService.getVariable(procInst.getId(), "injectedFieldIsNull"));
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ServiceTaskSpringDelegationTest method testMethodExpressionOnSpringBean.
@Deployment
public void testMethodExpressionOnSpringBean() {
ProcessInstance procInst = runtimeService.startProcessInstanceByKey("methodExpressionOnSpringBean");
assertEquals("ACTIVITI BPMN 2.0 PROCESS ENGINE", runtimeService.getVariable(procInst.getId(), "myVar"));
}
Aggregations