Search in sources :

Example 76 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class JCacheProducerPutTest method testPutIfAbsentFailure.

@Test
public void testPutIfAbsentFailure() 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, "PUTIFABSENT");
    headers.put(JCacheConstants.KEY, key);
    sendBody("direct:put-if-absent", val, headers);
    MockEndpoint mock = getMockEndpoint("mock:put-if-absent");
    mock.expectedMinimumMessageCount(1);
    mock.expectedHeaderReceived(JCacheConstants.KEY, key);
    mock.expectedHeaderReceived(JCacheConstants.RESULT, false);
    mock.expectedMessagesMatches(new Predicate() {

        @Override
        public boolean matches(Exchange exchange) {
            assertNotNull("body", exchange.getIn().getBody());
            return exchange.getIn().getBody().equals(val);
        }
    });
    mock.assertIsSatisfied();
}
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)

Example 77 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class JCacheProducerReplaceTest method testReplace.

@Test
public void testReplace() 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();
    final String val1 = randomString();
    cache.put(key, val);
    headers.clear();
    headers.put(JCacheConstants.ACTION, "REPLACE");
    headers.put(JCacheConstants.KEY, key);
    sendBody("direct:replace", val1, headers);
    MockEndpoint mock = getMockEndpoint("mock:replace");
    mock.expectedMinimumMessageCount(1);
    mock.expectedHeaderReceived(JCacheConstants.KEY, key);
    mock.expectedHeaderReceived(JCacheConstants.RESULT, true);
    mock.expectedMessagesMatches(new Predicate() {

        @Override
        public boolean matches(Exchange exchange) {
            assertNotNull("body", exchange.getIn().getBody());
            return exchange.getIn().getBody().equals(val1);
        }
    });
    mock.assertIsSatisfied();
    assertEquals(val1, 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)

Example 78 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class JCacheProducerReplaceTest method testReplaceIf.

@Test
public void testReplaceIf() 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();
    final String val1 = randomString();
    cache.put(key, val);
    headers.clear();
    headers.put(JCacheConstants.ACTION, "REPLACE");
    headers.put(JCacheConstants.KEY, key);
    headers.put(JCacheConstants.OLD_VALUE, val);
    sendBody("direct:replace", val1, headers);
    MockEndpoint mock = getMockEndpoint("mock:replace");
    mock.expectedMinimumMessageCount(1);
    mock.expectedHeaderReceived(JCacheConstants.KEY, key);
    mock.expectedHeaderReceived(JCacheConstants.RESULT, true);
    mock.expectedMessagesMatches(new Predicate() {

        @Override
        public boolean matches(Exchange exchange) {
            assertNotNull("body", exchange.getIn().getBody());
            return exchange.getIn().getBody().equals(val1);
        }
    });
    mock.assertIsSatisfied();
    assertEquals(val1, 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)

Example 79 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class JCacheProducerReplaceTest method testReplaceIfFailure.

@Test
public void testReplaceIfFailure() 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();
    final String val1 = randomString();
    cache.put(key, val);
    headers.clear();
    headers.put(JCacheConstants.ACTION, "REPLACE");
    headers.put(JCacheConstants.KEY, key);
    headers.put(JCacheConstants.OLD_VALUE, val1);
    sendBody("direct:replace", val1, headers);
    MockEndpoint mock = getMockEndpoint("mock:replace");
    mock.expectedMinimumMessageCount(1);
    mock.expectedHeaderReceived(JCacheConstants.KEY, key);
    mock.expectedHeaderReceived(JCacheConstants.RESULT, false);
    mock.expectedMessagesMatches(new Predicate() {

        @Override
        public boolean matches(Exchange exchange) {
            assertNotNull("body", exchange.getIn().getBody());
            return exchange.getIn().getBody().equals(val1);
        }
    });
    mock.assertIsSatisfied();
    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)

Example 80 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class JCacheProducerReplaceTest method testReplaceFail.

@Test
public void testReplaceFail() 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();
    assertFalse(cache.containsKey(key));
    headers.clear();
    headers.put(JCacheConstants.ACTION, "REPLACE");
    headers.put(JCacheConstants.KEY, key);
    sendBody("direct:replace-fail", val, headers);
    MockEndpoint mock = getMockEndpoint("mock:replace-fail");
    mock.expectedMinimumMessageCount(1);
    mock.expectedHeaderReceived(JCacheConstants.KEY, key);
    mock.expectedHeaderReceived(JCacheConstants.RESULT, false);
    mock.expectedMessagesMatches(new Predicate() {

        @Override
        public boolean matches(Exchange exchange) {
            assertNotNull("body", exchange.getIn().getBody());
            return exchange.getIn().getBody().equals(val);
        }
    });
    mock.assertIsSatisfied();
    assertFalse(cache.containsKey(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