Search in sources :

Example 31 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class CacheEntryEvaluatorTest method testEvaluateKey_ErrorOnEmpty_NonEmptyValue.

@Test
public void testEvaluateKey_ErrorOnEmpty_NonEmptyValue() throws Exception {
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    MetadataCacheValueTranslator translator = new MetadataCacheValueTranslator(DEFAULT_METADATA_KEY);
    eval.setKeyTranslator(translator);
    AdaptrisMessage msg = createMessage(Arrays.asList(new MetadataElement[] { new MetadataElement(DEFAULT_METADATA_KEY, DEFAULT_VALUE) }));
    assertEquals(DEFAULT_VALUE, eval.getKey(msg));
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 32 with MetadataElement

use of com.adaptris.core.MetadataElement 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 33 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class CacheEntryEvaluatorTest method testEvaluateKey_NoErrorOnEmpty_EmptyValue.

@Test
public void testEvaluateKey_NoErrorOnEmpty_EmptyValue() throws Exception {
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    MetadataCacheValueTranslator translator = new MetadataCacheValueTranslator(DEFAULT_METADATA_KEY);
    eval.setKeyTranslator(translator);
    eval.setErrorOnEmptyKey(false);
    AdaptrisMessage msg = createMessage(new ArrayList<MetadataElement>());
    assertEquals(null, eval.getKey(msg));
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 34 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class DynamicServiceExecutorTest method testDoService_DefaultServiceExtractor_WithMarshaller.

@Test
public void testDoService_DefaultServiceExtractor_WithMarshaller() throws Exception {
    AddMetadataService metadataService = new AddMetadataService();
    metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
    DynamicServiceExecutor dynamicService = createService();
    dynamicService.setMarshaller(new XStreamMarshaller());
    AdaptrisMessage msg = createMessage(new ServiceList(new Service[] { metadataService }));
    execute(dynamicService, msg);
    assertEquals(getName(), msg.getMetadataValue(getName()));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) Service(com.adaptris.core.Service) LogMessageService(com.adaptris.core.services.LogMessageService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) XStreamMarshaller(com.adaptris.core.XStreamMarshaller) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 35 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_ByContentId_NotFound.

@Test
public void testDoService_MimeServiceExtractor_ByContentId_NotFound() throws Exception {
    AddMetadataService metadataService = new AddMetadataService();
    metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
    DynamicServiceExecutor dynamicService = createService();
    dynamicService.setServiceExtractor(new MimeServiceExtractor(new SelectByContentId("Blah")));
    AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_BASE64);
    try {
        execute(dynamicService, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) SelectByContentId(com.adaptris.util.text.mime.SelectByContentId) Service(com.adaptris.core.Service) LogMessageService(com.adaptris.core.services.LogMessageService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Aggregations

MetadataElement (com.adaptris.core.MetadataElement)151 Test (org.junit.Test)101 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)94 XPath (com.adaptris.util.text.xml.XPath)23 Document (org.w3c.dom.Document)19 MetadataCollection (com.adaptris.core.MetadataCollection)18 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)18 ServiceException (com.adaptris.core.ServiceException)17 ServiceList (com.adaptris.core.ServiceList)14 Cache (com.adaptris.core.cache.Cache)14 MetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)12 ArrayList (java.util.ArrayList)11 CoreException (com.adaptris.core.CoreException)10 Service (com.adaptris.core.Service)10 HashSet (java.util.HashSet)9 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)7 StaticCacheValueTranslator (com.adaptris.core.services.cache.translators.StaticCacheValueTranslator)7 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 Session (javax.jms.Session)6