use of org.apache.camel.Predicate in project camel by apache.
the class AggregateShouldSkipFilteredExchangesTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
Predicate goodWord = body().contains("World");
from("direct:start").filter(goodWord).to("mock:filtered").aggregate(header("id"), new MyAggregationStrategy()).completionTimeout(1000).to("mock:result").end().end();
}
};
}
use of org.apache.camel.Predicate in project camel by apache.
the class AggregateProcessorTest method testAggregateProcessorCompletionPredicateEager.
public void testAggregateProcessorCompletionPredicateEager() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B+END");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "predicate");
Processor done = new SendProcessor(context.getEndpoint("mock:result"));
Expression corr = header("id");
AggregationStrategy as = new BodyInAggregatingStrategy();
Predicate complete = body().isEqualTo("END");
AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
ap.setCompletionPredicate(complete);
ap.setEagerCheckCompletion(true);
ap.start();
Exchange e1 = new DefaultExchange(context);
e1.getIn().setBody("A");
e1.getIn().setHeader("id", 123);
Exchange e2 = new DefaultExchange(context);
e2.getIn().setBody("B");
e2.getIn().setHeader("id", 123);
Exchange e3 = new DefaultExchange(context);
e3.getIn().setBody("END");
e3.getIn().setHeader("id", 123);
Exchange e4 = new DefaultExchange(context);
e4.getIn().setBody("D");
e4.getIn().setHeader("id", 123);
ap.process(e1);
ap.process(e2);
ap.process(e3);
ap.process(e4);
assertMockEndpointsSatisfied();
ap.stop();
}
use of org.apache.camel.Predicate in project camel by apache.
the class AggregateProcessorTest method testAggregateProcessorCompletionPredicate.
public void testAggregateProcessorCompletionPredicate() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B+END");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "predicate");
Processor done = new SendProcessor(context.getEndpoint("mock:result"));
Expression corr = header("id");
AggregationStrategy as = new BodyInAggregatingStrategy();
Predicate complete = body().contains("END");
AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
ap.setCompletionPredicate(complete);
ap.setEagerCheckCompletion(false);
ap.start();
Exchange e1 = new DefaultExchange(context);
e1.getIn().setBody("A");
e1.getIn().setHeader("id", 123);
Exchange e2 = new DefaultExchange(context);
e2.getIn().setBody("B");
e2.getIn().setHeader("id", 123);
Exchange e3 = new DefaultExchange(context);
e3.getIn().setBody("END");
e3.getIn().setHeader("id", 123);
Exchange e4 = new DefaultExchange(context);
e4.getIn().setBody("D");
e4.getIn().setHeader("id", 123);
ap.process(e1);
ap.process(e2);
ap.process(e3);
ap.process(e4);
assertMockEndpointsSatisfied();
ap.stop();
}
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);
}
}
Aggregations