use of org.ff4j.property.Property in project ff4j by ff4j.
the class FeatureXmlParserTest method testParsingFeatures.
@Test
public void testParsingFeatures() throws IOException {
// Given
XmlParser parser = new XmlParser();
InputStream in = getClass().getClassLoader().getResourceAsStream("ff4j-parser-features.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);
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class FeatureXmlParserTest method testPropertiesParsing.
@Test
public void testPropertiesParsing() throws IOException {
// Given
XmlParser parser = new XmlParser();
InputStream in = getClass().getClassLoader().getResourceAsStream("ff4j.xml");
// When
XmlConfig conf = parser.parseConfigurationFile(in);
// Then
Map<String, Feature> features = conf.getFeatures();
Assert.assertNotNull(features);
Feature f = features.get("first");
Assert.assertNotNull(f);
Assert.assertNotNull(f.getUid());
Assert.assertNotNull(f.getCustomProperties());
Assert.assertNotNull(f.getCustomProperties().get("ppint"));
Assert.assertEquals(f.getCustomProperties().get("ppint").asInt(), 12);
Assert.assertEquals(f.getCustomProperties().get("ppdouble").asDouble(), 12.5, 0);
Assert.assertEquals(f.getCustomProperties().get("ppboolean").asBoolean(), true);
Assert.assertEquals(f.getCustomProperties().get("ppstring").asString(), "hello");
Assert.assertEquals(f.getCustomProperties().get("regionIdentifier").asString(), "AMER");
Assert.assertNotNull(f.getCustomProperties().get("regionIdentifier").getFixedValues());
Assert.assertFalse(f.getCustomProperties().get("regionIdentifier").getFixedValues().isEmpty());
PropertyLogLevel pll = (PropertyLogLevel) f.getCustomProperties().get("myLogLevel");
Assert.assertEquals(pll.getValue(), LogLevel.DEBUG);
// Then
Map<String, Property<?>> properties = conf.getProperties();
Assert.assertNotNull(properties);
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class ConsoleOperations method importFile.
/**
* User action to import Features from a properties files.
*
* @param in
* inpustream from configuration file
* @throws IOException
* Error raised if the configuration cannot be read
*/
public static void importFile(FF4j ff4j, FF4jConfiguration config) throws IOException {
if (config.isAutoCreate()) {
ff4j.setAutocreate(true);
LOGGER.info("Autocreate is now enabled.");
}
if (config.isAudit()) {
ff4j.setEnableAudit(true);
LOGGER.info("Audit is now enabled.");
}
FeatureStore store = ff4j.getFeatureStore();
Map<String, Feature> mapsOfFeat = config.getFeatures();
for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) {
if (store.exist(feature.getKey())) {
store.update(feature.getValue());
} else {
store.create(feature.getValue());
}
}
LOGGER.info(mapsOfFeat.size() + " features have been imported.");
PropertyStore pstore = ff4j.getPropertiesStore();
Map<String, Property<?>> mapsOfProperties = config.getProperties();
for (Entry<String, Property<?>> p : mapsOfProperties.entrySet()) {
if (pstore.existProperty(p.getKey())) {
pstore.updateProperty(p.getValue());
} else {
pstore.createProperty(p.getValue());
}
}
LOGGER.info(mapsOfProperties.size() + " features have been imported.");
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class PropertyStoreElastic method readProperty.
/**
* {@inheritDoc}
*/
@Override
public Property<?> readProperty(String name) {
assertPropertyExist(name);
SearchResult result = getConnection().search(getBuilder().queryPropertyByName(name), true);
return result.getFirstHit(Property.class).source;
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class ConsoleOperations method importFile.
/**
* User action to import Features from a properties files.
*
* @param in
* inpustream from configuration file
* @throws IOException
* Error raised if the configuration cannot be read
*/
public static void importFile(FF4j ff4j, InputStream in) throws IOException {
FeatureStore store = ff4j.getFeatureStore();
XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(in);
Map<String, Feature> mapsOfFeat = xmlConfig.getFeatures();
for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) {
if (store.exist(feature.getKey())) {
store.update(feature.getValue());
} else {
store.create(feature.getValue());
}
}
LOGGER.info(mapsOfFeat.size() + " features have been imported.");
PropertyStore pstore = ff4j.getPropertiesStore();
Map<String, Property<?>> mapsOfProperties = xmlConfig.getProperties();
for (Entry<String, Property<?>> p : mapsOfProperties.entrySet()) {
if (pstore.existProperty(p.getKey())) {
pstore.updateProperty(p.getValue());
} else {
pstore.createProperty(p.getValue());
}
}
LOGGER.info(mapsOfProperties.size() + " features have been imported.");
}
Aggregations