use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class ClearCacheServiceTest method testDoService.
@Test
public void testDoService() throws Exception {
Cache mockCache = Mockito.mock(Cache.class);
CacheConnection cache = new CacheConnection(mockCache);
ClearCacheService service = new ClearCacheService().withConnection(cache);
ExampleServiceCase.execute(service, AdaptrisMessageFactory.getDefaultInstance().newMessage());
}
use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class GetValueFromCacheTest method testDoService_WithError.
@Test
public void testDoService_WithError() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
Cache cache = createCacheInstanceForTests();
GetValueFromCache service = new GetValueFromCache().withExceptionIfNotFound(true).withValueTranslator(new StringPayloadCacheTranslator()).withKey("%message{%uniqueId}").withConnection(new CacheConnection().withCacheInstance(cache));
try {
start(service);
service.doService(msg);
fail();
} catch (ServiceException expected) {
} finally {
stop(service);
}
}
use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class GetValueFromCacheTest method testDoService_NotFoundWithError.
@Test
public void testDoService_NotFoundWithError() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
Cache cache = createCacheInstanceForTests();
GetValueFromCache service = new GetValueFromCache().withExceptionIfNotFound(false).withValueTranslator(new StringPayloadCacheTranslator()).withKey("%message{%uniqueId}").withConnection(new CacheConnection().withCacheInstance(cache));
try {
start(service);
service.doService(msg);
assertNotEquals("Hello World", msg.getContent());
} catch (ServiceException expected) {
} finally {
stop(service);
}
}
use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class RemoveKeyFromCacheTest method testDoService.
@Test
public void testDoService() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
Cache cache = createCacheInstanceForTests();
RemoveKeyFromCache service = new RemoveKeyFromCache().withKey("%message{%uniqueId}").withConnection(new CacheConnection().withCacheInstance(cache));
try {
start(service);
cache.put(msg.getUniqueId(), msg.getContent());
assertNotNull(cache.get(msg.getUniqueId()));
service.doService(msg);
assertNull(cache.get(msg.getUniqueId()));
} finally {
stop(service);
}
}
use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class RetrieveFromCacheServiceTest method testDoService_AddToMessageFailure.
@Test
public void testDoService_AddToMessageFailure() 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