@Test public void getConfigurationsMapTest() throws Exception { String str = "{\"name\":\"123\",\"profiles\":[\"123\"],\"label\":\"123\",\"version\":null,\"state\":null,\"propertySources\":[{\"name\":\"rule-stg\",\"source\":{\"test\":\"test\"}},{\"name\":\"application-stg\",\"source\":{\"test\":\"test\"}}]}"; JsonParser jsonParser = new JsonParser(); JsonObject jo = (JsonObject)jsonParser.parse(str); mockStatic(CommonHttpUtils.class); when(CommonHttpUtils.getEnvironmentVariable(anyString())).thenReturn("123"); when(CommonHttpUtils.getHeader(anyString())).thenReturn(new HashMap<String, Object>()); when(CommonHttpUtils.getConfigurationsFromConfigApi(anyString(),anyObject())).thenReturn(jo); assertThat(configManager.getConfigurationsMap(), is(notNullValue())); when(CommonHttpUtils.getConfigurationsFromConfigApi(anyString(),anyObject())).thenReturn(jo); assertThat(configManager.getConfigurationsMap(), is(notNullValue())); when(CommonHttpUtils.getEnvironmentVariable(anyString())).thenReturn(null); assertThatThrownBy( () -> configManager.getConfigurationsMap()).isInstanceOf(InvalidInputException.class); }
public static Hashtable<String, Object> getConfigurationsMap() { JsonArray propertySourcesArray = new JsonArray(); Hashtable<String, Object> appPropsHashtable = new Hashtable<>(); Hashtable<String, Object> rulePropsHashtable = new Hashtable<>(); Hashtable<String, Object> configHashtable = new Hashtable<>(); String configServerURL = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_SERVICE_URL); String configCredentials = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_CREDENTIALS); if (StringUtils.isNullOrEmpty(configServerURL) || StringUtils.isNullOrEmpty(configCredentials)) { logger.info(PacmanSdkConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_CONFIGURATION); } Map<String, Object> configCreds = CommonHttpUtils.getHeader(configCredentials); JsonObject configurationsFromPacmanTable = CommonHttpUtils.getConfigurationsFromConfigApi(configServerURL, configCreds); logger.info("Configured values {} ",configurationsFromPacmanTable); if (configurationsFromPacmanTable != null) { propertySourcesArray = configurationsFromPacmanTable.get("propertySources").getAsJsonArray(); } if (propertySourcesArray.size() > 0) { for (int i = 0; i < propertySourcesArray.size(); i++) { JsonObject propertySource = (JsonObject) propertySourcesArray.get(i); if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("application")) { JsonObject appProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); appPropsHashtable = new Gson().fromJson(appProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("rule")) { JsonObject ruleProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); rulePropsHashtable = new Gson().fromJson(ruleProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } } } else { logger.info(PacmanSdkConstants.MISSING_DB_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_DB_CONFIGURATION); } configHashtable.putAll(appPropsHashtable); configHashtable.putAll(rulePropsHashtable); return configHashtable; }
ConfigManager { public static Hashtable<String, Object> getConfigurationsMap() { JsonArray propertySourcesArray = new JsonArray(); Hashtable<String, Object> appPropsHashtable = new Hashtable<>(); Hashtable<String, Object> rulePropsHashtable = new Hashtable<>(); Hashtable<String, Object> configHashtable = new Hashtable<>(); String configServerURL = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_SERVICE_URL); String configCredentials = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_CREDENTIALS); if (StringUtils.isNullOrEmpty(configServerURL) || StringUtils.isNullOrEmpty(configCredentials)) { logger.info(PacmanSdkConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_CONFIGURATION); } Map<String, Object> configCreds = CommonHttpUtils.getHeader(configCredentials); JsonObject configurationsFromPacmanTable = CommonHttpUtils.getConfigurationsFromConfigApi(configServerURL, configCreds); logger.info("Configured values {} ",configurationsFromPacmanTable); if (configurationsFromPacmanTable != null) { propertySourcesArray = configurationsFromPacmanTable.get("propertySources").getAsJsonArray(); } if (propertySourcesArray.size() > 0) { for (int i = 0; i < propertySourcesArray.size(); i++) { JsonObject propertySource = (JsonObject) propertySourcesArray.get(i); if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("application")) { JsonObject appProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); appPropsHashtable = new Gson().fromJson(appProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("rule")) { JsonObject ruleProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); rulePropsHashtable = new Gson().fromJson(ruleProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } } } else { logger.info(PacmanSdkConstants.MISSING_DB_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_DB_CONFIGURATION); } configHashtable.putAll(appPropsHashtable); configHashtable.putAll(rulePropsHashtable); return configHashtable; } }
ConfigManager { public static Hashtable<String, Object> getConfigurationsMap() { JsonArray propertySourcesArray = new JsonArray(); Hashtable<String, Object> appPropsHashtable = new Hashtable<>(); Hashtable<String, Object> rulePropsHashtable = new Hashtable<>(); Hashtable<String, Object> configHashtable = new Hashtable<>(); String configServerURL = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_SERVICE_URL); String configCredentials = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_CREDENTIALS); if (StringUtils.isNullOrEmpty(configServerURL) || StringUtils.isNullOrEmpty(configCredentials)) { logger.info(PacmanSdkConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_CONFIGURATION); } Map<String, Object> configCreds = CommonHttpUtils.getHeader(configCredentials); JsonObject configurationsFromPacmanTable = CommonHttpUtils.getConfigurationsFromConfigApi(configServerURL, configCreds); logger.info("Configured values {} ",configurationsFromPacmanTable); if (configurationsFromPacmanTable != null) { propertySourcesArray = configurationsFromPacmanTable.get("propertySources").getAsJsonArray(); } if (propertySourcesArray.size() > 0) { for (int i = 0; i < propertySourcesArray.size(); i++) { JsonObject propertySource = (JsonObject) propertySourcesArray.get(i); if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("application")) { JsonObject appProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); appPropsHashtable = new Gson().fromJson(appProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("rule")) { JsonObject ruleProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); rulePropsHashtable = new Gson().fromJson(ruleProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } } } else { logger.info(PacmanSdkConstants.MISSING_DB_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_DB_CONFIGURATION); } configHashtable.putAll(appPropsHashtable); configHashtable.putAll(rulePropsHashtable); return configHashtable; }  }
ConfigManager { public static Hashtable<String, Object> getConfigurationsMap() { JsonArray propertySourcesArray = new JsonArray(); Hashtable<String, Object> appPropsHashtable = new Hashtable<>(); Hashtable<String, Object> rulePropsHashtable = new Hashtable<>(); Hashtable<String, Object> configHashtable = new Hashtable<>(); String configServerURL = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_SERVICE_URL); String configCredentials = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_CREDENTIALS); if (StringUtils.isNullOrEmpty(configServerURL) || StringUtils.isNullOrEmpty(configCredentials)) { logger.info(PacmanSdkConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_CONFIGURATION); } Map<String, Object> configCreds = CommonHttpUtils.getHeader(configCredentials); JsonObject configurationsFromPacmanTable = CommonHttpUtils.getConfigurationsFromConfigApi(configServerURL, configCreds); logger.info("Configured values {} ",configurationsFromPacmanTable); if (configurationsFromPacmanTable != null) { propertySourcesArray = configurationsFromPacmanTable.get("propertySources").getAsJsonArray(); } if (propertySourcesArray.size() > 0) { for (int i = 0; i < propertySourcesArray.size(); i++) { JsonObject propertySource = (JsonObject) propertySourcesArray.get(i); if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("application")) { JsonObject appProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); appPropsHashtable = new Gson().fromJson(appProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("rule")) { JsonObject ruleProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); rulePropsHashtable = new Gson().fromJson(ruleProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } } } else { logger.info(PacmanSdkConstants.MISSING_DB_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_DB_CONFIGURATION); } configHashtable.putAll(appPropsHashtable); configHashtable.putAll(rulePropsHashtable); return configHashtable; }  static Hashtable<String, Object> getConfigurationsMap(); }
ConfigManager { public static Hashtable<String, Object> getConfigurationsMap() { JsonArray propertySourcesArray = new JsonArray(); Hashtable<String, Object> appPropsHashtable = new Hashtable<>(); Hashtable<String, Object> rulePropsHashtable = new Hashtable<>(); Hashtable<String, Object> configHashtable = new Hashtable<>(); String configServerURL = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_SERVICE_URL); String configCredentials = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_CREDENTIALS); if (StringUtils.isNullOrEmpty(configServerURL) || StringUtils.isNullOrEmpty(configCredentials)) { logger.info(PacmanSdkConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_CONFIGURATION); } Map<String, Object> configCreds = CommonHttpUtils.getHeader(configCredentials); JsonObject configurationsFromPacmanTable = CommonHttpUtils.getConfigurationsFromConfigApi(configServerURL, configCreds); logger.info("Configured values {} ",configurationsFromPacmanTable); if (configurationsFromPacmanTable != null) { propertySourcesArray = configurationsFromPacmanTable.get("propertySources").getAsJsonArray(); } if (propertySourcesArray.size() > 0) { for (int i = 0; i < propertySourcesArray.size(); i++) { JsonObject propertySource = (JsonObject) propertySourcesArray.get(i); if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("application")) { JsonObject appProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); appPropsHashtable = new Gson().fromJson(appProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("rule")) { JsonObject ruleProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject(); rulePropsHashtable = new Gson().fromJson(ruleProps,new TypeToken<Hashtable<String, Object>>() {}.getType()); } } } else { logger.info(PacmanSdkConstants.MISSING_DB_CONFIGURATION); throw new InvalidInputException(PacmanSdkConstants.MISSING_DB_CONFIGURATION); } configHashtable.putAll(appPropsHashtable); configHashtable.putAll(rulePropsHashtable); return configHashtable; }  static Hashtable<String, Object> getConfigurationsMap();  }