MetadataFilterService extends MetadataServiceImpl { public void setFilter(MetadataFilter mf) { filter = Args.notNull(mf, "filter"); } MetadataFilterService(); @Override void doService(AdaptrisMessage msg); MetadataFilter getFilter(); void setFilter(MetadataFilter mf); MetadataFilterService withFilter(MetadataFilter mf);  }
@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()); }
@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)); }
@Test public void testServiceInclude() throws Exception { AdaptrisMessage msg = createMessage(); MetadataFilterService service = new MetadataFilterService(); RegexMetadataFilter filter = new RegexMetadataFilter(); filter.addIncludePattern(REG_EXP); service.setFilter(filter); execute(service, msg); assertFalse(msg.containsKey(JMS_MESSAGE_ID)); assertEquals(DEF_VALUE, msg.getMetadataValue(JMS_KEY_1)); assertEquals(DEF_VALUE, msg.getMetadataValue(JMS_KEY_2)); assertEquals(DEF_VALUE, msg.getMetadataValue(JMS_KEY_3)); }
@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)); }