Search in sources :

Example 21 with Expression

use of org.camunda.bpm.engine.delegate.Expression in project camunda-bpm-platform by camunda.

the class CaseVariableListenerHandlerTest method testClassDelegateHandling.

@Test
public void testClassDelegateHandling() {
    ExtensionElements extensionElements = SpecUtil.createElement(modelInstance, caseTask, null, ExtensionElements.class);
    CamundaVariableListener variableListener = SpecUtil.createElement(modelInstance, extensionElements, null, CamundaVariableListener.class);
    CamundaField field = SpecUtil.createElement(modelInstance, variableListener, null, CamundaField.class);
    field.setCamundaName("fieldName");
    field.setCamundaStringValue("a string value");
    variableListener.setCamundaClass("a.class.Name");
    // when
    CmmnActivity activity = handler.handleElement(planItem, context);
    List<VariableListener<?>> listeners = activity.getVariableListenersLocal(CaseVariableListener.CREATE);
    Assert.assertEquals(1, listeners.size());
    ClassDelegateCaseVariableListener listener = (ClassDelegateCaseVariableListener) listeners.get(0);
    Assert.assertEquals("a.class.Name", listener.getClassName());
    Assert.assertEquals(1, listener.getFieldDeclarations().size());
    Assert.assertEquals("fieldName", listener.getFieldDeclarations().get(0).getName());
    Object fieldValue = listener.getFieldDeclarations().get(0).getValue();
    assertTrue(fieldValue instanceof Expression);
    Expression expressionValue = (Expression) fieldValue;
    assertEquals("a string value", expressionValue.getExpressionText());
    Assert.assertEquals(listener, activity.getVariableListenersLocal(CaseVariableListener.UPDATE).get(0));
    Assert.assertEquals(listener, activity.getVariableListenersLocal(CaseVariableListener.DELETE).get(0));
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) CamundaField(org.camunda.bpm.model.cmmn.instance.camunda.CamundaField) CamundaVariableListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener) CaseVariableListener(org.camunda.bpm.engine.delegate.CaseVariableListener) ExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ExpressionCaseVariableListener) DelegateExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.DelegateExpressionCaseVariableListener) CamundaVariableListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener) VariableListener(org.camunda.bpm.engine.delegate.VariableListener) ClassDelegateCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener) Expression(org.camunda.bpm.engine.delegate.Expression) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) ClassDelegateCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener) Test(org.junit.Test)

Example 22 with Expression

use of org.camunda.bpm.engine.delegate.Expression in project camunda-bpm-platform by camunda.

the class TaskDecoratorTest method testDecoratePriority.

public void testDecoratePriority() {
    // given
    String aPriority = "10";
    Expression priorityExpression = expressionManager.createExpression(aPriority);
    taskDefinition.setPriorityExpression(priorityExpression);
    // when
    decorate(task, taskDecorator);
    // then
    assertEquals(Integer.parseInt(aPriority), task.getPriority());
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression)

Example 23 with Expression

use of org.camunda.bpm.engine.delegate.Expression in project camunda-bpm-platform by camunda.

the class TaskDecoratorTest method testDecorateCandidateUsers.

public void testDecorateCandidateUsers() {
    // given
    List<String> aCandidateUserList = new ArrayList<String>();
    aCandidateUserList.add("john");
    aCandidateUserList.add("peter");
    aCandidateUserList.add("mary");
    for (String candidateUser : aCandidateUserList) {
        Expression candidateUserExpression = expressionManager.createExpression(candidateUser);
        taskDefinition.addCandidateUserIdExpression(candidateUserExpression);
    }
    // when
    decorate(task, taskDecorator);
    // then
    Set<IdentityLink> candidates = task.getCandidates();
    assertEquals(3, candidates.size());
    for (IdentityLink identityLink : candidates) {
        String taskId = identityLink.getTaskId();
        assertEquals(task.getId(), taskId);
        assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
        String userId = identityLink.getUserId();
        if ("john".equals(userId)) {
            assertEquals("john", userId);
        } else if ("peter".equals(userId)) {
            assertEquals("peter", userId);
        } else if ("mary".equals(userId)) {
            assertEquals("mary", userId);
        } else {
            fail("Unexpected user: " + userId);
        }
    }
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression) ArrayList(java.util.ArrayList) IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Example 24 with Expression

use of org.camunda.bpm.engine.delegate.Expression in project camunda-bpm-platform by camunda.

the class TaskDecoratorTest method testDecorateAssigneeFromVariable.

public void testDecorateAssigneeFromVariable() {
    // given
    String aAssignee = "john";
    taskService.setVariable(task.getId(), "assignee", aAssignee);
    Expression assigneeExpression = expressionManager.createExpression("${assignee}");
    taskDefinition.setAssigneeExpression(assigneeExpression);
    // when
    decorate(task, taskDecorator);
    // then
    assertEquals(aAssignee, task.getAssignee());
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression)

Example 25 with Expression

use of org.camunda.bpm.engine.delegate.Expression in project camunda-bpm-platform by camunda.

the class TaskDecoratorTest method testDecorateDescription.

public void testDecorateDescription() {
    // given
    String aDescription = "This is a Task";
    Expression descriptionExpression = expressionManager.createExpression(aDescription);
    taskDefinition.setDescriptionExpression(descriptionExpression);
    // when
    decorate(task, taskDecorator);
    // then
    assertEquals(aDescription, task.getDescription());
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression)

Aggregations

Expression (org.camunda.bpm.engine.delegate.Expression)62 ConditionExpression (org.camunda.bpm.model.cmmn.instance.ConditionExpression)18 Test (org.junit.Test)15 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)14 ExpressionManager (org.camunda.bpm.engine.impl.el.ExpressionManager)14 HumanTaskActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior)12 TaskDefinition (org.camunda.bpm.engine.impl.task.TaskDefinition)12 HumanTask (org.camunda.bpm.model.cmmn.instance.HumanTask)8 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 CmmnIfPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration)4 IdentityLink (org.camunda.bpm.engine.task.IdentityLink)4 CamundaField (org.camunda.bpm.model.cmmn.instance.camunda.CamundaField)4 FieldDeclaration (org.camunda.bpm.engine.impl.bpmn.parser.FieldDeclaration)3 CaseControlRuleImpl (org.camunda.bpm.engine.impl.cmmn.behavior.CaseControlRuleImpl)3 CmmnSentryDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration)3 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)3 CamundaExpression (org.camunda.bpm.model.cmmn.instance.camunda.CamundaExpression)3 CamundaString (org.camunda.bpm.model.cmmn.instance.camunda.CamundaString)3 Collection (java.util.Collection)2