use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class AddToCacheServiceTest method testDoService_EnforceSerializable_NotSerializable.
@Test
public void testDoService_EnforceSerializable_NotSerializable() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID) }));
Cache cache = createCacheInstanceForTests();
AddToCacheService service = createServiceForTests();
try {
service.setConnection(new CacheConnection(cache));
service.setEnforceSerializable(true);
start(service);
service.doService(msg);
fail();
} catch (ServiceException expected) {
} finally {
stop(service);
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class AddToCacheServiceTest method testDoService_ErrorOnEmpty.
@Test
public void testDoService_ErrorOnEmpty() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID) }));
Cache cache = createCacheInstanceForTests();
AddToCacheService service = createServiceForTests();
CacheEntryEvaluator eval = service.getCacheEntryEvaluators().get(0);
eval.setValueTranslator(new MetadataCacheValueTranslator(SRC_KEY));
eval.setKeyTranslator(new MetadataCacheValueTranslator(SRC_KEY));
try {
service.setConnection(new CacheConnection(cache));
start(service);
service.doService(msg);
fail();
} catch (ServiceException expected) {
} finally {
stop(service);
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class CheckCacheServiceTest method testDoService_Error.
@Test
public void testDoService_Error() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
ExpiringMapCache cache = new KeysSizeUnsupportedCache().withMaxEntries(10).withExpiration(new TimeInterval(10L, TimeUnit.SECONDS));
CheckCacheService service = new CheckCacheService() {
@Override
protected boolean eval(AdaptrisMessage msg, FoundInCache callback) throws CoreException {
throw new CoreException();
}
};
try {
service.withConnection(new CacheConnection().withCacheInstance(cache));
service.setKeysFoundServiceId(FOUND);
service.setKeysNotFoundServiceId(NOT_FOUND);
start(service);
cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
service.doService(msg);
fail();
} catch (ServiceException expected) {
} finally {
stop(service);
}
}
use of com.adaptris.core.ServiceException 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);
}
}
use of com.adaptris.core.ServiceException 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