@Test public void testDynamicProperty() { config.stopLoading(); DynamicProperty fastProp = DynamicProperty.getInstance(PROP_NAME); assertEquals("FastProperty does not have correct name", PROP_NAME, fastProp.getName()); assertSame("DynamicProperty.getInstance did not find the object", fastProp, DynamicProperty.getInstance(PROP_NAME)); String hello = "Hello"; assertNull("Unset DynamicProperty is not null", fastProp.getString()); assertEquals("Unset DynamicProperty does not default correctly", hello, fastProp.getString(hello)); config.setProperty(PROP_NAME, hello); assertEquals("Set DynamicProperty does not have correct value", hello, fastProp.getString()); assertEquals("Set DynamicProperty uses supplied default", hello, fastProp.getString("not " + hello)); assertEquals("Non-integer DynamicProperty doesn't default on integer fetch", 123, fastProp.getInteger(Integer.valueOf(123)).intValue()); assertEquals("Non-float DynamicProperty doesn't default on float fetch", 2.71838f, fastProp.getFloat(Float.valueOf(2.71838f)).floatValue(), 0.001f); try { fastProp.getFloat(); fail("Parse should have failed: " + fastProp); } catch (IllegalArgumentException e) { assertNotNull(e); } String pi = "3.14159"; String ee = "2.71838"; config.setProperty(PROP_NAME, pi); assertEquals("Set DynamicProperty does not have correct value", pi, fastProp.getString()); assertEquals("DynamicProperty did not property parse float string", 3.14159f, fastProp.getFloat(Float.valueOf(0.0f)).floatValue(), 0.001f); config.setProperty(PROP_NAME, ee); assertEquals("Set DynamicProperty does not have correct value", ee, fastProp.getString()); assertEquals("DynamicProperty did not property parse float string", 2.71838f, fastProp.getFloat(Float.valueOf(0.0f)).floatValue(), 0.001f); try { fastProp.getInteger(); fail("Integer fetch of non-integer DynamicProperty should have failed: " + fastProp); } catch (IllegalArgumentException e) { assertNotNull(e); } assertEquals("Integer fetch of non-integer DynamicProperty did not use default value", -123, fastProp.getInteger(Integer.valueOf(-123)).intValue()); String devil = "666"; config.setProperty(PROP_NAME, devil); assertEquals("Changing DynamicProperty does not result in correct value", devil, fastProp.getString()); assertEquals("Integer fetch of changed DynamicProperty did not return correct value", 666, fastProp.getInteger().intValue()); String self = "com.netflix.config.DynamicProperty"; assertEquals("Fetch of named class from integer valued DynamicProperty did not use default", DynamicPropertyTest.class, fastProp.getNamedClass(DynamicPropertyTest.class)); config.setProperty(PROP_NAME, self); assertEquals("Fetch of named class from DynamicProperty did not find the class", DynamicProperty.class, fastProp.getNamedClass()); config.clearProperty(PROP_NAME); assertNull("Fetch of cleard property did not return null", fastProp.getString()); assertEquals("Fetch of cleard property did not use default value", devil, fastProp.getString(devil)); assertNull("Fetch of cleard property did not return null", fastProp.getInteger()); assertEquals("Fetch of cleard property did not use default value", -123, fastProp.getInteger(Integer.valueOf(-123)).intValue()); assertNull("Fetch of cleard property did not return null", fastProp.getFloat()); assertEquals("Fetch of cleard property did not use default value", 2.71838f, fastProp.getFloat(Float.valueOf(2.71838f)).floatValue(), 0.001f); assertNull("Fetch of cleard property did not return null", fastProp.getNamedClass()); assertEquals("Fetch of cleard property did not use default value", DynamicProperty.class, fastProp.getNamedClass(DynamicProperty.class)); String yes = "yes"; String maybe = "maybe"; String no = "Off"; config.setProperty(PROP_NAME, yes); assertTrue("boolean property set to 'yes' is not true", fastProp.getBoolean().booleanValue()); config.setProperty(PROP_NAME, no); assertTrue("boolean property set to 'no' is not false", !fastProp.getBoolean().booleanValue()); config.setProperty(PROP_NAME, maybe); try { fastProp.getBoolean(); fail("Parse should have failed: " + fastProp); } catch (IllegalArgumentException e) { assertNotNull(e); } assertTrue(fastProp.getBoolean(Boolean.TRUE).booleanValue()); assertTrue(!fastProp.getBoolean(Boolean.FALSE).booleanValue()); }
protected DynamicProperty() { }
DynamicProperty { protected DynamicProperty() { } }
DynamicProperty { protected DynamicProperty() { } protected  DynamicProperty(); private  DynamicProperty(String propName); }
DynamicProperty { protected DynamicProperty() { } protected  DynamicProperty(); private  DynamicProperty(String propName); static DynamicProperty getInstance(String propName); String getName(); long getChangedTimestamp(); String getString(); String getString(String defaultValue); Boolean getBoolean(); Boolean getBoolean(Boolean defaultValue); Integer getInteger(); Integer getInteger(Integer defaultValue); Float getFloat(); Float getFloat(Float defaultValue); Long getLong(); Long getLong(Long defaultValue); Double getDouble(); Double getDouble(Double defaultValue); Class getNamedClass(); Class<?> getNamedClass(Class<?> defaultValue); @SuppressWarnings("unchecked") Optional<T> getCachedValue(Class<T> objectType); void addCallback(Runnable r); void addValidator(PropertyChangeValidator validator); boolean removeCallback(Runnable r); @Override String toString(); }
DynamicProperty { protected DynamicProperty() { } protected  DynamicProperty(); private  DynamicProperty(String propName); static DynamicProperty getInstance(String propName); String getName(); long getChangedTimestamp(); String getString(); String getString(String defaultValue); Boolean getBoolean(); Boolean getBoolean(Boolean defaultValue); Integer getInteger(); Integer getInteger(Integer defaultValue); Float getFloat(); Float getFloat(Float defaultValue); Long getLong(); Long getLong(Long defaultValue); Double getDouble(); Double getDouble(Double defaultValue); Class getNamedClass(); Class<?> getNamedClass(Class<?> defaultValue); @SuppressWarnings("unchecked") Optional<T> getCachedValue(Class<T> objectType); void addCallback(Runnable r); void addValidator(PropertyChangeValidator validator); boolean removeCallback(Runnable r); @Override String toString();  }