MetadataResourceResolver { public SortedMap<String, String> getSourceMetadataPaths(String sourcePath) throws IOException { final String basename = getBasename(sourcePath); final String dirname = getDirname(sourcePath); final String wantedPrefix = removeFileExtension(basename) + "-"; SortedMap<String, String> sourceNames = new TreeMap<String, String>(); String[] directoryList = simpleFileSystem.list(dirname); if (directoryList != null) { for (String filename : directoryList) { if (!filename.equalsIgnoreCase(basename) && filename.startsWith(wantedPrefix)) { String metadataBaseName = filename.substring(wantedPrefix.length()); if (dirname.isEmpty()) { sourceNames.put(metadataBaseName, filename); } else { sourceNames.put(metadataBaseName, dirname + "/" + filename); } } } } return sourceNames; } MetadataResourceResolver(SimpleFileSystem simpleFileSystem); SortedMap<String, String> getSourceMetadataPaths(String sourcePath); TargetResourceInfo getTargetName(String templatePath, String targetPath); static final String VELOCITY_TEMPLATE_EXTENSION; }
@Test public void testGetSourceNames() throws Exception { SimpleFileSystem fileSystem = mock(SimpleFileSystem.class); MetadataResourceResolver resolver = new MetadataResourceResolver(fileSystem); when(fileSystem.isFile(anyString())).thenReturn(true); when(fileSystem.list(anyString())).thenReturn(new String[]{"file1", "product-file2.xml", "file3", "product-file4.properties"}); SortedMap<String,String> sourceMetadataPaths= resolver.getSourceMetadataPaths("/bla/bli/product.dim"); assertEquals(2, sourceMetadataPaths.size()); assertEquals("/bla/bli/product-file2.xml", sourceMetadataPaths.get("file2.xml")); assertEquals("/bla/bli/product-file4.properties", sourceMetadataPaths.get("file4.properties")); }