/** * Create new Property. * * @param featureID * unique feature identifier. */ public FF4j createProperty(Property<?> prop) { getPropertiesStore().createProperty(prop); return this; }
/** TDD. */ @Test(expected = IllegalArgumentException.class) public void addPropertyKONull() { // Given testedStore.createProperty(null); // Then expect to fail }
/** * Help to import propertiess. * * @param features * set of features. * @return * a reference to this object (builder pattern). * * @since 1.6 */ public FF4j importProperties(Collection < Property<?>> properties) { if (properties != null) { for (Property<?> property : properties) { getPropertiesStore().createProperty(property); } } return this; }
/** {@inheritDoc} */ @Override public void addProperty(String key, Object value) { ff4jStore().createProperty(PropertyFactory.createProperty(key, value)); }
/** {@inheritDoc} */ @Override public Configuration subset(String prefix) { Map < String, Property<?>> myProps = ff4jStore().readAllProperties(); PropertyStore ps = new InMemoryPropertyStore(); for (Map.Entry< String, Property<?>> prop : myProps.entrySet()) { if (prop.getKey().startsWith(prefix)) { ps.createProperty(prop.getValue()); } } return new FF4jConfiguration(ps); }
/** {@inheritDoc} */ @Override protected void addPropertyDirect(String key, Object value) { ff4jStore().createProperty(PropertyFactory.createProperty(key, value)); }
/** TDD. */ @Test(expected = PropertyAlreadyExistException.class) public void addPropertyKOAlreadyExist() { // Given testedStore.createProperty(new PropertyLogLevel("log", LogLevel.DEBUG)); Assert.assertTrue(testedStore.existProperty("log")); // When testedStore.createProperty(new PropertyLogLevel("log", LogLevel.DEBUG)); // Then expect to fail }
/** TDD. */ @Test public void addPropertyOKDate() { // Given //Assert.assertFalse(testedStore.exist("log")); // When testedStore.createProperty(new PropertyDate("ddate", new Date())); // Then Assert.assertTrue(testedStore.existProperty("ddate")); }
/** {@inheritDoc} */ @Override public <T> void createProperty(Property<T> property) { getTargetPropertyStore().createProperty(property); getCacheManager().putProperty(property); }
/** TDD. */ @Test(expected = IllegalArgumentException.class) public void updateKOInvalidValue() { // Given testedStore.createProperty(new PropertyLogLevel("updateKOInvalidValue", LogLevel.ERROR)); // When testedStore.updateProperty("updateKOInvalidValue", "KO"); }
/** TDD. */ @Test public void clear() { // Given Assert.assertNotNull(testedStore); Map <String, Property<?>> before = testedStore.readAllProperties(); Assert.assertFalse(before.isEmpty()); // When testedStore.clear(); // Then Assert.assertTrue(testedStore.readAllProperties().isEmpty()); /// Reinit for (Map.Entry<String,Property<?>> pName : before.entrySet()) { testedStore.createProperty(pName.getValue()); } }
/** TDD. */ @Test public void addPropertyOKLogLevel() { // Given //Assert.assertFalse(testedStore.exist("log")); // When testedStore.createProperty(new PropertyLogLevel("logi", LogLevel.DEBUG)); // Then Assert.assertTrue(testedStore.existProperty("logi")); }
/** {@inheritDoc} */ public < T > void createProperty(Property<T> prop) { long start = System.nanoTime(); target.createProperty(prop); long duration = System.nanoTime() - start; publish(builder(ACTION_CREATE) .property(prop.getName()) .value(prop.asString()) .duration(duration)); }
/** TDD. */ @Test public void updateOK() { // Given testedStore.createProperty(new PropertyLogLevel(UPDATE_OK, LogLevel.ERROR)); // When testedStore.updateProperty(UPDATE_OK, "INFO"); // Then Assert.assertEquals(LogLevel.INFO, testedStore.readProperty(UPDATE_OK).getValue()); }
/** TDD. */ @Test public void addPropertyOKsimple() { // Given Assert.assertFalse(testedStore.existProperty(ADD_PROPERTY_O_KSIMPLE)); // When testedStore.createProperty(new PropertyString(ADD_PROPERTY_O_KSIMPLE, "ff4j")); // Then Assert.assertTrue(testedStore.existProperty(ADD_PROPERTY_O_KSIMPLE)); }
/** TDD. */ @Test public void deleteOK() { // Given testedStore.createProperty(new PropertyString(DELETE_OK, "ff4j")); Assert.assertTrue(testedStore.existProperty(DELETE_OK)); // When testedStore.deleteProperty(DELETE_OK); // Then Assert.assertFalse(testedStore.existProperty(DELETE_OK)); }
/** TDD. */ @Test public void updateOKProperties() { // Given testedStore.createProperty(new PropertyLogLevel("logX", LogLevel.ERROR)); // When PropertyLogLevel pll = new PropertyLogLevel("logX", LogLevel.INFO); testedStore.updateProperty(pll); // Then Assert.assertEquals(LogLevel.INFO, testedStore.readProperty("logX").getValue()); }
public FeatureActions createOrUpdateProperty(String propertyName, PropertyApiBean propertyApiBean) { propertyValidator.assertPropertyNameNotBlank(propertyApiBean.getName()); propertyValidator.assertPropertyNameMatch(propertyName, propertyApiBean.getName()); Property<?> property = propertyApiBean.asProperty(); if (ff4j.getPropertiesStore().existProperty(propertyName)) { ff4j.getPropertiesStore().updateProperty(property); return FeatureActions.UPDATED; } else { ff4j.getPropertiesStore().createProperty(property); return FeatureActions.CREATED; } }
@Test public void readOK() { // Given testedStore.createProperty(new PropertyString("toto", "ff4j")); // When Property<?> ap = testedStore.readProperty("toto"); // Then Assert.assertNotNull(ap); Assert.assertNotNull(ap.getName()); Assert.assertEquals("toto", ap.getName()); Assert.assertEquals("ff4j", ap.getValue()); Assert.assertEquals("ff4j", ap.asString()); Assert.assertNull(ap.getFixedValues()); }
@Test public void readOKFixed() { // Given testedStore.createProperty(new PropertyLogLevel(READ_OK_FIXED, LogLevel.ERROR)); // When Property<?> log = testedStore.readProperty(READ_OK_FIXED); // Then Assert.assertNotNull(log); Assert.assertNotNull(log.getName()); Assert.assertEquals(READ_OK_FIXED, log.getName()); Assert.assertEquals(LogLevel.ERROR, log.getValue()); Assert.assertEquals("ERROR", log.asString()); Assert.assertNotNull(log.getFixedValues()); }