AppConfigValidationFactory { @SuppressWarnings("unchecked") public static ValidateResult whiteListHandle(Map<String, Object> config) { ValidateResult validateResult = new ValidateResult(); String jsonStr = CommonUtil.readJsonFile("whitelist.json"); Gson gson = new Gson(); List<Map<String, Map<String,List<Map<String, String>>>>> whiteList = gson.fromJson(jsonStr, List.class); return processAppConfigValidation(config,validateResult,whiteList,ValidationType.WHITE_LIST); }  @SuppressWarnings("unchecked") static void validateConfigType(Map<String, Object> config, List<String> warningMsgList); @SuppressWarnings("unchecked") static ValidateResult blackListHandle(Map<String, Object> config); @SuppressWarnings("unchecked") static ValidateResult whiteListHandle(Map<String, Object> config);  }
@Test public void testWhiteListHandle() { ValidateResult hadoopValidateResult=AppConfigValidationFactory.whiteListHandle(cluster.getNodeGroups()[0].getConfiguration()); assertEquals(hadoopValidateResult.getType(),ValidateResult.Type.WHITE_LIST_INVALID_NAME); assertEquals(hadoopValidateResult.getFailureNames().get(0), "dfs.namenode.test.level"); assertEquals(hadoopValidateResult.getFailureNames().get(1), "dfs.namenode.logger.level"); ValidateResult zookeeperValidateResult=AppConfigValidationFactory.whiteListHandle(cluster.getNodeGroups()[1].getConfiguration()); assertEquals(zookeeperValidateResult.getType(),ValidateResult.Type.WHITE_LIST_INVALID_NAME); assertEquals(zookeeperValidateResult.getFailureNames().size(), 1); assertEquals(zookeeperValidateResult.getFailureNames().get(0), "other"); ValidateResult noExistingValidateResult=AppConfigValidationFactory.whiteListHandle(cluster.getNodeGroups()[2].getConfiguration()); assertEquals(noExistingValidateResult.getType(),ValidateResult.Type.WHITE_LIST_INVALID_NAME); assertEquals(noExistingValidateResult.getNoExistFileNames().get("zookeeper").size(),3); Map<String, Object> fairSchedulerMap = new HashMap<String,Object>(); fairSchedulerMap.put("text", "<?xml version=\"1.0\"?>" + "<allocations> <pool name=\"sample_pool\"><minMaps>5</minMaps>" + "<minReduces>5</minReduces><maxMaps>25</maxMaps><maxReduces>25</maxReduces>" + "<minSharePreemptionTimeout>300</minSharePreemptionTimeout></pool>" + "<user name=\"sample_user\"><maxRunningJobs>6</maxRunningJobs></user>" + "<userMaxJobsDefault>3</userMaxJobsDefault><fairSharePreemptionTimeout>600k" + "</fairSharePreemptionTimeout></allocations>"); ((Map<String, Object>)cluster.getNodeGroups()[0].getConfiguration().get("hadoop")).put("fair-scheduler.xml", fairSchedulerMap); hadoopValidateResult=AppConfigValidationFactory.whiteListHandle(cluster.getNodeGroups()[0].getConfiguration()); assertEquals(hadoopValidateResult.getType(),ValidateResult.Type.WHITE_LIST_INVALID_VALUE); assertEquals(hadoopValidateResult.getFailureValues().get(0), "600k"); fairSchedulerMap.put("text", "<allocations> <pool name=\"sample_pool\"><minMaps>5</minMaps>" + "<minReduces>5</minReduces><maxMaps>25</maxMaps><maxReduces>25</maxReduces>" + "<minSharePreemptionTimeout>300</minSharePreemptionTimeout></pool>" + "<user name=\"sample_user\"><maxRunningJobs>6</maxRunningJobs></user>" + "<userMaxJobsDefault>3</userMaxJobsDefault><fairSharePreemptionTimeout>600k" + "</fairSharePreemptionTimeout>"); ((Map<String, Object>)cluster.getNodeGroups()[0].getConfiguration().get("hadoop")).put("fair-scheduler.xml", fairSchedulerMap); hadoopValidateResult=AppConfigValidationFactory.whiteListHandle(cluster.getNodeGroups()[0].getConfiguration()); assertEquals(hadoopValidateResult.getType(),ValidateResult.Type.WHITE_LIST_INVALID_VALUE); assertEquals(hadoopValidateResult.getFailureValues().get(0), "<allocations> <pool name=\"sample_pool\"><minMaps>5</minMaps>" + "<minReduces>5</minReduces><maxMaps>25</maxMaps><maxReduces>25</maxReduces>" + "<minSharePreemptionTimeout>300</minSharePreemptionTimeout></pool>" + "<user name=\"sample_user\"><maxRunningJobs>6</maxRunningJobs></user>" + "<userMaxJobsDefault>3</userMaxJobsDefault><fairSharePreemptionTimeout>600k" + "</fairSharePreemptionTimeout>"); }