MappedKeyMetadataFilter extends MetadataFilterImpl { @Override public MetadataCollection filter(MetadataCollection original) { MetadataCollection result = new MetadataCollection(); for (MetadataElement e : original) { result.add(new MetadataElement(renameKey(e.getKey()), e.getValue())); } return result; } MappedKeyMetadataFilter();  MappedKeyMetadataFilter(String prefix, String replacement); @Override MetadataCollection filter(MetadataCollection original); String getPrefix(); void setPrefix(String s); String getReplacement(); void setReplacement(String s);  }
@Test public void testFilter() { MappedKeyMetadataFilter filterer = new MappedKeyMetadataFilter("^key(.*)$", "actual$1"); AdaptrisMessage message = newMessage(); MetadataCollection resultingCollection = filterer.filter(message); assertEquals(message.getMetadata().size(), resultingCollection.size()); assertTrue(message.getMessageHeaders().containsKey("key1")); assertFalse(resultingCollection.containsKey("key1")); assertFalse(message.getMessageHeaders().containsKey("actual1")); assertTrue(resultingCollection.containsKey("actual1")); }
@Test public void testFilterNoReplacement() { MappedKeyMetadataFilter filterer = new MappedKeyMetadataFilter("key", ""); AdaptrisMessage message = newMessage(); MetadataCollection resultingCollection = filterer.filter(message); assertEquals(message.getMetadata().size(), resultingCollection.size()); assertTrue(message.getMessageHeaders().containsKey("key1")); assertFalse(resultingCollection.containsKey("key1")); assertFalse(message.getMessageHeaders().containsKey("1")); assertTrue(resultingCollection.containsKey("1")); }