Search in sources :

Example 21 with BusinessProcess

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

the class BusinessProcessBeanTest method testGetVariableLocal.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testGetVariableLocal() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    ProcessInstance processInstance = businessProcess.startProcessByKey("businessProcessBeanTest");
    TaskService taskService = getBeanInstance(TaskService.class);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    businessProcess.startTask(task.getId());
    businessProcess.setVariableLocal("aVariableName", "aVariableValue");
    // Flushing and re-getting should retain the value (CAM-1806):
    businessProcess.flushVariableCache();
    assertTrue(businessProcess.getCachedLocalVariableMap().isEmpty());
    assertEquals("aVariableValue", businessProcess.getVariableLocal("aVariableName"));
}
Also used : Task(org.camunda.bpm.engine.task.Task) TaskService(org.camunda.bpm.engine.TaskService) 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 22 with BusinessProcess

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

the class BusinessProcessBeanTest method testProcessWithoutWatestate.

@Test
@Deployment
public void testProcessWithoutWatestate() {
    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.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 23 with BusinessProcess

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

the class BusinessProcessBeanTest method testResolveTaskBean.

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

Example 24 with BusinessProcess

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

the class ProcessVariableMapTest method testProcessVariableMap.

@Test
public void testProcessVariableMap() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    VariableMap variables = (VariableMap) getBeanInstance("processVariableMap");
    assertNotNull(variables);
    // /////////////////////////////////////////////////////////////////
    // Put a variable via BusinessProcess and get it via VariableMap //
    // /////////////////////////////////////////////////////////////////
    String aValue = "aValue";
    businessProcess.setVariable(VARNAME_1, Variables.stringValue(aValue));
    // Legacy API
    assertEquals(aValue, variables.get(VARNAME_1));
    // Typed variable API
    TypedValue aTypedValue = variables.getValueTyped(VARNAME_1);
    assertEquals(ValueType.STRING, aTypedValue.getType());
    assertEquals(aValue, aTypedValue.getValue());
    assertEquals(aValue, variables.getValue(VARNAME_1, String.class));
    // Type API with wrong type
    try {
        variables.getValue(VARNAME_1, Integer.class);
        fail("ClassCastException expected!");
    } catch (ClassCastException ex) {
        assertEquals("Cannot cast variable named 'aVariable' with value 'aValue' to type 'class java.lang.Integer'.", ex.getMessage());
    }
    // /////////////////////////////////////////////////////////////////
    // Put a variable via VariableMap and get it via BusinessProcess //
    // /////////////////////////////////////////////////////////////////
    String anotherValue = "anotherValue";
    variables.put(VARNAME_2, Variables.stringValue(anotherValue));
    // Legacy API
    assertEquals(anotherValue, businessProcess.getVariable(VARNAME_2));
    // Typed variable API
    TypedValue anotherTypedValue = businessProcess.getVariableTyped(VARNAME_2);
    assertEquals(ValueType.STRING, anotherTypedValue.getType());
    assertEquals(anotherValue, anotherTypedValue.getValue());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Test(org.junit.Test)

Example 25 with BusinessProcess

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

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.camunda.bpm.engine.cdi.BusinessProcess) Ignore(org.junit.Ignore) 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