@Test public void testReadQuestionTemplatesRecursive() throws Exception { JSONObject testQuestion1 = new JSONObject(); testQuestion1.put( "instance", new JSONObject() .put("instanceName", "testQuestion1") .put("description", "test question one description")); Path question1JsonPath = _folder.newFile("testquestion1.json").toPath(); CommonUtil.writeFile(question1JsonPath, testQuestion1.toString()); JSONObject testQuestion2 = new JSONObject(); testQuestion2.put( "instance", new JSONObject() .put("instanceName", "testQuestion2") .put("description", "test question two description")); File nestedFolder = _folder.newFolder("nestedFolder"); Path question2JsonPath = nestedFolder.toPath().resolve("testquestions2.json"); CommonUtil.writeFile(question2JsonPath, testQuestion2.toString()); Map<String, String> questionTemplates = Maps.newHashMap(); readQuestionTemplates(_folder.getRoot().toPath(), questionTemplates); assertThat(questionTemplates.keySet(), hasSize(2)); assertThat( questionTemplates, allOf( IsMapContaining.hasEntry( "testquestion1", "{\"instance\":{\"instanceName\":\"testQuestion1\",\"description\":\"test question one description\"}}"), IsMapContaining.hasEntry( "testquestion2", "{\"instance\":{\"instanceName\":\"testQuestion2\",\"description\":\"test question two 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);  }