Search in sources :

Example 1 with StaticCacheValueTranslator

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);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) StaticCacheValueTranslator(com.adaptris.core.services.cache.translators.StaticCacheValueTranslator) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 2 with StaticCacheValueTranslator

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));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StaticCacheValueTranslator(com.adaptris.core.services.cache.translators.StaticCacheValueTranslator) MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) NullCacheValueTranslator(com.adaptris.core.services.cache.CacheEntryEvaluator.NullCacheValueTranslator) StaticCacheValueTranslator(com.adaptris.core.services.cache.translators.StaticCacheValueTranslator) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 3 with StaticCacheValueTranslator

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));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StaticCacheValueTranslator(com.adaptris.core.services.cache.translators.StaticCacheValueTranslator) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 4 with StaticCacheValueTranslator

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);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) StaticCacheValueTranslator(com.adaptris.core.services.cache.translators.StaticCacheValueTranslator) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 MetadataElement (com.adaptris.core.MetadataElement)4 StaticCacheValueTranslator (com.adaptris.core.services.cache.translators.StaticCacheValueTranslator)4 Test (org.junit.Test)4 ServiceException (com.adaptris.core.ServiceException)2 Cache (com.adaptris.core.cache.Cache)2 NullCacheValueTranslator (com.adaptris.core.services.cache.CacheEntryEvaluator.NullCacheValueTranslator)1 MetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)1