### Question:
IngestSourceManagerImpl implements IngestSourceManager { @Override public IngestSource getIngestSourceForUri(URI uri) { for (IngestSource source: ingestSources) { if (source.isValidUri(uri)) { return source; } } throw new UnknownIngestSourceException("No ingest sources match URI " + uri); }  void init(); @Override List<IngestSource> listSources(PID target); @Override List<IngestSourceCandidate> listCandidates(PID destination); @Override IngestSource getIngestSourceById(String id); @Override IngestSource getIngestSourceForUri(URI uri); void setConfigPath(String configPath); void setMappingPath(String mappingPath); void setContentPathFactory(ContentPathFactory contentPathFactory);  }### Answer:
@Test public void testGetIngestSourceForUri_NestedUri() throws Exception { configPath = createConfigFile(createBasicConfig("testsource", destPid)); Path source2FolderPath = tmpFolder.newFolder().toPath(); Map<String, Object> source2 = createConfig( "testsource2", "Source 2", source2FolderPath, asList("*"), destPid); configPath = createConfigFile(source2, createBasicConfig("testsource", destPid)); Path targetPath = addBagToSource(sourceFolderPath); initializeManager(); IngestSource source = sourceMan.getIngestSourceForUri(targetPath.toUri()); assertEquals("testsource", source.getId()); }
@Test public void testGetIngestSourceForUri_ValidPathTargetNotExist() throws Exception { configPath = createConfigFile(createBasicConfig("testsource", destPid)); initializeManager(); URI targetUri = sourceFolderPath.resolve("my_target").toUri(); IngestSource source = sourceMan.getIngestSourceForUri(targetUri); assertEquals("testsource", source.getId()); }
@Test public void testGetIngestSourceForUri_NestedPath() throws Exception { configPath = createConfigFile(createBasicConfig("testsource", destPid)); Path bagPath = addBagToSource(sourceFolderPath); Path nestedPath = bagPath.resolve("data/test1.txt"); initializeManager(); IngestSource source = sourceMan.getIngestSourceForUri(nestedPath.toUri()); assertEquals("testsource", source.getId()); }
@Test public void testGetIngestSourceForUri_NestedNotExist() throws Exception { configPath = createConfigFile(createBasicConfig("testsource", destPid)); Path bagPath = addBagToSource(sourceFolderPath); Path nestedPath = bagPath.resolve("data/somewhere.txt"); initializeManager(); IngestSource source = sourceMan.getIngestSourceForUri(nestedPath.toUri()); assertEquals("testsource", source.getId()); }