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();
}
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));
}
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));
}
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));
}
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));
}
Aggregations