Search in sources :

Example 16 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testGetCachedLocalVariableMap.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testGetCachedLocalVariableMap() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getCachedLocalVariableMap());
    // set a variable - this should fail before the process is started
    try {
        businessProcess.setVariableLocal("aVariableName", "aVariableValue");
        fail("exception expected!");
    } catch (ProcessEngineCdiException e) {
        assertEquals("Cannot set a local cached variable: neither a Task nor an Execution is associated.", e.getMessage());
    }
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // now the variable cache is empty again:
    assertEquals(Collections.EMPTY_MAP, businessProcess.getCachedLocalVariableMap());
    // set a variable
    businessProcess.setVariableLocal("anotherVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getCachedLocalVariableMap());
    // getting the variable cache does not empty it:
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getCachedLocalVariableMap());
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 17 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testResolveProcessInstanceBean.

@Test
@Deployment(resources = "org/camunda/bpm/engine/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.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 18 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testGetAndClearVariableCache.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
@SuppressWarnings("deprecation")
public void testGetAndClearVariableCache() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearVariableCache());
    // set a variable
    businessProcess.setVariable("aVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("aVariableName", "aVariableValue"), businessProcess.getAndClearVariableCache());
    // now the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearVariableCache());
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // now the variable cache is empty again:
    assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableCache());
    // set a variable
    businessProcess.setVariable("anotherVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getVariableCache());
}
Also used : BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 19 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testGetVariableLocalCache.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
@SuppressWarnings("deprecation")
public void testGetVariableLocalCache() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableLocalCache());
    // set a variable - this should fail before the process is started
    try {
        businessProcess.setVariableLocal("aVariableName", "aVariableValue");
        fail("exception expected!");
    } catch (ProcessEngineCdiException e) {
        assertEquals("Cannot set a local cached variable: neither a Task nor an Execution is associated.", e.getMessage());
    }
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // now the variable cache is empty again:
    assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableLocalCache());
    // set a variable
    businessProcess.setVariableLocal("anotherVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getVariableLocalCache());
    // getting the variable cache does not empty it:
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getVariableLocalCache());
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 20 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

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", Variables.stringValue(value));
    assertEquals(value, businessProcess.getVariable("key"));
    // Typed variable API
    TypedValue typedValue = businessProcess.getVariableTyped("key");
    assertEquals(ValueType.STRING, typedValue.getType());
    assertEquals(value, typedValue.getValue());
    // Local variables
    String localValue = "localValue";
    businessProcess.setVariableLocal("localKey", Variables.stringValue(localValue));
    assertEquals(localValue, businessProcess.getVariableLocal("localKey"));
    // Local typed variable API
    TypedValue typedLocalValue = businessProcess.getVariableLocalTyped("localKey");
    assertEquals(ValueType.STRING, typedLocalValue.getType());
    assertEquals(localValue, typedLocalValue.getValue());
    // 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.camunda.bpm.engine.task.Task) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

BusinessProcess (org.camunda.bpm.engine.cdi.BusinessProcess)28 Test (org.junit.Test)26 Deployment (org.camunda.bpm.engine.test.Deployment)25 ProcessEngineCdiException (org.camunda.bpm.engine.cdi.ProcessEngineCdiException)7 Task (org.camunda.bpm.engine.task.Task)6 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)6 DeclarativeProcessController (org.camunda.bpm.engine.cdi.test.impl.beans.DeclarativeProcessController)4 VariableMap (org.camunda.bpm.engine.variable.VariableMap)4 StringValue (org.camunda.bpm.engine.variable.value.StringValue)3 Bean (javax.enterprise.inject.spi.Bean)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 HashMap (java.util.HashMap)1 TaskService (org.camunda.bpm.engine.TaskService)1 CreditCard (org.camunda.bpm.engine.cdi.test.impl.beans.CreditCard)1 Execution (org.camunda.bpm.engine.runtime.Execution)1 Ignore (org.junit.Ignore)1