Search in sources :

Example 6 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testGetAndClearCachedVariableMap.

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

Example 7 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testSaveTask.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testSaveTask() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // cannot save task in absence of an association:
    try {
        businessProcess.saveTask();
        fail();
    } catch (ProcessEngineCdiException e) {
        assertEquals("No task associated. Call businessProcess.startTask() first.", e.getMessage());
    }
    // start the process
    String processInstanceId = businessProcess.startProcessByKey("businessProcessBeanTest", Collections.singletonMap("key", (Object) "value")).getId();
    assertEquals("value", runtimeService.getVariable(processInstanceId, "key"));
    businessProcess.startTask(taskService.createTaskQuery().singleResult().getId());
    // assignee is not set to jonny
    assertNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());
    Task task = businessProcess.getTask();
    task.setAssignee("jonny");
    assertNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());
    // if we save the task
    businessProcess.saveTask();
    // THEN
    // assignee is now set to jonny
    assertNotNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());
    // business process is still associated with task:
    assertTrue(businessProcess.isTaskAssociated());
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) 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 8 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testGetAndClearVariableLocalCache.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
@SuppressWarnings("deprecation")
public void testGetAndClearVariableLocalCache() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearVariableLocalCache());
    // 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());
    }
    // the variable cache is still empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearVariableLocalCache());
    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());
}
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 9 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class ProcessVariableMapTest method testProcessVariableMapLocal.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testProcessVariableMapLocal() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    businessProcess.startProcessByKey("businessProcessBeanTest");
    VariableMap variables = (VariableMap) getBeanInstance("processVariableMapLocal");
    assertNotNull(variables);
    // /////////////////////////////////////////////////////////////////
    // Put a variable via BusinessProcess and get it via VariableMap //
    // /////////////////////////////////////////////////////////////////
    String aValue = "aValue";
    businessProcess.setVariableLocal(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.getVariableLocal(VARNAME_2));
    // Typed variable API
    TypedValue anotherTypedValue = businessProcess.getVariableLocalTyped(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) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class ExecutionIdTest method testExecutionIdInjectableByQualifier.

@Test
@Deployment
public void testExecutionIdInjectableByQualifier() {
    getBeanInstance(BusinessProcess.class).startProcessByKey("keyOfTheProcess");
    Set<Bean<?>> beans = beanManager.getBeans(String.class, new ExecutionIdLiteral());
    Bean<String> bean = (Bean<java.lang.String>) beanManager.resolve(beans);
    CreationalContext<String> ctx = beanManager.createCreationalContext(bean);
    String executionId = (String) beanManager.getReference(bean, String.class, ctx);
    Assert.assertNotNull(executionId);
    String processInstanceId = (String) getBeanInstance("processInstanceId");
    Assert.assertNotNull(processInstanceId);
    assertEquals(processInstanceId, executionId);
}
Also used : ExecutionIdLiteral(org.camunda.bpm.engine.cdi.annotation.ExecutionIdLiteral) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Deployment (org.camunda.bpm.engine.test.Deployment)3376 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1325 Task (org.camunda.bpm.engine.task.Task)788 Test (org.junit.Test)635 HashMap (java.util.HashMap)441 Job (org.camunda.bpm.engine.runtime.Job)310 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)277 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)265 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)256 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)251 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)230 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)206 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)195 Execution (org.camunda.bpm.engine.runtime.Execution)189 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)175 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)161 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)149 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)143 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)134 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)134