use of org.activiti.engine.delegate.Expression in project herd by FINRAOS.
the class ActivitiHelperTest method testGetExpressionVariableAsBooleanInvalidValue.
@Test
public void testGetExpressionVariableAsBooleanInvalidValue() {
// Mock dependencies.
Expression expression = mock(Expression.class);
DelegateExecution execution = mock(DelegateExecution.class);
when(expression.getValue(execution)).thenReturn(INVALID_VALUE);
// Try to call the method under test.
try {
activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED, NO_BOOLEAN_DEFAULT_VALUE);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("\"%s\" must be a valid boolean value of \"true\" or \"false\".", VARIABLE_NAME), e.getMessage());
}
}
use of org.activiti.engine.delegate.Expression in project herd by FINRAOS.
the class ActivitiHelperTest method testGetRequiredExpressionVariableAsString.
@Test
public void testGetRequiredExpressionVariableAsString() {
// Mock dependencies.
Expression expression = mock(Expression.class);
DelegateExecution execution = mock(DelegateExecution.class);
when(expression.getValue(execution)).thenReturn(STRING_VALUE);
// Call the method under test.
String result = activitiHelper.getRequiredExpressionVariableAsString(expression, execution, VARIABLE_NAME);
// Validate the result.
assertEquals(STRING_VALUE, result);
}
use of org.activiti.engine.delegate.Expression in project herd by FINRAOS.
the class ActivitiHelperTest method testGetExpressionVariableAsIntegerBlankValue.
@Test
public void testGetExpressionVariableAsIntegerBlankValue() {
// Mock dependencies.
Expression expression = mock(Expression.class);
DelegateExecution execution = mock(DelegateExecution.class);
when(expression.getValue(execution)).thenReturn(BLANK_TEXT);
// Call the method under test.
Integer result = activitiHelper.getExpressionVariableAsInteger(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED);
// Validate the result.
assertNull(result);
}
use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.
the class ExpressionResolver method resolveInStringPlaceHolder.
private String resolveInStringPlaceHolder(final ExpressionEvaluator expressionEvaluator, final String sourceString) {
final Matcher matcher = EXPRESSION_PATTERN.matcher(sourceString);
final StringBuffer sb = new StringBuffer();
while (matcher.find()) {
final String expressionKey = matcher.group(EXPRESSION_KEY_INDEX);
final Expression expression = expressionManager.createExpression(expressionKey);
try {
final Object value = expressionEvaluator.evaluate(expression, expressionManager, delegateInterceptor);
matcher.appendReplacement(sb, Objects.toString(value));
} catch (final Exception e) {
logger.warn("Unable to resolve expression in variables, keeping original value", e);
}
}
matcher.appendTail(sb);
return sb.toString();
}
use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.
the class IntermediateThrowSignalEventActivityBehavior method execute.
public void execute(DelegateExecution execution) {
CommandContext commandContext = Context.getCommandContext();
String eventSubscriptionName = null;
if (signalEventName != null) {
eventSubscriptionName = signalEventName;
} else {
Expression expressionObject = commandContext.getProcessEngineConfiguration().getExpressionManager().createExpression(signalExpression);
eventSubscriptionName = expressionObject.getValue(execution).toString();
}
EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
List<SignalEventSubscriptionEntity> subscriptionEntities = null;
if (processInstanceScope) {
subscriptionEntities = eventSubscriptionEntityManager.findSignalEventSubscriptionsByProcessInstanceAndEventName(execution.getProcessInstanceId(), eventSubscriptionName);
} else {
subscriptionEntities = eventSubscriptionEntityManager.findSignalEventSubscriptionsByEventName(eventSubscriptionName, execution.getTenantId());
}
for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
Map<String, Object> signalVariables = Optional.ofNullable(execution.getVariables()).filter(it -> !it.isEmpty()).orElse(null);
eventSubscriptionEntityManager.eventReceived(signalEventSubscriptionEntity, signalVariables, signalEventDefinition.isAsync());
}
Context.getAgenda().planTakeOutgoingSequenceFlowsOperation((ExecutionEntity) execution, true);
}
Aggregations