use of org.camunda.bpm.application.InvocationContext in project camunda-bpm-platform by camunda.
the class CommandContext method performOperation.
public void performOperation(final CmmnAtomicOperation executionOperation, final CaseExecutionEntity execution) {
ProcessApplicationReference targetProcessApplication = getTargetProcessApplication(execution);
if (requiresContextSwitch(targetProcessApplication)) {
Context.executeWithinProcessApplication(new Callable<Void>() {
public Void call() throws Exception {
performOperation(executionOperation, execution);
return null;
}
}, targetProcessApplication, new InvocationContext(execution));
} else {
try {
Context.setExecutionContext(execution);
LOG.debugExecutingAtomicOperation(executionOperation, execution);
executionOperation.execute(execution);
} finally {
Context.removeExecutionContext();
}
}
}
use of org.camunda.bpm.application.InvocationContext in project camunda-bpm-platform by camunda.
the class InvocationContextTest method testInvokeProcessApplicationWithContextOnSignalTask.
@Test
@OperateOnDeployment("app")
public void testInvokeProcessApplicationWithContextOnSignalTask() {
runtimeService.startProcessInstanceByKey("signalableProcess");
ProcessApplicationWithInvocationContext.clearInvocationContext();
Execution execution = runtimeService.createExecutionQuery().activityId("waitingTask").singleResult();
assertThat(execution, is(notNullValue()));
runtimeService.signal(execution.getId());
InvocationContext invocationContext = ProcessApplicationWithInvocationContext.getInvocationContext();
assertThat(invocationContext, is(notNullValue()));
assertThat(invocationContext.getExecution(), is(notNullValue()));
assertThat(invocationContext.getExecution().getId(), is(execution.getId()));
}
use of org.camunda.bpm.application.InvocationContext in project camunda-bpm-platform by camunda.
the class InvocationContextTest method testInvokeProcessApplicationWithContextOnAsyncExecution.
@Test
@OperateOnDeployment("app")
public void testInvokeProcessApplicationWithContextOnAsyncExecution() {
runtimeService.startProcessInstanceByKey("timerProcess");
ProcessApplicationWithInvocationContext.clearInvocationContext();
Job timer = managementService.createJobQuery().timers().singleResult();
assertThat(timer, is(notNullValue()));
long dueDate = timer.getDuedate().getTime();
Date afterDueDate = new Date(dueDate + 1000 * 60);
ClockUtil.setCurrentTime(afterDueDate);
waitForJobExecutorToProcessAllJobs();
InvocationContext invocationContext = ProcessApplicationWithInvocationContext.getInvocationContext();
assertThat(invocationContext, is(notNullValue()));
assertThat(invocationContext.getExecution(), is(notNullValue()));
assertThat(invocationContext.getExecution().getId(), is(timer.getExecutionId()));
}
use of org.camunda.bpm.application.InvocationContext in project camunda-bpm-platform by camunda.
the class InvocationContextTest method testInvokeProcessApplicationWithContextOnMessageReceived.
@Test
@OperateOnDeployment("app")
public void testInvokeProcessApplicationWithContextOnMessageReceived() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageProcess");
ProcessApplicationWithInvocationContext.clearInvocationContext();
EventSubscription messageSubscription = runtimeService.createEventSubscriptionQuery().eventType("message").processInstanceId(processInstance.getId()).singleResult();
assertThat(messageSubscription, is(notNullValue()));
runtimeService.messageEventReceived(messageSubscription.getEventName(), messageSubscription.getExecutionId());
InvocationContext invocationContext = ProcessApplicationWithInvocationContext.getInvocationContext();
assertThat(invocationContext, is(notNullValue()));
assertThat(invocationContext.getExecution(), is(notNullValue()));
assertThat(invocationContext.getExecution().getId(), is(messageSubscription.getExecutionId()));
}
use of org.camunda.bpm.application.InvocationContext in project camunda-bpm-platform by camunda.
the class ProcessApplicationContextTest method testExecuteWithInvocationContext.
@SuppressWarnings("unchecked")
public void testExecuteWithInvocationContext() throws Exception {
// given a process application which extends the default one
// - using a spy for verify the invocations
TestApplicationWithoutEngine processApplication = spy(pa);
ProcessApplicationReference processApplicationReference = mock(ProcessApplicationReference.class);
when(processApplicationReference.getProcessApplication()).thenReturn(processApplication);
// when execute with context
InvocationContext invocationContext = new InvocationContext(mock(BaseDelegateExecution.class));
Context.executeWithinProcessApplication(mock(Callable.class), processApplicationReference, invocationContext);
// then the execute method should be invoked with context
verify(processApplication).execute(any(Callable.class), eq(invocationContext));
// and forward to call to the default execute method
verify(processApplication).execute(any(Callable.class));
}
Aggregations