Search in sources :

Example 6 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class WriteMetadataToFilesystemTest method testService_Filter.

@Test
public void testService_Filter() throws Exception {
    String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", "");
    AdaptrisMessage msg = createMessage();
    WriteMetadataToFilesystem service = createService(subDir);
    RegexMetadataFilter filter = new RegexMetadataFilter();
    filter.addIncludePattern("alt_key.*");
    filter.addExcludePattern("^key.*");
    service.setMetadataFilter(filter);
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_DIR), true));
    String propsFilename = parentDir.getCanonicalPath() + "/" + subDir + "/" + msg.getUniqueId();
    execute(service, msg);
    Properties p = readProperties(new File(propsFilename), false);
    assertFalse(p.containsKey("key5"));
    assertTrue(p.containsKey("alt_key5"));
    assertEquals("av5", p.getProperty("alt_key5"));
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 7 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class WriteMetadataToFilesystemTest method testSetMetadataFilter.

@Test
public void testSetMetadataFilter() throws Exception {
    WriteMetadataToFilesystem service = new WriteMetadataToFilesystem();
    assertNull(service.getMetadataFilter());
    service.setMetadataFilter(new RegexMetadataFilter());
    assertEquals(RegexMetadataFilter.class, service.getMetadataFilter().getClass());
    service.setMetadataFilter(null);
    assertEquals(NoOpMetadataFilter.class, service.metadataFilter().getClass());
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) Test(org.junit.Test)

Example 8 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class MetadataFilterServiceTest method testServiceIncludesAndExcludes.

@Test
public void testServiceIncludesAndExcludes() throws Exception {
    AdaptrisMessage msg = createMessage();
    MetadataFilterService service = new MetadataFilterService();
    RegexMetadataFilter filter = new RegexMetadataFilter();
    filter.addExcludePattern(REG_EXP);
    filter.addIncludePattern(MATCH_ANY);
    service.setFilter(filter);
    execute(service, msg);
    assertEquals(DEF_VALUE, msg.getMetadataValue(JMS_MESSAGE_ID));
    assertFalse(msg.containsKey(JMS_KEY_1));
    assertFalse(msg.containsKey(JMS_KEY_2));
    assertFalse(msg.containsKey(JMS_KEY_3));
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 9 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class MetadataFilterServiceTest method testSetFilter.

@Test
public void testSetFilter() {
    MetadataFilterService service = new MetadataFilterService();
    assertEquals(NoOpMetadataFilter.class, service.getFilter().getClass());
    service.setFilter(new RegexMetadataFilter());
    assertEquals(RegexMetadataFilter.class, service.getFilter().getClass());
    try {
        service.setFilter(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(RegexMetadataFilter.class, service.getFilter().getClass());
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) Test(org.junit.Test)

Example 10 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class MetadataFilterServiceTest method testServiceExclude.

@Test
public void testServiceExclude() throws Exception {
    AdaptrisMessage msg = createMessage();
    MetadataFilterService service = new MetadataFilterService();
    RegexMetadataFilter filter = new RegexMetadataFilter();
    filter.addExcludePattern(REG_EXP);
    service.setFilter(filter);
    execute(service, msg);
    assertEquals(DEF_VALUE, msg.getMetadataValue(JMS_MESSAGE_ID));
    assertFalse(msg.containsKey(JMS_KEY_1));
    assertFalse(msg.containsKey(JMS_KEY_2));
    assertFalse(msg.containsKey(JMS_KEY_3));
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

RegexMetadataFilter (com.adaptris.core.metadata.RegexMetadataFilter)33 Test (org.junit.Test)25 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)19 Channel (com.adaptris.core.Channel)8 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)5 Session (javax.jms.Session)5 StandaloneProducer (com.adaptris.core.StandaloneProducer)4 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)4 Message (javax.jms.Message)4 MetadataElement (com.adaptris.core.MetadataElement)3 MessageTypeTranslatorImp (com.adaptris.core.jms.MessageTypeTranslatorImp)3 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 ServiceList (com.adaptris.core.ServiceList)2 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)2 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)2 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)2 KeyValuePair (com.adaptris.util.KeyValuePair)2 CoreException (com.adaptris.core.CoreException)1