XmlPropertiesFileMetadataLoader implements MetadataLoader { public Map<String, String> loadMetadata(File file) { Map<String, String> metadata = null; if ( hasMetadata(file) ) { String metadataFilename = file.getAbsolutePath() + "." + XML_METADATA_EXTENSION; Properties properties = new Properties(); try { FileInputStream fileInputStream = new FileInputStream(metadataFilename); try { properties.loadFromXML(fileInputStream); } catch (IOException e) { logger.error(e.getMessage(), e); throw new Move2AlfException(e.getMessage(), e); } finally { try { fileInputStream.close(); } catch (IOException e) { logger.warn(e.getMessage(), e); } } properties.remove("type"); properties.remove("aspects"); @SuppressWarnings({ "unchecked", "rawtypes" }) Map<String, String> propertyMap = new HashMap<String, String>((Map) properties); metadata = propertyMap; } catch (FileNotFoundException e) { logger.error(e.getMessage(), e); throw new Move2AlfException(e.getMessage(), e); } } else { metadata = new HashMap<String, String>(); } return metadata; }  boolean hasMetadata(File file); Map<String, String> loadMetadata(File file);  }
@Test public final void testLoadMetadataForContentFile() { Map<String, String> metadata = metadataLoader.loadMetadata(contentFile); assertEquals(1, metadata.size()); assertNull(metadata.get("type")); assertNull(metadata.get("aspects")); assertEquals("ikke", metadata.get("contributor")); }
@Test public final void testLoadMetadataForMetadataFile() { Map<String, String> metadata = metadataLoader.loadMetadata(metadataFile); assertEquals(0, metadata.size()); }
@Test (expected = Move2AlfException.class) public final void testLoadMetadataForNonExistingContentFile() { File file = new File(DIR, "xyz"); @SuppressWarnings("unused") Map<String, String> metadata = metadataLoader.loadMetadata(file); }
@Test (expected = Move2AlfException.class) public final void testLoadMetadataForCorruptPropertiesFile() { File file = new File(DIR, "testfile_metadataCorrupt.txt"); @SuppressWarnings("unused") Map<String, String> metadata = metadataLoader.loadMetadata(file); }