Search in sources :

Example 1 with MetadataCacheValueTranslator

use of com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator in project interlok by adaptris.

the class AddToCacheServiceTest method testDoService_NoErrorOnEmpty_NoKeyValue.

@Test
public void testDoService_NoErrorOnEmpty_NoKeyValue() 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.setErrorOnEmptyKey(false);
    eval.setKeyTranslator(new MetadataCacheValueTranslator(SRC_KEY));
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        service.doService(msg);
        assertNull(cache.get(SRC_VALUE));
    } finally {
        stop(service);
    }
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 2 with MetadataCacheValueTranslator

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

Example 3 with MetadataCacheValueTranslator

use of com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator in project interlok by adaptris.

the class AddToCacheServiceTest method testDoService_NoErrorOnEmpty_NoValue.

@Test
public void testDoService_NoErrorOnEmpty_NoValue() 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.setErrorOnEmptyValue(false);
    eval.setValueTranslator(new MetadataCacheValueTranslator(SRC_KEY));
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        service.doService(msg);
        assertNull(cache.get(SRC_VALUE));
    } finally {
        stop(service);
    }
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 4 with MetadataCacheValueTranslator

use of com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator in project interlok by adaptris.

the class AddToCacheServiceTest method createServiceForTests.

private AddToCacheService createServiceForTests() {
    AddToCacheService service = createService();
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    eval.setKeyTranslator(new MetadataCacheValueTranslator("JMSCorrelationID"));
    eval.setValueTranslator(new JmsReplyToCacheValueTranslator());
    service.addCacheEntryEvaluator(eval);
    return service;
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) JmsReplyToCacheValueTranslator(com.adaptris.core.services.cache.translators.JmsReplyToCacheValueTranslator)

Example 5 with MetadataCacheValueTranslator

use of com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator in project interlok by adaptris.

the class RetrieveFromCacheServiceTest method createServiceForTests.

protected RetrieveFromCacheService createServiceForTests() {
    RetrieveFromCacheService service = createService();
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    eval.setKeyTranslator(new MetadataCacheValueTranslator(SRC_METADATA_KEY));
    eval.setValueTranslator(new MetadataCacheValueTranslator(TARGET_METADATA_KEY));
    service.addCacheEntryEvaluator(eval);
    return service;
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)

Aggregations

MetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)20 Test (org.junit.Test)13 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)11 MetadataElement (com.adaptris.core.MetadataElement)11 Cache (com.adaptris.core.cache.Cache)5 ServiceException (com.adaptris.core.ServiceException)3 CacheEntryEvaluator (com.adaptris.core.services.cache.CacheEntryEvaluator)3 NullCacheValueTranslator (com.adaptris.core.services.cache.CacheEntryEvaluator.NullCacheValueTranslator)3 JmsReplyToCacheValueTranslator (com.adaptris.core.services.cache.translators.JmsReplyToCacheValueTranslator)3 ObjectMetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.ObjectMetadataCacheValueTranslator)3 StaticCacheValueTranslator (com.adaptris.core.services.cache.translators.StaticCacheValueTranslator)3 ArrayList (java.util.ArrayList)3 StringPayloadCacheTranslator (com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator)2 AddToCacheService (com.adaptris.core.services.cache.AddToCacheService)1 XpathCacheValueTranslator (com.adaptris.core.services.cache.translators.XpathCacheValueTranslator)1