use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class CheckCacheServiceTest method testDoService_InCache.
@Test
public void testDoService_InCache() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
ExpiringMapCache cache = createCacheInstanceForTests();
CheckCacheService service = createServiceForTests();
try {
service.setConnection(new CacheConnection(cache));
service.setKeysFoundServiceId(FOUND);
service.setKeysNotFoundServiceId(NOT_FOUND);
start(service);
cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
service.doService(msg);
assertEquals(FOUND, msg.getNextServiceId());
} finally {
stop(service);
}
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class CheckCacheServiceTest method testDoService_NotInCache.
@Test
public void testDoService_NotInCache() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
ExpiringMapCache cache = createCacheInstanceForTests();
CheckCacheService service = createServiceForTests();
try {
service.setConnection(new CacheConnection(cache));
service.setKeysFoundServiceId(FOUND);
service.setKeysNotFoundServiceId(NOT_FOUND);
start(service);
service.doService(msg);
assertEquals(NOT_FOUND, msg.getNextServiceId());
} finally {
stop(service);
}
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class RemoveFromCacheServiceTest method testDoService.
@Override
@Test
public void testDoService() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(SRC_METADATA_KEY, LOOKUP_VALUE) }));
Cache cache = createCacheInstanceForTests();
CacheServiceBase service = createServiceForTests();
try {
service.setConnection(new CacheConnection(cache));
start(service);
// Now add the TARGET DATA to the cache.
cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
service.doService(msg);
assertTrue(msg.headersContainsKey(TARGET_METADATA_KEY));
assertEquals(LOOKED_UP_VALUE, msg.getMetadataValue(TARGET_METADATA_KEY));
// The service should have removed it.
assertFalse(cache.getKeys().contains(LOOKUP_VALUE));
} finally {
stop(service);
}
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class RetrieveFromCacheServiceTest method testDoService_KeyNotFound.
@Test
public void testDoService_KeyNotFound() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", new ArrayList<MetadataElement>());
Cache cache = createCacheInstanceForTests();
RetrieveFromCacheService service = createService();
CacheEntryEvaluator eval = new CacheEntryEvaluator();
eval.setErrorOnEmptyKey(false);
service.addCacheEntryEvaluator(eval);
try {
service.setConnection(new CacheConnection(cache));
start(service);
service.doService(msg);
} finally {
stop(service);
}
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class RetrieveFromCacheServiceTest method testDoService_NullValueTranslator.
@Test
public void testDoService_NullValueTranslator() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(SRC_METADATA_KEY, LOOKUP_VALUE) }));
Cache cache = createCacheInstanceForTests();
RetrieveFromCacheService service = createServiceForTests();
CacheEntryEvaluator eval = service.getCacheEntryEvaluators().get(0);
// we know that StaticCacheValueTranslator should throw an exception if
// we try to apply a value into the message.
eval.setValueTranslator(new StaticCacheValueTranslator("dummy value"));
try {
service.setConnection(new CacheConnection(cache));
start(service);
// Now add the TARGET DATA to the cache.
cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
service.doService(msg);
fail("Expected a ServiceException");
} catch (ServiceException expected) {
} finally {
stop(service);
}
}
Aggregations