Search in sources :

Example 11 with MetadataCollection

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

the class OrderedItemMetadataFilterTest method testFilterIgnoreCase.

@Test
public void testFilterIgnoreCase() {
    OrderedItemMetadataFilter filter = new OrderedItemMetadataFilter();
    filter.setIgnoreCase(true);
    filter.setMetadataKeys(Arrays.asList("key1", "key2", "key3"));
    AdaptrisMessage message = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    message.addMetadata("Key1", "value1");
    message.addMetadata("key3", "value3");
    MetadataCollection collection = filter.filter(message);
    assertEquals(3, collection.size());
    assertEquals("key1", collection.get(0).getKey());
    assertEquals("value1", collection.get(0).getValue());
    assertEquals("key2", collection.get(1).getKey());
    assertEquals("", collection.get(1).getValue());
    assertEquals("key3", collection.get(2).getKey());
    assertEquals("value3", collection.get(2).getValue());
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataCollection(com.adaptris.core.MetadataCollection) Test(org.junit.Test)

Example 12 with MetadataCollection

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

the class PasswordDecodeMetadataFilterTest method testFilter_NoMatches.

@Test
public void testFilter_NoMatches() throws Exception {
    PasswordDecodeMetadataFilter filter = new PasswordDecodeMetadataFilter();
    AdaptrisMessage msg = createMessage();
    MetadataCollection filtered = filter.filter(msg);
    assertEquals(3, filtered.size());
    // Changes not reflected in the underlying message.
    assertNotSame("password1", msg.getMetadataValue("passwordKey1"));
    assertNotSame("password2", msg.getMetadataValue("passwordKey2"));
    assertEquals("PW:WillNotDecode", msg.getMetadataValue("key1"));
    for (MetadataElement e : filtered) {
        if ("passwordKey1".equalsIgnoreCase(e.getKey())) {
            assertTrue(e.getValue().startsWith("PW:"));
        }
        if ("passwordKey2".equalsIgnoreCase(e.getKey())) {
            assertTrue(e.getValue().startsWith("PW:"));
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataCollection(com.adaptris.core.MetadataCollection) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 13 with MetadataCollection

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

the class PasswordDecodeMetadataFilterTest method testFilterWithException.

@Test
public void testFilterWithException() throws Exception {
    PasswordDecodeMetadataFilter filter = new PasswordDecodeMetadataFilter().withPatterns("^.*password.*$", "^.*secret.*$");
    AdaptrisMessage msg = createMessage();
    msg.addMetadata("passwordKey3", "PW:Does_Not_Compute");
    try {
        MetadataCollection filtered = filter.filter(msg);
        fail();
    } catch (RuntimeException expected) {
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataCollection(com.adaptris.core.MetadataCollection) Test(org.junit.Test)

Example 14 with MetadataCollection

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

the class PasswordDecodeMetadataFilterTest method testFilter.

@Test
public void testFilter() throws Exception {
    PasswordDecodeMetadataFilter filter = new PasswordDecodeMetadataFilter().withPatterns("^.*password.*$", "^.*secret.*$");
    AdaptrisMessage msg = createMessage();
    MetadataCollection filtered = filter.filter(msg);
    assertEquals(3, filtered.size());
    // Changes not reflected in the underlying message.
    assertNotSame("password1", msg.getMetadataValue("passwordKey1"));
    assertNotSame("password2", msg.getMetadataValue("passwordKey2"));
    assertEquals("PW:WillNotDecode", msg.getMetadataValue("key1"));
    assertPasswords(filtered);
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataCollection(com.adaptris.core.MetadataCollection) Test(org.junit.Test)

Example 15 with MetadataCollection

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

the class RemoveAllMetadataFilterTest method testFilterSet.

@Test
public void testFilterSet() throws Exception {
    RemoveAllMetadataFilter filter = new RemoveAllMetadataFilter();
    MetadataCollection c = filter.filter(createMessage().getMetadata());
    assertEquals(0, c.size());
}
Also used : 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