use of org.apache.camel.Predicate in project camel by apache.
the class CamelSWFWorkflowConsumerTest method receivesDecisionTask.
@Test
public void receivesDecisionTask() throws Exception {
// use minimum as depending on the polling we may do more than 1 in the test before we assert and stop
result.expectedMinimumMessageCount(1);
result.expectedMessagesMatches(new Predicate() {
public boolean matches(Exchange exchange) {
return exchange.getIn().getHeader(SWFConstants.ACTION) != null;
}
});
DecisionTask decisionTask = new DecisionTask();
decisionTask.setTaskToken("token");
when(amazonSWClient.pollForDecisionTask(any(PollForDecisionTaskRequest.class))).thenReturn(decisionTask);
context.start();
assertMockEndpointsSatisfied();
verify(amazonSWClient, atLeastOnce()).pollForDecisionTask(any(PollForDecisionTaskRequest.class));
}
use of org.apache.camel.Predicate in project camel by apache.
the class DefaultAnnotationExpressionFactory method createExpression.
public Expression createExpression(CamelContext camelContext, Annotation annotation, LanguageAnnotation languageAnnotation, Class<?> expressionReturnType) {
String languageName = languageAnnotation.language();
if (languageName == null) {
throw new IllegalArgumentException("Cannot determine the language from the annotation: " + annotation);
}
Language language = camelContext.resolveLanguage(languageName);
if (language == null) {
throw new IllegalArgumentException("Cannot find the language: " + languageName + " on the classpath");
}
String expression = getExpressionFromAnnotation(annotation);
if (expressionReturnType == Boolean.class || expressionReturnType == boolean.class) {
Predicate predicate = language.createPredicate(expression);
return PredicateToExpressionAdapter.toExpression(predicate);
} else {
return language.createExpression(expression);
}
}
use of org.apache.camel.Predicate in project camel by apache.
the class ValueBuilder method in.
public Predicate in(Object... values) {
List<Predicate> predicates = new ArrayList<Predicate>();
for (Object value : values) {
Expression right = asExpression(value);
right = ExpressionBuilder.convertToExpression(right, expression);
Predicate predicate = onNewPredicate(PredicateBuilder.isEqualTo(expression, right));
predicates.add(predicate);
}
return in(predicates.toArray(new Predicate[predicates.size()]));
}
use of org.apache.camel.Predicate in project camel by apache.
the class PredicateBuilder method regex.
/**
* Returns a predicate which is true if the expression matches the given
* regular expression
*
* @param expression the expression to evaluate
* @param pattern the regular expression to match against
* @return a new predicate
*/
public static Predicate regex(final Expression expression, final Pattern pattern) {
notNull(expression, "expression");
notNull(pattern, "pattern");
return new Predicate() {
public boolean matches(Exchange exchange) {
String value = expression.evaluate(exchange, String.class);
if (value != null) {
Matcher matcher = pattern.matcher(value);
return matcher.matches();
}
return false;
}
@Override
public String toString() {
return expression + ".matches('" + pattern + "')";
}
};
}
use of org.apache.camel.Predicate in project camel by apache.
the class BacklogDebugger method addConditionalBreakpoint.
public void addConditionalBreakpoint(String nodeId, String language, String predicate) {
Predicate condition = camelContext.resolveLanguage(language).createPredicate(predicate);
NodeBreakpoint breakpoint = breakpoints.get(nodeId);
if (breakpoint == null) {
logger.log("Adding conditional breakpoint " + nodeId + " [" + predicate + "]");
breakpoint = new NodeBreakpoint(nodeId, condition);
breakpoints.put(nodeId, breakpoint);
debugger.addBreakpoint(breakpoint, breakpoint);
} else if (breakpoint.getCondition() == null) {
logger.log("Updating to conditional breakpoint " + nodeId + " [" + predicate + "]");
debugger.removeBreakpoint(breakpoint);
breakpoints.put(nodeId, breakpoint);
debugger.addBreakpoint(breakpoint, breakpoint);
} else if (breakpoint.getCondition() != null) {
logger.log("Updating conditional breakpoint " + nodeId + " [" + predicate + "]");
breakpoint.setCondition(condition);
}
}
Aggregations