Search in sources :

Example 16 with MetadataCacheValueTranslator

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

the class CacheEntryEvaluatorTest method testEvaluateKey_ErrorOnEmpty_EmptyValue.

@Test
public void testEvaluateKey_ErrorOnEmpty_EmptyValue() throws Exception {
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    MetadataCacheValueTranslator translator = new MetadataCacheValueTranslator(DEFAULT_METADATA_KEY);
    eval.setKeyTranslator(translator);
    eval.setErrorOnEmptyKey(true);
    AdaptrisMessage msg = createMessage(new ArrayList<MetadataElement>());
    try {
        eval.getKey(msg);
        fail();
    } catch (ServiceException expected) {
    }
}
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) Test(org.junit.Test)

Example 17 with MetadataCacheValueTranslator

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

the class CacheEntryEvaluatorTest method testEvaluateValue_ErrorOnEmpty_EmptyValue.

@Test
public void testEvaluateValue_ErrorOnEmpty_EmptyValue() throws Exception {
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    CacheValueTranslator translator = new MetadataCacheValueTranslator(DEFAULT_METADATA_KEY);
    eval.setValueTranslator(translator);
    eval.setErrorOnEmptyValue(true);
    AdaptrisMessage msg = createMessage(new ArrayList<MetadataElement>());
    try {
        eval.getValue(msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) ServiceException(com.adaptris.core.ServiceException) 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) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 18 with MetadataCacheValueTranslator

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

the class CacheEntryEvaluatorTest method testEvaluateValue_ErrorOnEmpty_NonEmptyValue.

@Test
public void testEvaluateValue_ErrorOnEmpty_NonEmptyValue() throws Exception {
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    CacheValueTranslator translator = new MetadataCacheValueTranslator(DEFAULT_METADATA_KEY);
    eval.setValueTranslator(translator);
    AdaptrisMessage msg = createMessage(Arrays.asList(new MetadataElement[] { new MetadataElement(DEFAULT_METADATA_KEY, DEFAULT_VALUE) }));
    assertEquals(DEFAULT_VALUE, eval.getValue(msg));
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) 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) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 19 with MetadataCacheValueTranslator

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

the class CheckAndRetrieveCacheTest method createServiceForTests.

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

Example 20 with MetadataCacheValueTranslator

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

the class BasicCacheExampleGenerator method createAddToCacheService.

public static AddToCacheService createAddToCacheService() {
    AddToCacheService service = new AddToCacheService();
    CacheEntryEvaluator eval1 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval2 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval3 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval4 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval5 = new CacheEntryEvaluator();
    eval1.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    eval1.setValueTranslator(new MetadataCacheValueTranslator("Another_MetadataKey_Whose_Value_Makes_The_Cache_CacheValue"));
    eval2.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    eval2.setValueTranslator(new StringPayloadCacheTranslator());
    eval3.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    eval3.setValueTranslator(new XpathCacheValueTranslator("/some/xpath/value"));
    eval4.setKeyTranslator(new MetadataCacheValueTranslator("JMSCorrelationID"));
    eval4.setValueTranslator(new JmsReplyToCacheValueTranslator());
    eval5.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    eval5.setValueTranslator(new ObjectMetadataCacheValueTranslator(JmsConstants.OBJ_JMS_REPLY_TO_KEY));
    service.setCacheEntryEvaluators(new ArrayList(Arrays.asList(new CacheEntryEvaluator[] { eval1, eval2, eval3, eval4, eval5 })));
    return service;
}
Also used : ObjectMetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.ObjectMetadataCacheValueTranslator) MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) XpathCacheValueTranslator(com.adaptris.core.services.cache.translators.XpathCacheValueTranslator) JmsReplyToCacheValueTranslator(com.adaptris.core.services.cache.translators.JmsReplyToCacheValueTranslator) ArrayList(java.util.ArrayList) CacheEntryEvaluator(com.adaptris.core.services.cache.CacheEntryEvaluator) StringPayloadCacheTranslator(com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator) AddToCacheService(com.adaptris.core.services.cache.AddToCacheService) ObjectMetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.ObjectMetadataCacheValueTranslator)

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