@Test public void testReadQuestionTemplatesCaps() 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", DUPLICATE_TEMPLATE_NAME.toUpperCase()) .put("description", "test question description")); Path questionJsonPath = _folder.newFile("testquestion.json").toPath(); CommonUtil.writeFile(questionJsonPath, testQuestion.toString()); readQuestionTemplate(questionJsonPath, questionTemplates); assertThat(questionTemplates.keySet(), hasSize(1)); assertThat( questionTemplates, IsMapContaining.hasEntry( DUPLICATE_TEMPLATE_NAME, "{\"instance\":{\"instanceName\":\"DUPLICATE_TEMPLATE\",\"description\":\"test question description\"}}")); }
@VisibleForTesting static String readQuestionTemplate(Path file, Map<String, String> templates) throws JSONException, IOException { String questionText = CommonUtil.readFile(file); JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper().readValue(instanceDataStr, InstanceData.class); String name = instanceData.getInstanceName(); String key = name.toLowerCase(); if (templates.containsKey(key) && _logger != null) { _logger.warnf( "Found duplicate template having instance name %s, only the last one in the list of templatedirs will be loaded\n", name); } templates.put(key, questionText); return name; } else { throw new BatfishException(String.format("Question in file:%s has no instance name", file)); } }
Main { @VisibleForTesting static String readQuestionTemplate(Path file, Map<String, String> templates) throws JSONException, IOException { String questionText = CommonUtil.readFile(file); JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper().readValue(instanceDataStr, InstanceData.class); String name = instanceData.getInstanceName(); String key = name.toLowerCase(); if (templates.containsKey(key) && _logger != null) { _logger.warnf( "Found duplicate template having instance name %s, only the last one in the list of templatedirs will be loaded\n", name); } templates.put(key, questionText); return name; } else { throw new BatfishException(String.format("Question in file:%s has no instance name", file)); } } }
Main { @VisibleForTesting static String readQuestionTemplate(Path file, Map<String, String> templates) throws JSONException, IOException { String questionText = CommonUtil.readFile(file); JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper().readValue(instanceDataStr, InstanceData.class); String name = instanceData.getInstanceName(); String key = name.toLowerCase(); if (templates.containsKey(key) && _logger != null) { _logger.warnf( "Found duplicate template having instance name %s, only the last one in the list of templatedirs will be loaded\n", name); } templates.put(key, questionText); return name; } else { throw new BatfishException(String.format("Question in file:%s has no instance name", file)); } }  }
Main { @VisibleForTesting static String readQuestionTemplate(Path file, Map<String, String> templates) throws JSONException, IOException { String questionText = CommonUtil.readFile(file); JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper().readValue(instanceDataStr, InstanceData.class); String name = instanceData.getInstanceName(); String key = name.toLowerCase(); if (templates.containsKey(key) && _logger != null) { _logger.warnf( "Found duplicate template having instance name %s, only the last one in the list of templatedirs will be loaded\n", name); } templates.put(key, questionText); return name; } else { throw new BatfishException(String.format("Question in file:%s has no instance name", file)); } }  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 String readQuestionTemplate(Path file, Map<String, String> templates) throws JSONException, IOException { String questionText = CommonUtil.readFile(file); JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper().readValue(instanceDataStr, InstanceData.class); String name = instanceData.getInstanceName(); String key = name.toLowerCase(); if (templates.containsKey(key) && _logger != null) { _logger.warnf( "Found duplicate template having instance name %s, only the last one in the list of templatedirs will be loaded\n", name); } templates.put(key, questionText); return name; } else { throw new BatfishException(String.format("Question in file:%s has no instance name", file)); } }  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);  }