use of org.apache.camel.Predicate in project camel by apache.
the class SimpleParserPredicateTest method testSimpleIn.
public void testSimpleIn() throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("key", "foo");
map.put("key2", "bar");
map.put("key3", "none");
exchange.getIn().setBody(map);
SimplePredicateParser parser = new SimplePredicateParser("${body[key]} in ${ref:myList}", true);
Predicate pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
parser = new SimplePredicateParser("${body[key2]} in ${ref:myList}", true);
pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
parser = new SimplePredicateParser("${body[key3]} in ${ref:myList}", true);
pre = parser.parsePredicate();
assertFalse("Should not match", pre.matches(exchange));
}
use of org.apache.camel.Predicate in project camel by apache.
the class DnsLookupEndpointTest method testDNSWithNameHeader.
@Test
@Ignore("Testing behind nat produces timeouts")
public void testDNSWithNameHeader() throws Exception {
resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedMessagesMatches(new Predicate() {
public boolean matches(Exchange exchange) {
Record[] record = (Record[]) exchange.getIn().getBody();
return record[0].getName().toString().equals("www.example.com.");
}
});
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("dns.name", "www.example.com");
template.sendBodyAndHeaders("hello", headers);
resultEndpoint.assertIsSatisfied();
}
use of org.apache.camel.Predicate in project camel by apache.
the class WikipediaEndpointSpringTest method testWikipediaForMonkey.
@Test
@Ignore("Testing behind nat produces timeouts")
public void testWikipediaForMonkey() throws Exception {
resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedMessagesMatches(new Predicate() {
public boolean matches(Exchange exchange) {
String str = (String) exchange.getIn().getBody();
return RESPONSE_MONKEY.equals(str);
}
});
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("term", "monkey");
template.sendBodyAndHeaders(null, headers);
resultEndpoint.assertIsSatisfied();
}
use of org.apache.camel.Predicate in project camel by apache.
the class DnsDigEndpointSpringTest method testDigForMonkey.
@Test
@Ignore("Testing behind nat produces timeouts")
public void testDigForMonkey() throws Exception {
resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedMessagesMatches(new Predicate() {
public boolean matches(Exchange exchange) {
String str = ((Message) exchange.getIn().getBody()).getSectionArray(Section.ANSWER)[0].rdataToString();
return RESPONSE_MONKEY.equals(str);
}
});
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("dns.name", "monkey.wp.dg.cx");
headers.put("dns.type", "TXT");
template.sendBodyAndHeaders(null, headers);
resultEndpoint.assertIsSatisfied();
}
use of org.apache.camel.Predicate in project camel by apache.
the class JCacheProducerInvokeTest method testInvoke.
@Test
public void testInvoke() throws Exception {
final Map<String, Object> headers = new HashMap<>();
final Cache<Object, Object> cache = getCacheFromEndpoint("jcache://test-cache");
final String key = randomString();
final String val = randomString();
cache.put(key, val);
headers.clear();
headers.put(JCacheConstants.ACTION, "INVOKE");
headers.put(JCacheConstants.KEY, key);
headers.put(JCacheConstants.ENTRY_PROCESSOR, ENTRY_PROCESSOR);
sendBody("direct:invoke", null, headers);
MockEndpoint mock = getMockEndpoint("mock:invoke");
mock.expectedMinimumMessageCount(1);
mock.expectedHeaderReceived(JCacheConstants.KEY, key);
mock.expectedMessagesMatches(new Predicate() {
@Override
public boolean matches(Exchange exchange) {
return exchange.getIn().getBody(String.class).equals("processor-" + val);
}
});
mock.assertIsSatisfied();
assertTrue(cache.containsKey(key));
assertEquals(val, cache.get(key));
}
Aggregations