ReadMetadataFromFilesystem extends MetadataServiceImpl { public void setOverwriteExistingMetadata(Boolean b) { overwriteExistingMetadata = b; } ReadMetadataFromFilesystem();  ReadMetadataFromFilesystem(MessageDrivenDestination d); @Override void doService(AdaptrisMessage msg); InputStyle getInputStyle(); void setInputStyle(InputStyle style); MessageDrivenDestination getDestination(); void setDestination(MessageDrivenDestination d); Boolean getOverwriteExistingMetadata(); void setOverwriteExistingMetadata(Boolean b); boolean overwriteExistingMetadata(); FileNameCreator getFilenameCreator(); void setFilenameCreator(FileNameCreator creator);  }
@Test public void testService_OverwriteExistingMetadata() throws Exception { String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", ""); AdaptrisMessage msg = new DefaultMessageFactory().newMessage(); msg.addMetadata("key5", "MyValue"); ReadMetadataFromFilesystem service = createService(subDir); service.setOverwriteExistingMetadata(true); File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_DIR), true)); String propsFilename = parentDir.getCanonicalPath() + "/" + subDir + "/" + msg.getUniqueId(); Properties p = createProperties(); writeProperties(p, new File(propsFilename), false); execute(service, msg); assertTrue(msg.headersContainsKey("key5")); assertEquals("v5", msg.getMetadataValue("key5")); }
@Test public void testService_DoNotOverwriteExistingMetadata() throws Exception { String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", ""); AdaptrisMessage msg = new DefaultMessageFactory().newMessage(); msg.addMetadata("key5", "MyValue"); ReadMetadataFromFilesystem service = createService(subDir); service.setOverwriteExistingMetadata(false); File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_DIR), true)); String propsFilename = parentDir.getCanonicalPath() + "/" + subDir + "/" + msg.getUniqueId(); Properties p = createProperties(); writeProperties(p, new File(propsFilename), false); execute(service, msg); assertTrue(msg.headersContainsKey("key5")); assertEquals("MyValue", msg.getMetadataValue("key5")); }