@Test public void testReadQuestionTemplates() throws Exception { Map<String, String> questionTemplates = Maps.newHashMap(); questionTemplates.put(DUPLICATE_TEMPLATE_NAME, "template_body"); JSONObject testQuestion = new JSONObject(); testQuestion.put( "instance", new JSONObject() .put("instanceName", NEW_TEMPLATE_NAME) .put("description", "test question description")); Path questionJsonPath = _folder.newFile("testquestion.json").toPath(); CommonUtil.writeFile(questionJsonPath, testQuestion.toString()); readQuestionTemplate(questionJsonPath, questionTemplates); assertThat(questionTemplates.keySet(), hasSize(2)); assertThat( questionTemplates, allOf( IsMapContaining.hasEntry(DUPLICATE_TEMPLATE_NAME, "template_body"), IsMapContaining.hasEntry( NEW_TEMPLATE_NAME, "{\"instance\":{\"instanceName\":\"new_template\",\"description\":\"test question description\"}}"))); }
@VisibleForTesting static void readQuestionTemplates(Path questionsPath, Map<String, String> templates) { try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { try { readQuestionTemplate(file, templates); } catch (Exception e) { _logger.errorf( "Failed to read question template from '%s': %s", file, Throwables.getStackTraceAsString(e)); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit templates dir: " + questionsPath, e); } }
Main { @VisibleForTesting static void readQuestionTemplates(Path questionsPath, Map<String, String> templates) { try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { try { readQuestionTemplate(file, templates); } catch (Exception e) { _logger.errorf( "Failed to read question template from '%s': %s", file, Throwables.getStackTraceAsString(e)); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit templates dir: " + questionsPath, e); } } }
Main { @VisibleForTesting static void readQuestionTemplates(Path questionsPath, Map<String, String> templates) { try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { try { readQuestionTemplate(file, templates); } catch (Exception e) { _logger.errorf( "Failed to read question template from '%s': %s", file, Throwables.getStackTraceAsString(e)); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit templates dir: " + questionsPath, e); } }  }
Main { @VisibleForTesting static void readQuestionTemplates(Path questionsPath, Map<String, String> templates) { try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { try { readQuestionTemplate(file, templates); } catch (Exception e) { _logger.errorf( "Failed to read question template from '%s': %s", file, Throwables.getStackTraceAsString(e)); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit templates dir: " + questionsPath, e); } }  static Authorizer getAuthorizer(); static BatfishLogger getLogger(); static PoolMgr getPoolMgr(); @Nullable static Map<String, String> getQuestionTemplates(); @Nullable static Map<String, String> getQuestionTemplates(boolean verbose); static Settings getSettings(); static WorkMgr getWorkMgr(); static void setLogger(BatfishLogger logger); static void setWorkMgr(WorkMgr workManager); static void setAuthorizer(Authorizer authorizer); static void main(String[] args, BatfishLogger logger, BindPortFutures portFutures); static void mainInit(String[] args); }
Main { @VisibleForTesting static void readQuestionTemplates(Path questionsPath, Map<String, String> templates) { try { Files.walkFileTree( questionsPath, EnumSet.of(FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { try { readQuestionTemplate(file, templates); } catch (Exception e) { _logger.errorf( "Failed to read question template from '%s': %s", file, Throwables.getStackTraceAsString(e)); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new BatfishException("Failed to visit templates dir: " + questionsPath, e); } }  static Authorizer getAuthorizer(); static BatfishLogger getLogger(); static PoolMgr getPoolMgr(); @Nullable static Map<String, String> getQuestionTemplates(); @Nullable static Map<String, String> getQuestionTemplates(boolean verbose); static Settings getSettings(); static WorkMgr getWorkMgr(); static void setLogger(BatfishLogger logger); static void setWorkMgr(WorkMgr workManager); static void setAuthorizer(Authorizer authorizer); static void main(String[] args, BatfishLogger logger, BindPortFutures portFutures); static void mainInit(String[] args);  }