use of org.apache.camel.Predicate in project camel by apache.
the class PdfCreationTest method testPdfCreation.
@Test
public void testPdfCreation() throws Exception {
final String expectedText = "expectedText";
template.sendBody("direct:start", expectedText);
resultEndpoint.setExpectedMessageCount(1);
resultEndpoint.expectedMessagesMatches(new Predicate() {
@Override
public boolean matches(Exchange exchange) {
Object body = exchange.getIn().getBody();
assertThat(body, instanceOf(ByteArrayOutputStream.class));
try {
PDDocument doc = PDDocument.load(new ByteArrayInputStream(((ByteArrayOutputStream) body).toByteArray()));
PDFTextStripper pdfTextStripper = new PDFTextStripper();
String text = pdfTextStripper.getText(doc);
assertEquals(1, doc.getNumberOfPages());
assertThat(text, containsString(expectedText));
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
}
});
resultEndpoint.assertIsSatisfied();
}
use of org.apache.camel.Predicate in project camel by apache.
the class SimpleParserPredicateTest method testSimpleLogicalOr.
public void testSimpleLogicalOr() throws Exception {
exchange.getIn().setBody("Hello");
exchange.getIn().setHeader("high", true);
exchange.getIn().setHeader("foo", 123);
SimplePredicateParser parser = new SimplePredicateParser("${header.high} == false || ${header.foo} == 123", true);
Predicate pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
}
use of org.apache.camel.Predicate in project camel by apache.
the class SimpleTest method testSimpleExpressionOrPredicate.
public void testSimpleExpressionOrPredicate() throws Exception {
Predicate predicate = SimpleLanguage.predicate("${header.bar} == 123");
assertTrue(predicate.matches(exchange));
predicate = SimpleLanguage.predicate("${header.bar} == 124");
assertFalse(predicate.matches(exchange));
Expression expression = SimpleLanguage.expression("${body}");
assertEquals("<hello id='m123'>world!</hello>", expression.evaluate(exchange, String.class));
expression = SimpleLanguage.simple("${body}");
assertEquals("<hello id='m123'>world!</hello>", expression.evaluate(exchange, String.class));
expression = SimpleLanguage.simple("${body}", String.class);
assertEquals("<hello id='m123'>world!</hello>", expression.evaluate(exchange, String.class));
expression = SimpleLanguage.simple("${header.bar} == 123", boolean.class);
assertEquals(Boolean.TRUE, expression.evaluate(exchange, Object.class));
expression = SimpleLanguage.simple("${header.bar} == 124", boolean.class);
assertEquals(Boolean.FALSE, expression.evaluate(exchange, Object.class));
expression = SimpleLanguage.simple("${header.bar} == 123", Boolean.class);
assertEquals(Boolean.TRUE, expression.evaluate(exchange, Object.class));
expression = SimpleLanguage.simple("${header.bar} == 124", Boolean.class);
assertEquals(Boolean.FALSE, expression.evaluate(exchange, Object.class));
}
use of org.apache.camel.Predicate in project camel by apache.
the class OnExceptionContinuePredicateTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// use a predicate instance
Predicate predicate = new Predicate() {
@Override
public boolean matches(Exchange exchange) {
predicateInvoked.incrementAndGet();
return true;
}
};
// tell Camel to handle and continue when this exception is thrown
onException(IllegalArgumentException.class).continued(predicate).process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
processorInvoked.incrementAndGet();
}
}).to("mock:me");
from("direct:start").to("mock:start").throwException(new IllegalArgumentException("Forced")).to("mock:result");
}
};
}
use of org.apache.camel.Predicate in project camel by apache.
the class CamelSWFActivityConsumerTest method receivesDecisionTask.
@Test
public void receivesDecisionTask() throws Exception {
result.expectedMinimumMessageCount(1);
result.expectedMessagesMatches(new Predicate() {
public boolean matches(Exchange exchange) {
return exchange.getIn().getHeader(SWFConstants.ACTION).equals(SWFConstants.EXECUTE_ACTION) && exchange.getIn().getBody(Object[].class)[0].equals("test");
}
});
ActivityTask activityTask = new ActivityTask();
activityTask.setTaskToken("token");
activityTask.setInput("[\"[Ljava.lang.Object;\",[\"test\"]]");
when(amazonSWClient.pollForActivityTask(any(PollForActivityTaskRequest.class))).thenReturn(activityTask);
context.start();
assertMockEndpointsSatisfied();
verify(amazonSWClient, atLeastOnce()).pollForActivityTask(any(PollForActivityTaskRequest.class));
}
Aggregations