AddMetadataService extends MetadataServiceImpl { public void addMetadataElement(MetadataElement element) { metadataElements.add(element); } AddMetadataService();  AddMetadataService(Collection<MetadataElement> elements);  AddMetadataService(MetadataElement... elements); @Override void doService(AdaptrisMessage msg); Set<MetadataElement> getMetadataElements(); void setMetadataElements(Set<MetadataElement> s); void addMetadataElement(MetadataElement element); void addMetadataElement(String key, String value); Boolean getOverwrite(); void setOverwrite(Boolean b);  }
@Test public void testAddMetadataElement() { AddMetadataService s = new AddMetadataService(); MetadataElement me = new MetadataElement("key3", "val3"); s.addMetadataElement(me); assertTrue(s.getMetadataElements().contains(me)); try { s.addMetadataElement(null, null); fail("expected IllegalArgumnetException on service.addMetadataElement(null, null)"); } catch (IllegalArgumentException e) { } s.addMetadataElement(m1.getKey(), m1.getValue()); assertTrue(s.getMetadataElements().contains(m1)); }
@Test public void testDoServiceWithReferencedKey() throws CoreException { AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance() .newMessage(); msg.addMessageHeader("key999", "key666"); m1 = new MetadataElement("$$key999", "value666"); service = new AddMetadataService(); service.addMetadataElement(m1); execute(service, msg); assertEquals("value666", msg.getMetadataValue("key666")); }
@Test public void testUniqueIdMetadata() throws CoreException { AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance() .newMessage(); MetadataElement m3 = new MetadataElement("key3", "$UNIQUE_ID$"); service.addMetadataElement(m3); execute(service, msg); assertTrue(msg.getMetadataValue("key1").equals("val1")); assertTrue(msg.getMetadataValue("key2").equals("val2")); assertEquals(msg.getUniqueId(), msg.getMetadataValue("key3")); }
@Test public void testFilesizeMetadata() throws CoreException { AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance() .newMessage("The Quick Brown Fox Jumps Over The Lazy Dog"); MetadataElement m3 = new MetadataElement("key3", "$MSG_SIZE$"); service.addMetadataElement(m3); execute(service, msg); assertTrue(msg.getMetadataValue("key1").equals("val1")); assertTrue(msg.getMetadataValue("key2").equals("val2")); assertEquals(String.valueOf(msg.getSize()), msg.getMetadataValue("key3")); }