private String[] getRegistryKeys() { String registryNamesConcatenated = super.getProperty(REGISTRY_LIST); if (registryNamesConcatenated == null) { return (String[])getDefaultPropertyMap().keySet().toArray(new String[]{}); } else { return registryNamesConcatenated.split(","); } }
@Test public void testListNotThere() throws Exception { AbstractConfigurable c = DummyConfigurable.getInstance(); c.getInternalPropertyMap().clear(); assertNull("the property should be null",c.getProperty("sdflhsdfhsdfjkhsdfkhsdfkhsdfjkh")); assertNull("the list should be null if the property doesn't exist",c.getPropertyStringList("sdflhsdfhsdfjkhsdfkhsdfkhsdfjkh")); }
/** * Returns an unmodifiable List<String> for the given key. Internally the value is stored as a single String, but converted to a list when calling this method. * <br> * The list is unmodifiable to prevent the mistake of trying <pre>getPropertyStringList(..).add("new element");</pre> which will not affect the stored * list. For the property to be updated this{@link #setPropertyStringList(String, List)} must be used. */ public List<String> getPropertyStringList(String key) { String value = getProperty(key); if (value!=null) { return Collections.unmodifiableList(fromListText(value)); } else { return null; } }
@Test public void testListNotThere() throws Exception { AbstractConfigurable c = DummyConfigurable.getInstance(); c.getInternalPropertyMap().clear(); assertNull("the property should be null",c.getProperty("sdflhsdfhsdfjkhsdfkhsdfkhsdfjkh")); assertNull("the list should be null if the property doesn't exist",c.getPropertyStringList("sdflhsdfhsdfjkhsdfkhsdfkhsdfjkh")); }
private void updateRegistryMap() { registryMap.clear(); for (String key : getRegistryKeys()) { String value = super.getProperty(key); try { registryMap.put(key, calculateRegistry(new URL( value))); } catch (MalformedURLException e) { logger.error("bogus url (" + value + ") in configuration file", e); } catch (RegistryException e) { logger.error("failed to construct registry handle for " + value, e); } } }
@Test public void testDeleteDefaultProperty() throws Exception { AbstractConfigurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); conf.deleteProperty("name"); manager.store(conf); manager.populate(conf); assertNull("value for name should be null",conf.getProperty("name")); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertTrue("Key name should be in stored props because its a deleted default value",props.containsKey("name")); assertEquals("name should have the special value to indicate its been deleted",ConfigurationManager.DELETED_VALUE_CODE,props.getProperty("name")); }
@Test public void testDeleteDefaultProperty() throws Exception { AbstractConfigurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); conf.deleteProperty("name"); manager.store(conf); manager.populate(conf); assertNull("value for name should be null",conf.getProperty("name")); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertTrue("Key name should be in stored props because its a deleted default value",props.containsKey("name")); assertEquals("name should have the special value to indicate its been deleted",ConfigurationManager.DELETED_VALUE_CODE,props.getProperty("name")); }