RuntimeModelLoader { protected void loadAvailableModels() { logger.info("Registering existing models"); try (Stream<java.nio.file.Path> walk = Files.walk(Paths.get(runtimeOptions.getImportsBaseDir()), 1)) { walk.filter(p -> p.toFile().isFile() && p.toString().toLowerCase().endsWith(DASHBOARD_EXTENSION)) .map(Object::toString) .forEach(p -> { logger.info("Registering {}", p); runtimeModelRegistry.registerFile(p); logger.info("Sucessfully Registered {}", p); }); } catch (Exception e) { throw new RuntimeException("Error registering existing models.", e); } }    }
@Test public void testLoadAvailableModels() throws IOException { String baseDir = baseTempDir.toString(); when(runtimeOptions.getImportsBaseDir()).thenReturn(baseDir); Path p1 = Paths.get(baseDir, "model1" + RuntimeOptions.DASHBOARD_EXTENSION); Path p2 = Paths.get(baseDir, "model2" + RuntimeOptions.DASHBOARD_EXTENSION); Path p3 = Paths.get(baseDir, "ignored.bkp"); Path p4 = Paths.get(baseDir, "intermediary", "ignored.bkp"); p4.toFile().getParentFile().mkdirs(); for (Path p : Arrays.asList(p1, p2, p3, p4)) { p.toFile().createNewFile(); } runtimeModelLoader.loadAvailableModels(); verify(registry).registerFile(matches(p1.toString())); verify(registry).registerFile(matches(p2.toString())); verify(registry, times(0)).registerFile(matches(p3.toString())); verify(registry, times(0)).registerFile(matches(p4.toString())); }