Search in sources :

Example 6 with BusinessProcess

use of org.activiti.cdi.BusinessProcess in project Activiti by Activiti.

the class BusinessProcessBeanTest method testResolveProcessInstanceBean.

@Test
@Deployment(resources = "org/activiti/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testResolveProcessInstanceBean() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    assertNull(getBeanInstance(ProcessInstance.class));
    assertNull(getBeanInstance("processInstanceId"));
    assertNull(getBeanInstance(Execution.class));
    assertNull(getBeanInstance("executionId"));
    String pid = businessProcess.startProcessByKey("businessProcessBeanTest").getId();
    // assert that now we can resolve the ProcessInstance-bean
    assertEquals(pid, getBeanInstance(ProcessInstance.class).getId());
    assertEquals(pid, getBeanInstance("processInstanceId"));
    assertEquals(pid, getBeanInstance(Execution.class).getId());
    assertEquals(pid, getBeanInstance("executionId"));
    taskService.complete(taskService.createTaskQuery().singleResult().getId());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) BusinessProcess(org.activiti.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Example 7 with BusinessProcess

use of org.activiti.cdi.BusinessProcess in project Activiti by Activiti.

the class TaskIdTest method testTaskIdInjectable.

@Test
@Deployment
public void testTaskIdInjectable() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    businessProcess.startProcessByKey("keyOfTheProcess");
    businessProcess.startTask(taskService.createTaskQuery().singleResult().getId());
    // assert that now the 'taskId'-bean can be looked up
    assertNotNull(getBeanInstance("taskId"));
    businessProcess.completeTask();
}
Also used : BusinessProcess(org.activiti.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Example 8 with BusinessProcess

use of org.activiti.cdi.BusinessProcess in project Activiti by Activiti.

the class BusinessProcessContext method get.

@Override
public <T> T get(Contextual<T> contextual) {
    Bean<T> bean = (Bean<T>) contextual;
    String variableName = bean.getName();
    BusinessProcess businessProcess = getBusinessProcess();
    Object variable = businessProcess.getVariable(variableName);
    if (variable != null) {
        if (logger.isDebugEnabled()) {
            if (businessProcess.isAssociated()) {
                logger.debug("Getting instance of bean '{}' from Execution[{}]", variableName, businessProcess.getExecutionId());
            } else {
                logger.debug("Getting instance of bean '{}' from transient bean store", variableName);
            }
        }
        return (T) variable;
    } else {
        return null;
    }
}
Also used : Bean(javax.enterprise.inject.spi.Bean) BusinessProcess(org.activiti.cdi.BusinessProcess)

Example 9 with BusinessProcess

use of org.activiti.cdi.BusinessProcess in project Activiti by Activiti.

the class CompleteTaskTest method testCompleteTask.

@Test
@Deployment(resources = "org/activiti/cdi/test/api/annotation/CompleteTaskTest.bpmn20.xml")
public void testCompleteTask() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    businessProcess.startProcessByKey("keyOfTheProcess");
    Task task = taskService.createTaskQuery().singleResult();
    // associate current unit of work with the task:
    businessProcess.startTask(task.getId());
    getBeanInstance(DeclarativeProcessController.class).completeTask();
    // assert that now the task is completed
    assertNull(taskService.createTaskQuery().singleResult());
}
Also used : Task(org.activiti.engine.task.Task) DeclarativeProcessController(org.activiti.cdi.test.impl.beans.DeclarativeProcessController) BusinessProcess(org.activiti.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Example 10 with BusinessProcess

use of org.activiti.cdi.BusinessProcess in project Activiti by Activiti.

the class StartProcessTest method testStartProcessByName.

@Test
@Deployment(resources = "org/activiti/cdi/test/api/annotation/StartProcessTest.bpmn20.xml")
public void testStartProcessByName() {
    assertNull(runtimeService.createProcessInstanceQuery().singleResult());
    getBeanInstance(DeclarativeProcessController.class).startProcessByName();
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    assertNotNull(runtimeService.createProcessInstanceQuery().singleResult());
    assertEquals("Activiti", businessProcess.getVariable("name"));
    businessProcess.startTask(taskService.createTaskQuery().singleResult().getId());
    businessProcess.completeTask();
}
Also used : DeclarativeProcessController(org.activiti.cdi.test.impl.beans.DeclarativeProcessController) BusinessProcess(org.activiti.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Aggregations

BusinessProcess (org.activiti.cdi.BusinessProcess)12 Deployment (org.activiti.engine.test.Deployment)10 Test (org.junit.Test)10 DeclarativeProcessController (org.activiti.cdi.test.impl.beans.DeclarativeProcessController)3 Task (org.activiti.engine.task.Task)3 Bean (javax.enterprise.inject.spi.Bean)2 HashMap (java.util.HashMap)1 CreditCard (org.activiti.cdi.test.impl.beans.CreditCard)1 Execution (org.activiti.engine.runtime.Execution)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 Ignore (org.junit.Ignore)1