use of org.ff4j.conf.XmlConfig in project ff4j by ff4j.
the class AbstractPropertyStore method importPropertiesFromXmlFile.
/**
* Initialize store from XML Configuration File.
*
* @param xmlConfFile
* xml configuration file
*/
public Map<String, Property<?>> importPropertiesFromXmlFile(String xmlConfFile) {
// Argument validation
if (xmlConfFile == null || xmlConfFile.isEmpty()) {
throw new IllegalArgumentException("Configuration filename cannot be null nor empty");
}
// Load as Inputstream
InputStream xmlIS = getClass().getClassLoader().getResourceAsStream(xmlConfFile);
if (xmlIS == null) {
throw new IllegalArgumentException("File " + xmlConfFile + " could not be read, please check path and rights");
}
// Use the Feature Parser
XmlConfig conf = new XmlParser().parseConfigurationFile(xmlIS);
Map<String, Property<?>> properties = conf.getProperties();
// Override existing configuration within database
for (Map.Entry<String, Property<?>> featureName : properties.entrySet()) {
if (existProperty(featureName.getKey())) {
deleteProperty(featureName.getKey());
}
createProperty(featureName.getValue());
}
return properties;
}
use of org.ff4j.conf.XmlConfig 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);
}
use of org.ff4j.conf.XmlConfig 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.conf.XmlConfig 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.conf.XmlConfig in project ff4j by ff4j.
the class AbstractFeatureStore method importFeaturesFromXmlFile.
/**
* Initialize store from XML Configuration File.
*
* @param xmlConfFile
* xml configuration file
*/
public Map<String, Feature> importFeaturesFromXmlFile(String xmlConfFile) {
// Argument validation
if (xmlConfFile == null || xmlConfFile.isEmpty()) {
throw new IllegalArgumentException("Configuration filename cannot be null nor empty");
}
// Load as Inputstream
InputStream xmlIS = getClass().getClassLoader().getResourceAsStream(xmlConfFile);
if (xmlIS == null) {
throw new IllegalArgumentException("File " + xmlConfFile + " could not be read, please check path and rights");
}
// Use the Feature Parser
XmlConfig conf = new XmlParser().parseConfigurationFile(xmlIS);
Map<String, Feature> features = conf.getFeatures();
importFeatures(features.values());
return features;
}
Aggregations