Search in sources :

Example 21 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class FF4jConfiguration method getProperties.

/**
 * {@inheritDoc}
 */
@Override
public Properties getProperties(String key) {
    Properties props = new Properties();
    if (key == null)
        return props;
    Map<String, Property<?>> myProps = ff4jStore().readAllProperties();
    for (Map.Entry<String, Property<?>> prop : myProps.entrySet()) {
        if (prop.getKey().startsWith(key)) {
            props.put(prop.getKey(), prop.getValue().getValue());
        }
    }
    return props;
}
Also used : Properties(java.util.Properties) Property(org.ff4j.property.Property) Map(java.util.Map)

Example 22 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class FF4jConfiguration method subset.

/**
 * {@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);
}
Also used : InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) Property(org.ff4j.property.Property) Map(java.util.Map) InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) PropertyStore(org.ff4j.property.store.PropertyStore)

Example 23 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class FeatureXmlParserTest method testParsingALL.

@Test
public void testParsingALL() throws IOException {
    // Given
    XmlParser parser = new XmlParser();
    InputStream in = getClass().getClassLoader().getResourceAsStream("ff4j-parser-all.xml");
    // When
    XmlConfig conf = parser.parseConfigurationFile(in);
    // Then
    Map<String, Feature> features = conf.getFeatures();
    Assert.assertNotNull(features);
    // Then
    Map<String, Property<?>> properties = conf.getProperties();
    Assert.assertNotNull(properties);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) Test(org.junit.Test)

Example 24 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class FF4jTest method testImportProperties.

@Test
public void testImportProperties() {
    FF4j ff4j = new FF4j();
    List<Property<?>> listOfProperties = new ArrayList<Property<?>>();
    listOfProperties.add(new PropertyString("p1", "v1"));
    ff4j.importProperties(listOfProperties);
    Assert.assertTrue(ff4j.getPropertiesStore().existProperty("p1"));
    // no Error
    ff4j.importProperties(null);
}
Also used : PropertyString(org.ff4j.property.PropertyString) FF4j(org.ff4j.FF4j) ArrayList(java.util.ArrayList) Property(org.ff4j.property.Property) Test(org.junit.Test)

Example 25 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class AbstractPropertyStoreJunitTest method clear.

/**
 * 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 (String pName : before.keySet()) {
        testedStore.createProperty(before.get(pName));
    }
}
Also used : PropertyString(org.ff4j.property.PropertyString) Property(org.ff4j.property.Property) Test(org.junit.Test)

Aggregations

Property (org.ff4j.property.Property)56 HashMap (java.util.HashMap)20 PropertyString (org.ff4j.property.PropertyString)20 Test (org.junit.Test)20 Feature (org.ff4j.core.Feature)16 Map (java.util.Map)11 InputStream (java.io.InputStream)9 XmlParser (org.ff4j.conf.XmlParser)7 InMemoryPropertyStore (org.ff4j.property.store.InMemoryPropertyStore)7 LinkedHashMap (java.util.LinkedHashMap)6 XmlConfig (org.ff4j.conf.XmlConfig)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 FeatureStore (org.ff4j.core.FeatureStore)4 PropertyAccessException (org.ff4j.exception.PropertyAccessException)4 PropertyStore (org.ff4j.property.store.PropertyStore)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 FF4jCacheProxy (org.ff4j.cache.FF4jCacheProxy)3