Search in sources :

Example 26 with MetadataElement

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

the class RetrieveFromCacheServiceTest method testDoService_NoExceptionIfNotFound_NotFound.

@Test
public void testDoService_NoExceptionIfNotFound_NotFound() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(SRC_METADATA_KEY, LOOKUP_VALUE) }));
    Cache cache = createCacheInstanceForTests();
    RetrieveFromCacheService service = createServiceForTests();
    service.setExceptionIfNotFound(false);
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        service.doService(msg);
        assertFalse(msg.headersContainsKey(TARGET_METADATA_KEY));
    } finally {
        stop(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 27 with MetadataElement

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

the class RetrieveFromCacheServiceTest method testDoService.

@Test
public void testDoService() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(SRC_METADATA_KEY, LOOKUP_VALUE) }));
    Cache cache = createCacheInstanceForTests();
    RetrieveFromCacheService service = createServiceForTests();
    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);
        assertTrue(msg.headersContainsKey(TARGET_METADATA_KEY));
        assertEquals(LOOKED_UP_VALUE, msg.getMetadataValue(TARGET_METADATA_KEY));
    } finally {
        stop(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 28 with MetadataElement

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

the class MimeAggregatorCase method testJoinMessage_WithSubType.

@Test
public void testJoinMessage_WithSubType() throws Exception {
    MimeAggregator aggr = createAggregatorForTests().withMimeContentSubType("form-data");
    AdaptrisMessage original = AdaptrisMessageFactory.getDefaultInstance().newMessage("<envelope/>", null, new HashSet<>(Arrays.asList(new MetadataElement("X-Interlok-Test", "ZZLC-original"))));
    AdaptrisMessage s1 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>hello</document>", null, new HashSet<>(Arrays.asList(new MetadataElement("X-Interlok-Test", "ZZLC-split1"))));
    AdaptrisMessage s2 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>world</document>", null, new HashSet<>(Arrays.asList(new MetadataElement("X-Interlok-Test", "ZZLC-split2"))));
    aggr.joinMessage(original, Arrays.asList(s1, s2));
    String payload = original.getContent();
    System.err.println(payload);
    assertTrue(payload.contains("multipart/form-data"));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 29 with MetadataElement

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

the class MimeAggregatorCase method testJoinMessage_ContentType.

@Test
public void testJoinMessage_ContentType() throws Exception {
    MimeAggregator aggr = createAggregatorForTests();
    aggr.setPartContentType("%message{MyContentType}");
    Set<MetadataElement> metadata = new HashSet<>();
    metadata.add(new MetadataElement("MyContentType", "application/xml"));
    AdaptrisMessage original = AdaptrisMessageFactory.getDefaultInstance().newMessage("<envelope/>", null, new HashSet<>(metadata));
    AdaptrisMessage s1 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>hello</document>", null, new HashSet<>(metadata));
    AdaptrisMessage s2 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>world</document>", null, new HashSet<>(metadata));
    aggr.joinMessage(original, Arrays.asList(new AdaptrisMessage[] { s1, s2 }));
    BodyPartIterator m = new BodyPartIterator(original.getInputStream());
    for (int i = 0; i < m.size(); i++) {
        MimeBodyPart part = m.getBodyPart(i);
        assertEquals("application/xml", part.getContentType());
    }
}
Also used : BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) MimeBodyPart(javax.mail.internet.MimeBodyPart) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with MetadataElement

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

the class CacheEntryEvaluatorTest method testEvaluateValue_NoErrorOnEmpty_EmptyValue.

@Test
public void testEvaluateValue_NoErrorOnEmpty_EmptyValue() throws Exception {
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    CacheValueTranslator translator = new MetadataCacheValueTranslator(DEFAULT_METADATA_KEY);
    eval.setValueTranslator(translator);
    eval.setErrorOnEmptyValue(false);
    AdaptrisMessage msg = createMessage(new ArrayList<MetadataElement>());
    assertEquals(null, 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)

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