use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class ClearCacheServiceTest method testDoService_Exception.
@Test(expected = ServiceException.class)
public void testDoService_Exception() throws Exception {
Cache mockCache = Mockito.mock(Cache.class);
Mockito.doThrow(new CoreException()).when(mockCache).clear();
CacheConnection cache = new CacheConnection(mockCache);
ClearCacheService service = new ClearCacheService().withIgnoreUnsupported(true).withConnection(cache);
ExampleServiceCase.execute(service, AdaptrisMessageFactory.getDefaultInstance().newMessage());
}
use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class ClearCacheServiceTest method testDoService_Quietly.
@Test
public void testDoService_Quietly() throws Exception {
Cache mockCache = Mockito.mock(Cache.class);
Mockito.doThrow(new UnsupportedOperationException()).when(mockCache).clear();
CacheConnection cache = new CacheConnection(mockCache);
ClearCacheService service = new ClearCacheService().withIgnoreUnsupported(true).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.
@Test
public void testDoService() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
Cache cache = createCacheInstanceForTests();
GetValueFromCache service = new GetValueFromCache().withValueTranslator(new StringPayloadCacheTranslator()).withKey("%message{%uniqueId}").withConnection(new CacheConnection().withCacheInstance(cache));
try {
start(service);
cache.put(msg.getUniqueId(), "Goodbye Cruel World");
service.doService(msg);
assertNotEquals("Hello World", msg.getContent());
assertEquals("Goodbye Cruel World", msg.getContent());
} finally {
stop(service);
}
}
use of com.adaptris.core.cache.Cache 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.cache.Cache in project interlok by adaptris.
the class RemoveKeyFromCacheTest method testDoService_WithError.
@Test
public void testDoService_WithError() throws Exception {
AdaptrisMessage msg = new DefectiveMessageFactory(EnumSet.of(WhenToBreak.METADATA_GET)).newMessage("Hello World");
msg.addMetadata("metadataKey", "value");
Cache cache = createCacheInstanceForTests();
RemoveKeyFromCache service = new RemoveKeyFromCache().withKey("%message{metadataKey}").withConnection(new CacheConnection().withCacheInstance(cache));
try {
start(service);
service.doService(msg);
fail();
} catch (ServiceException expected) {
} finally {
stop(service);
}
}
Aggregations