Search in sources :

Example 31 with XmlParser

use of org.ff4j.conf.XmlParser 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;
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature)

Example 32 with XmlParser

use of org.ff4j.conf.XmlParser in project ff4j by ff4j.

the class FF4jTest method autoCreateFeatureEnableTest.

@Test
public void autoCreateFeatureEnableTest() {
    // Default : store = inMemory, load features from ff4j.xml file
    FF4j ff4j = new FF4j(new XmlParser(), "ff4j.xml");
    ff4j.autoCreate();
    assertFalse(ff4j.exist("autoCreatedFeature"));
    // Auto creation by testing its value
    assertFalse(ff4j.check("autoCreatedFeature"));
    // Assertion
    assertTrue(ff4j.exist("autoCreatedFeature"));
}
Also used : XmlParser(org.ff4j.conf.XmlParser) FF4j(org.ff4j.FF4j) Test(org.junit.Test)

Example 33 with XmlParser

use of org.ff4j.conf.XmlParser in project ff4j by ff4j.

the class FF4jTest method testToString.

@Test
public void testToString() {
    FF4j ff4j = new FF4j(new XmlParser(), "ff4j.xml");
    ff4j.toString();
    Assert.assertNotNull(ff4j.getFeatureStore());
    ff4j.setFeatureStore(null);
    ff4j.setPropertiesStore(null);
    ff4j.setEventRepository(null);
    ff4j.setEventPublisher(null);
    ff4j.setAuthorizationsManager(new DefinedPermissionSecurityManager(Util.set("val1")));
    ff4j.toString();
    ff4j.removeCurrentContext();
    ff4j.getCurrentContext();
}
Also used : XmlParser(org.ff4j.conf.XmlParser) FF4j(org.ff4j.FF4j) Test(org.junit.Test)

Example 34 with XmlParser

use of org.ff4j.conf.XmlParser in project ff4j by ff4j.

the class FF4jTest method testGetFeatures.

@Test
public void testGetFeatures() {
    FF4j ff4j = new FF4j(new XmlParser(), "ff4j.xml");
    Assert.assertEquals(5, ff4j.getFeatures().size());
}
Also used : XmlParser(org.ff4j.conf.XmlParser) FF4j(org.ff4j.FF4j) Test(org.junit.Test)

Example 35 with XmlParser

use of org.ff4j.conf.XmlParser in project ff4j by ff4j.

the class FF4jTest method testDeleteFeature.

@Test
public void testDeleteFeature() {
    FF4j ff4j = new FF4j(new XmlParser(), "ff4j.xml");
    ff4j.audit();
    Assert.assertTrue(ff4j.exist(F1));
    ff4j.delete(F1);
    Assert.assertFalse(ff4j.exist(F1));
}
Also used : XmlParser(org.ff4j.conf.XmlParser) FF4j(org.ff4j.FF4j) Test(org.junit.Test)

Aggregations

XmlParser (org.ff4j.conf.XmlParser)44 Test (org.junit.Test)29 InputStream (java.io.InputStream)22 FF4j (org.ff4j.FF4j)17 XmlConfig (org.ff4j.conf.XmlConfig)14 Feature (org.ff4j.core.Feature)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Property (org.ff4j.property.Property)7 FF4jConfiguration (org.ff4j.conf.FF4jConfiguration)4 Date (java.util.Date)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 FileItem (org.apache.commons.fileupload.FileItem)2 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)2 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)2 YamlParser (org.ff4j.parser.yaml.YamlParser)2 PropertyDate (org.ff4j.property.PropertyDate)2 SpringSecurityAuthorisationManager (org.ff4j.security.SpringSecurityAuthorisationManager)2 TestConstantsFF4j (org.ff4j.test.TestConstantsFF4j)2