use of com.adaptris.core.services.cache.translators.StaticCacheValueTranslator 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);
}
}
use of com.adaptris.core.services.cache.translators.StaticCacheValueTranslator in project interlok by adaptris.
the class CacheEntryEvaluatorTest method testEvaluateValue_WithError.
@Test
public void testEvaluateValue_WithError() throws Exception {
CacheEntryEvaluator eval = new CacheEntryEvaluator();
CacheValueTranslator translator = new StaticCacheValueTranslator() {
@Override
public String getValueFromMessage(AdaptrisMessage msg) throws CoreException {
throw new UnsupportedOperationException();
}
};
eval.setValueTranslator(translator);
AdaptrisMessage msg = createMessage(new ArrayList<MetadataElement>());
// We don't actually *expect* to catch an exception here.
// The code just returns null in the event we can't get the value from the AdaptrisMessage.
assertNull(eval.getValue(msg));
}
use of com.adaptris.core.services.cache.translators.StaticCacheValueTranslator in project interlok by adaptris.
the class CacheEntryEvaluatorTest method testEvaluateKey_WithError.
@Test
public void testEvaluateKey_WithError() throws Exception {
CacheEntryEvaluator eval = new CacheEntryEvaluator();
StaticCacheValueTranslator translator = new StaticCacheValueTranslator() {
@Override
public String getValueFromMessage(AdaptrisMessage msg) throws CoreException {
throw new UnsupportedOperationException();
}
};
eval.setKeyTranslator(translator);
AdaptrisMessage msg = createMessage(new ArrayList<MetadataElement>());
// We don't actually *expect* to catch an exception here.
// The code just returns null in the event we can't get the value from the AdaptrisMessage.
assertNull(eval.getKey(msg));
}
use of com.adaptris.core.services.cache.translators.StaticCacheValueTranslator 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