Search in sources :

Example 1 with BusinessProcess

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

the class BusinessProcessBeanTest method testResolveTaskBean.

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

Example 2 with BusinessProcess

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

the class BusinessProcessBeanTest method testProcessWithoutWaitState.

@Test
@Deployment
public void testProcessWithoutWaitState() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // start the process
    businessProcess.startProcessByKey("businessProcessBeanTest").getId();
    // assert that the process is ended:
    assertNull(processEngine.getRuntimeService().createProcessInstanceQuery().singleResult());
}
Also used : BusinessProcess(org.activiti.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Example 3 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, CreationalContext<T> arg1) {
    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 {
        if (logger.isDebugEnabled()) {
            if (businessProcess.isAssociated()) {
                logger.debug("Creating instance of bean '{}' in business process context representing Execution[{}]", variableName, businessProcess.getExecutionId());
            } else {
                logger.debug("Creating instance of bean '{}' in transient bean store", variableName);
            }
        }
        T beanInstance = bean.create(arg1);
        businessProcess.setVariable(variableName, beanInstance);
        return beanInstance;
    }
}
Also used : Bean(javax.enterprise.inject.spi.Bean) BusinessProcess(org.activiti.cdi.BusinessProcess)

Example 4 with BusinessProcess

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

the class ProcessVariablesTest method testResolveString.

@Ignore
@Test
@Deployment(resources = "org/activiti/cdi/BusinessProcessBeanTest.test.bpmn20.xml")
public void testResolveString() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    Map<String, Object> processVariables = new HashMap<String, Object>();
    businessProcess.setVariable("testKeyString", "testValue");
    businessProcess.startProcessByKey("businessProcessBeanTest", processVariables);
    businessProcess.startTask(taskService.createTaskQuery().singleResult().getId());
    InjectProcessVariable injectProcessVariables = getBeanInstance(InjectProcessVariable.class);
    assertEquals("testValue", injectProcessVariables.testKeyString);
    businessProcess.completeTask();
}
Also used : HashMap(java.util.HashMap) BusinessProcess(org.activiti.cdi.BusinessProcess) Ignore(org.junit.Ignore) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Example 5 with BusinessProcess

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

the class BusinessProcessBeanTest method test.

/* General test asserting that the business process bean is functional */
@Test
@Deployment
public void test() throws Exception {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // start the process
    businessProcess.startProcessByKey("businessProcessBeanTest").getId();
    // ensure that the process is started:
    assertNotNull(processEngine.getRuntimeService().createProcessInstanceQuery().singleResult());
    // ensure that there is a single task waiting
    Task task = processEngine.getTaskService().createTaskQuery().singleResult();
    assertNotNull(task);
    String value = "value";
    businessProcess.setVariable("key", value);
    assertEquals(value, businessProcess.getVariable("key"));
    // complete the task
    assertEquals(task.getId(), businessProcess.startTask(task.getId()).getId());
    businessProcess.completeTask();
    // assert the task is completed
    assertNull(processEngine.getTaskService().createTaskQuery().singleResult());
    // assert that the process is ended:
    assertNull(processEngine.getRuntimeService().createProcessInstanceQuery().singleResult());
}
Also used : Task(org.activiti.engine.task.Task) 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