Search in sources :

Example 46 with MetadataCollection

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

the class ExampleEventHandlerCase method testSendEvent_WithProperties.

@Test
public void testSendEvent_WithProperties() throws Exception {
    Event e = EventFactory.create(AdapterCloseEvent.class);
    T eh = applyConfiguration(newEventHandler(getName()));
    Map<String, String> properties = MetadataCollection.asMap(new MetadataCollection(new MetadataElement("hello", "world")));
    try {
        eh.requestStart();
        eh.send(e, properties);
        doAssertions(eh, 1, e.getClass());
        MockMessageProducer p = getProducer(eh);
        AdaptrisMessage msg = p.getMessages().get(0);
        assertTrue(msg.headersContainsKey("hello"));
        assertEquals("world", msg.getMetadataValue("hello"));
    } finally {
        eh.requestClose();
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AdapterCloseEvent(com.adaptris.core.event.AdapterCloseEvent) Event(com.adaptris.core.Event) MetadataCollection(com.adaptris.core.MetadataCollection) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 47 with MetadataCollection

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

the class MetadataHandler method moveMetadata.

/**
 * <p>
 * Moves metadata from an <code>AdaptrisMessage</code> to a <code>javax.jms.Message</code> if <code>moveMetadata</code> is
 * <code>true</code>.
 * </p>
 *
 * @param in the <code>AdaptrisMessage</code> to move metadata from
 * @param out the JMS <code>Message</code> to move metadata to
 * @return the JMS <code>Message</code> with metadata added
 * @throws JMSException
 */
public final Message moveMetadata(AdaptrisMessage in, Message out) throws JMSException {
    MetadataCollection metadataCollection = context.metadataFilter().filter(in);
    if (context.metadataConverters().size() == 0) {
        new StringMetadataConverter().moveMetadata(metadataCollection, out);
    } else {
        for (MetadataConverter converter : context.metadataConverters()) {
            converter.moveMetadata(metadataCollection, out);
        }
    }
    out.setStringProperty(MESSAGE_UNIQUE_ID_KEY, in.getUniqueId());
    if (context.moveJmsHeaders()) {
        moveJmsHeaders(in, out);
    }
    return out;
}
Also used : MetadataCollection(com.adaptris.core.MetadataCollection)

Example 48 with MetadataCollection

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

the class MetadataHandler method createMetadataCollection.

private MetadataCollection createMetadataCollection(Message in) throws JMSException {
    MetadataCollection result = new MetadataCollection();
    Enumeration<?> props = in.getPropertyNames();
    while (props.hasMoreElements()) {
        String key = (String) props.nextElement();
        // converts all to Strings
        String value = in.getStringProperty(key);
        if (!isEmpty(value)) {
            result.add(new MetadataElement(key, value));
        } else {
            log.debug("ignoring null or empty metadata value against key [" + key + "]");
        }
    }
    return result;
}
Also used : MetadataCollection(com.adaptris.core.MetadataCollection) MetadataElement(com.adaptris.core.MetadataElement)

Example 49 with MetadataCollection

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

the class FixedValuesMetadataFilterTest method testFilterCollection.

@Test
public void testFilterCollection() throws Exception {
    FixedValuesMetadataFilter filter = new FixedValuesMetadataFilter().withMetadata(new KeyValuePair("hello", "world"));
    MetadataCollection c = filter.filter(new MetadataCollection(createMessage().getMetadata()));
    assertEquals(1, c.size());
    Map<String, String> map = MetadataCollection.asMap(c);
    assertFalse(map.containsKey("someRandomKey"));
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) MetadataCollection(com.adaptris.core.MetadataCollection) Test(org.junit.Test)

Example 50 with MetadataCollection

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

the class FixedValuesMetadataFilterTest method testFilterSet.

@Test
public void testFilterSet() throws Exception {
    FixedValuesMetadataFilter filter = new FixedValuesMetadataFilter().withMetadata(new KeyValuePair("hello", "world"));
    MetadataCollection c = filter.filter(createMessage().getMetadata());
    assertEquals(1, c.size());
    Map<String, String> map = MetadataCollection.asMap(c);
    assertFalse(map.containsKey("someRandomKey"));
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) MetadataCollection(com.adaptris.core.MetadataCollection) Test(org.junit.Test)

Aggregations

MetadataCollection (com.adaptris.core.MetadataCollection)66 Test (org.junit.Test)43 MetadataElement (com.adaptris.core.MetadataElement)18 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)12 KeyValuePair (com.adaptris.util.KeyValuePair)4 Message (javax.jms.Message)4 Session (javax.jms.Session)4 MultiPartOutput (com.adaptris.util.text.mime.MultiPartOutput)3 InternetHeaders (javax.mail.internet.InternetHeaders)2 MimeBodyPart (javax.mail.internet.MimeBodyPart)2 Event (com.adaptris.core.Event)1 AdapterCloseEvent (com.adaptris.core.event.AdapterCloseEvent)1 MetadataFilterImpl (com.adaptris.core.metadata.MetadataFilterImpl)1 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Properties (java.util.Properties)1 JMSException (javax.jms.JMSException)1