Search in sources :

Example 1 with InvocationContext

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();
        }
    }
}
Also used : ProcessApplicationReference(org.camunda.bpm.application.ProcessApplicationReference) InvocationContext(org.camunda.bpm.application.InvocationContext)

Example 2 with InvocationContext

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()));
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) InvocationContext(org.camunda.bpm.application.InvocationContext) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 3 with InvocationContext

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()));
}
Also used : Job(org.camunda.bpm.engine.runtime.Job) InvocationContext(org.camunda.bpm.application.InvocationContext) Date(java.util.Date) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 4 with InvocationContext

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()));
}
Also used : EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) InvocationContext(org.camunda.bpm.application.InvocationContext) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 5 with InvocationContext

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));
}
Also used : ProcessApplicationReference(org.camunda.bpm.application.ProcessApplicationReference) BaseDelegateExecution(org.camunda.bpm.engine.delegate.BaseDelegateExecution) TestApplicationWithoutEngine(org.camunda.bpm.application.impl.embedded.TestApplicationWithoutEngine) InvocationContext(org.camunda.bpm.application.InvocationContext) Callable(java.util.concurrent.Callable)

Aggregations

InvocationContext (org.camunda.bpm.application.InvocationContext)7 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)4 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)4 Test (org.junit.Test)4 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 Date (java.util.Date)1 Callable (java.util.concurrent.Callable)1 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)1 TestApplicationWithoutEngine (org.camunda.bpm.application.impl.embedded.TestApplicationWithoutEngine)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 BaseDelegateExecution (org.camunda.bpm.engine.delegate.BaseDelegateExecution)1 EventSubscription (org.camunda.bpm.engine.runtime.EventSubscription)1 Execution (org.camunda.bpm.engine.runtime.Execution)1 Job (org.camunda.bpm.engine.runtime.Job)1