@Test public void testLoadQuestionsFromDir() throws Exception { JSONObject testQuestion = new JSONObject(); testQuestion.put( "instance", new JSONObject() .put("instanceName", "testQuestionName") .put("description", "test question description")); Path questionJsonPath = _folder.newFile("testquestion.json").toPath(); CommonUtil.writeFile(questionJsonPath, testQuestion.toString()); Multimap<String, String> loadedQuestions = Client.loadQuestionsFromDir(questionJsonPath.toString(), null); Multimap<String, String> expectedMap = HashMultimap.create(); expectedMap.put("testQuestionName", testQuestion.toString()); assertEquals(expectedMap, loadedQuestions); }
static Multimap<String, String> loadQuestionsFromDir( String questionsPathStr, @Nullable BatfishLogger logger) { Path questionsPath = Paths.get(questionsPathStr); SortedSet<Path> jsonQuestionFiles = new TreeSet<>(); try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), 1, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { jsonQuestionFiles.add(file); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit questions dir", e); } Multimap<String, String> loadedQuestions = HashMultimap.create(); for (Path jsonQuestionFile : jsonQuestionFiles) { try { JSONObject questionJSON = loadQuestionFromFile(jsonQuestionFile); loadedQuestions.put( getQuestionName(questionJSON, jsonQuestionFile.toString()), questionJSON.toString()); } catch (Exception e) { if (logger != null) { logger.errorf("Could not load template from %s: %s", jsonQuestionFile, e); } } } return loadedQuestions; }
Client extends AbstractClient implements IClient { static Multimap<String, String> loadQuestionsFromDir( String questionsPathStr, @Nullable BatfishLogger logger) { Path questionsPath = Paths.get(questionsPathStr); SortedSet<Path> jsonQuestionFiles = new TreeSet<>(); try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), 1, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { jsonQuestionFiles.add(file); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit questions dir", e); } Multimap<String, String> loadedQuestions = HashMultimap.create(); for (Path jsonQuestionFile : jsonQuestionFiles) { try { JSONObject questionJSON = loadQuestionFromFile(jsonQuestionFile); loadedQuestions.put( getQuestionName(questionJSON, jsonQuestionFile.toString()), questionJSON.toString()); } catch (Exception e) { if (logger != null) { logger.errorf("Could not load template from %s: %s", jsonQuestionFile, e); } } } return loadedQuestions; } }
Client extends AbstractClient implements IClient { static Multimap<String, String> loadQuestionsFromDir( String questionsPathStr, @Nullable BatfishLogger logger) { Path questionsPath = Paths.get(questionsPathStr); SortedSet<Path> jsonQuestionFiles = new TreeSet<>(); try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), 1, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { jsonQuestionFiles.add(file); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit questions dir", e); } Multimap<String, String> loadedQuestions = HashMultimap.create(); for (Path jsonQuestionFile : jsonQuestionFiles) { try { JSONObject questionJSON = loadQuestionFromFile(jsonQuestionFile); loadedQuestions.put( getQuestionName(questionJSON, jsonQuestionFile.toString()), questionJSON.toString()); } catch (Exception e) { if (logger != null) { logger.errorf("Could not load template from %s: %s", jsonQuestionFile, e); } } } return loadedQuestions; } Client(Settings settings);  Client(String[] args); }
Client extends AbstractClient implements IClient { static Multimap<String, String> loadQuestionsFromDir( String questionsPathStr, @Nullable BatfishLogger logger) { Path questionsPath = Paths.get(questionsPathStr); SortedSet<Path> jsonQuestionFiles = new TreeSet<>(); try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), 1, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { jsonQuestionFiles.add(file); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit questions dir", e); } Multimap<String, String> loadedQuestions = HashMultimap.create(); for (Path jsonQuestionFile : jsonQuestionFiles) { try { JSONObject questionJSON = loadQuestionFromFile(jsonQuestionFile); loadedQuestions.put( getQuestionName(questionJSON, jsonQuestionFile.toString()), questionJSON.toString()); } catch (Exception e) { if (logger != null) { logger.errorf("Could not load template from %s: %s", jsonQuestionFile, e); } } } return loadedQuestions; } Client(Settings settings);  Client(String[] args); @Override BatfishLogger getLogger(); Settings getSettings(); void run(List<String> initialCommands); }
Client extends AbstractClient implements IClient { static Multimap<String, String> loadQuestionsFromDir( String questionsPathStr, @Nullable BatfishLogger logger) { Path questionsPath = Paths.get(questionsPathStr); SortedSet<Path> jsonQuestionFiles = new TreeSet<>(); try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), 1, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { jsonQuestionFiles.add(file); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit questions dir", e); } Multimap<String, String> loadedQuestions = HashMultimap.create(); for (Path jsonQuestionFile : jsonQuestionFiles) { try { JSONObject questionJSON = loadQuestionFromFile(jsonQuestionFile); loadedQuestions.put( getQuestionName(questionJSON, jsonQuestionFile.toString()), questionJSON.toString()); } catch (Exception e) { if (logger != null) { logger.errorf("Could not load template from %s: %s", jsonQuestionFile, e); } } } return loadedQuestions; } Client(Settings settings);  Client(String[] args); @Override BatfishLogger getLogger(); Settings getSettings(); void run(List<String> initialCommands);  }