use of org.camunda.bpm.engine.impl.task.TaskDefinition in project camunda-bpm-platform by camunda.
the class HumanTaskPlanItemHandlerTest method testAssignmentTaskListenerByExpression.
@Test
public void testAssignmentTaskListenerByExpression() {
// given:
ExtensionElements extensionElements = addExtensionElements(humanTask);
CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
String expression = "${myExpression}";
String event = TaskListener.EVENTNAME_ASSIGNMENT;
taskListener.setCamundaEvent(event);
taskListener.setCamundaExpression(expression);
// when
CmmnActivity activity = handler.handleElement(planItem, context);
// then
assertEquals(0, activity.getListeners().size());
HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
TaskDefinition taskDefinition = behavior.getTaskDefinition();
assertNotNull(taskDefinition);
assertEquals(1, taskDefinition.getTaskListeners().size());
List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
assertEquals(1, createListeners.size());
TaskListener listener = createListeners.get(0);
assertTrue(listener instanceof ExpressionTaskListener);
ExpressionTaskListener expressionListener = (ExpressionTaskListener) listener;
assertEquals(expression, expressionListener.getExpressionText());
}
use of org.camunda.bpm.engine.impl.task.TaskDefinition in project camunda-bpm-platform by camunda.
the class HumanTaskPlanItemHandlerTest method testTaskDefinitionCandidateUsers.
@Test
public void testTaskDefinitionCandidateUsers() {
// given
String aCandidateUsers = "mary,john,peter";
humanTask.setCamundaCandidateUsers(aCandidateUsers);
// when
CmmnActivity activity = handler.handleElement(planItem, context);
// then
HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
TaskDefinition taskDefinition = behavior.getTaskDefinition();
Set<Expression> candidateUserExpressions = taskDefinition.getCandidateUserIdExpressions();
assertEquals(3, candidateUserExpressions.size());
for (Expression candidateUserExpression : candidateUserExpressions) {
String candidateUser = candidateUserExpression.getExpressionText();
if ("mary".equals(candidateUser)) {
assertEquals("mary", candidateUser);
} else if ("john".equals(candidateUser)) {
assertEquals("john", candidateUser);
} else if ("peter".equals(candidateUser)) {
assertEquals("peter", candidateUser);
} else {
fail("Unexpected candidate user: " + candidateUser);
}
}
}
use of org.camunda.bpm.engine.impl.task.TaskDefinition in project camunda-bpm-platform by camunda.
the class HumanTaskPlanItemHandlerTest method testCreateTaskListenerByDelegateExpression.
@Test
public void testCreateTaskListenerByDelegateExpression() {
// given:
ExtensionElements extensionElements = addExtensionElements(humanTask);
CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
String delegateExpression = "${myDelegateExpression}";
String event = TaskListener.EVENTNAME_CREATE;
taskListener.setCamundaEvent(event);
taskListener.setCamundaDelegateExpression(delegateExpression);
// when
CmmnActivity activity = handler.handleElement(planItem, context);
// then
assertEquals(0, activity.getListeners().size());
HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
TaskDefinition taskDefinition = behavior.getTaskDefinition();
assertNotNull(taskDefinition);
assertEquals(1, taskDefinition.getTaskListeners().size());
List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
assertEquals(1, createListeners.size());
TaskListener listener = createListeners.get(0);
assertTrue(listener instanceof DelegateExpressionTaskListener);
DelegateExpressionTaskListener delegateExpressionListener = (DelegateExpressionTaskListener) listener;
assertEquals(delegateExpression, delegateExpressionListener.getExpressionText());
assertTrue(delegateExpressionListener.getFieldDeclarations().isEmpty());
}
use of org.camunda.bpm.engine.impl.task.TaskDefinition in project camunda-bpm-platform by camunda.
the class HumanTaskPlanItemHandlerTest method testCreateTaskListenerByExpression.
@Test
public void testCreateTaskListenerByExpression() {
// given:
ExtensionElements extensionElements = addExtensionElements(humanTask);
CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
String expression = "${myExpression}";
String event = TaskListener.EVENTNAME_CREATE;
taskListener.setCamundaEvent(event);
taskListener.setCamundaExpression(expression);
// when
CmmnActivity activity = handler.handleElement(planItem, context);
// then
assertEquals(0, activity.getListeners().size());
HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
TaskDefinition taskDefinition = behavior.getTaskDefinition();
assertNotNull(taskDefinition);
assertEquals(1, taskDefinition.getTaskListeners().size());
List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
assertEquals(1, createListeners.size());
TaskListener listener = createListeners.get(0);
assertTrue(listener instanceof ExpressionTaskListener);
ExpressionTaskListener expressionListener = (ExpressionTaskListener) listener;
assertEquals(expression, expressionListener.getExpressionText());
}
use of org.camunda.bpm.engine.impl.task.TaskDefinition in project camunda-bpm-platform by camunda.
the class HumanTaskPlanItemHandlerTest method testDeleteTaskListenerByClass.
@Test
public void testDeleteTaskListenerByClass() {
// given:
ExtensionElements extensionElements = addExtensionElements(humanTask);
CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
String className = "org.camunda.bpm.test.tasklistener.ABC";
String event = TaskListener.EVENTNAME_DELETE;
taskListener.setCamundaEvent(event);
taskListener.setCamundaClass(className);
// when
CmmnActivity activity = handler.handleElement(planItem, context);
// then
assertEquals(0, activity.getListeners().size());
HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
TaskDefinition taskDefinition = behavior.getTaskDefinition();
assertNotNull(taskDefinition);
assertEquals(1, taskDefinition.getTaskListeners().size());
List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
assertEquals(1, createListeners.size());
TaskListener listener = createListeners.get(0);
assertTrue(listener instanceof ClassDelegateTaskListener);
ClassDelegateTaskListener classDelegateListener = (ClassDelegateTaskListener) listener;
assertEquals(className, classDelegateListener.getClassName());
assertTrue(classDelegateListener.getFieldDeclarations().isEmpty());
}
Aggregations