Search in sources :

Example 71 with Predicate

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));
}
Also used : HashMap(java.util.HashMap) Predicate(org.apache.camel.Predicate)

Example 72 with Predicate

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();
}
Also used : Exchange(org.apache.camel.Exchange) HashMap(java.util.HashMap) Record(org.xbill.DNS.Record) Predicate(org.apache.camel.Predicate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 73 with Predicate

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();
}
Also used : Exchange(org.apache.camel.Exchange) HashMap(java.util.HashMap) Predicate(org.apache.camel.Predicate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 74 with Predicate

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();
}
Also used : Exchange(org.apache.camel.Exchange) HashMap(java.util.HashMap) Predicate(org.apache.camel.Predicate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 75 with Predicate

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));
}
Also used : Exchange(org.apache.camel.Exchange) HashMap(java.util.HashMap) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Predicate(org.apache.camel.Predicate) Test(org.junit.Test)

Aggregations

Predicate (org.apache.camel.Predicate)124 Exchange (org.apache.camel.Exchange)70 Test (org.junit.Test)40 HashMap (java.util.HashMap)25 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)23 Expression (org.apache.camel.Expression)22 Processor (org.apache.camel.Processor)19 DefaultExchange (org.apache.camel.impl.DefaultExchange)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)9 File (java.io.File)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Map (java.util.Map)7 Ignore (org.junit.Ignore)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 AggregateProcessor (org.apache.camel.processor.aggregate.AggregateProcessor)6 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)6 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)6 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)5