VulasConfiguration { public void checkSettings() throws ConfigurationException { final String[] optional_settings = this.getStringArray(OPTI_SETTINGS, null); if (optional_settings != null && optional_settings.length > 0) { for (String s : optional_settings) { if (this.isEmpty(s)) { log.warn("Optional setting [" + s + "] not specified"); } } } final String[] mandatory_settings = this.getStringArray(MAND_SETTINGS, null); final Set<String> not_specified = new HashSet<String>(); if (mandatory_settings != null && mandatory_settings.length > 0) { for (String s : mandatory_settings) { if (this.isEmpty(s)) { log.error("Mandatory setting [" + s + "] not specified"); not_specified.add(s); } } } final Iterator<String> iter = this.cfg.getKeys(); final Set<String> wrong_format = new HashSet<String>(); while (iter.hasNext()) { final String key = iter.next(); if (key.startsWith("vulas.") && key.endsWith(".format") && !this.isEmpty(key)) { final String key_to_check = key.substring(0, key.indexOf(".format")); if (!this.isEmpty(key_to_check)) { final String[] values_to_check = this.getStringArray(key_to_check, new String[] {}); for (String value_to_check : values_to_check) { if (!value_to_check.matches(this.cfg.getString(key))) { log.error( "Setting [" + key_to_check + "], value [" + value_to_check + "] does not comply with the required format [" + this.cfg.getString(key) + "]"); wrong_format.add(key_to_check); } } } } } if (!not_specified.isEmpty() || !wrong_format.isEmpty()) throw new ConfigurationException( "The following mandatory settings are not specified: [" + StringUtil.join(not_specified, ", ") + "], the following settings do not comply with the required format: [" + StringUtil.join(wrong_format, ", ") + "]"); } VulasConfiguration(); static final synchronized VulasConfiguration getGlobal(); org.apache.commons.configuration.Configuration getConfiguration(); void addLayerAfterSysProps(
      @NotNull String _layer_name,
      @NotNull Map<?, ?> _map,
      String _ignore_value,
      boolean _ignore_null); Configuration getConfigurationLayer(String _layer_name); void checkSettings(); boolean clearTransientProperties(); boolean isEmpty(String _key); Object getProperty(@NotNull String _key, Object _default); void setPropertyIfEmpty(@NotNull String _key, Object _value); void setProperty(@NotNull String _key, Object _value); void setProperty(
      @NotNull String _key, Object _value, String _ignore_value, boolean _ignore_null); String[] getStringArray(@NotNull String _key, String[] _default); Path getDir(String _key); Path getTmpDir(); String getServiceUrl(Service _service); String getServiceUrl(Service _service, boolean _throw_exception); Map<String, String> getServiceHeaders(Service _service); boolean hasServiceUrl(Service _service); void setServiceUrl(Service _service, String _value); static String getServiceUrlKey(Service _service); Path getLocalM2Repository(); void log(String[] _prefix, String _indent); final StringList getStringList(String... _config_names); static final String SYS_PROP_CFG_LAYER; static final String TRANSIENT_CFG_LAYER; static final String ENV_CFG_LAYER; static final String MAND_SETTINGS; static final String OPTI_SETTINGS; static final String VERSION; static final String BUILD_TIMESTAMP; static final String BUILD_NUMBER; static final String BUILD_BRANCH; static final String HOMEPAGE; static final String CHARSET; static final String TMP_DIR; static final String VULAS_JIRA_USER; static final String VULAS_JIRA_PWD; static final String M2_DIR; static final String SYS_PROPS; static final String SYS_PROPS_CUSTOM; static final String ENV_VARS; static final String ENV_VARS_CUSTOM; }
@Test public void testCheckSettings() { final VulasConfiguration c1 = new VulasConfiguration(); c1.setProperty(VulasConfiguration.MAND_SETTINGS, "bar"); Exception ce = null; try { c1.checkSettings(); } catch (ConfigurationException e) { ce = e; } assertFalse(ce == null); assertEquals( "The following mandatory settings are not specified: [bar], the following settings do not" + " comply with the required format: []", ce.getMessage()); }