Search in sources :

Example 6 with XmlParser

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

the class FeatureXmlParserTest method importThenExportFeatures2.

@Test
public void importThenExportFeatures2() throws IOException {
    // Given
    XmlParser parser = new XmlParser();
    InputStream in = getClass().getClassLoader().getResourceAsStream("ff4j-parser-all.xml");
    Map<String, Feature> features = parser.parseConfigurationFile(in).getFeatures();
    Assert.assertNotNull(features);
    // When
    InputStream in3 = parser.exportFeatures(features);
    // Then
    // output is OK
    Map<String, Feature> features2 = parser.parseConfigurationFile(in3).getFeatures();
    Assert.assertNotNull(features2);
    Assert.assertEquals(features.size(), features2.size());
}
Also used : XmlParser(org.ff4j.conf.XmlParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 7 with XmlParser

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

the class FeatureXmlParserTest method testLoaderRequiredEnable.

@Test(expected = IllegalArgumentException.class)
public void testLoaderRequiredEnable() {
    InputStream in = getClass().getClassLoader().getResourceAsStream("test-featureXmlParserTest-ko-enablerequired.xml");
    new XmlParser().parseConfigurationFile(in);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 8 with XmlParser

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

the class FeatureXmlParserTest method testLoaderXMLFile.

@Test
public void testLoaderXMLFile() {
    InputStream in = getClass().getClassLoader().getResourceAsStream("test-featureXmlParserTest-ok.xml");
    Map<String, Feature> features = new XmlParser().parseConfigurationFile(in).getFeatures();
    Assert.assertEquals(7, features.size());
    Assert.assertTrue(features.containsKey("f0"));
    Assert.assertNotNull(features.get("f0").getDescription());
    Assert.assertNotNull(features.get("f0").getPermissions());
    Assert.assertEquals(2, features.get("f0").getPermissions().size());
    Assert.assertNotNull(features.get("f0").getFlippingStrategy());
    Assert.assertEquals(1, features.get("f0").getFlippingStrategy().getInitParams().size());
    Assert.assertNotNull(features.get("f0").getGroup());
    Assert.assertEquals("group3", features.get("f0").getGroup());
    Assert.assertTrue(features.containsKey("f1"));
    Assert.assertTrue(features.containsKey("f2"));
    Assert.assertTrue(features.containsKey("f3"));
    Assert.assertTrue(features.containsKey("f4"));
    Assert.assertTrue(features.containsKey("f5"));
}
Also used : XmlParser(org.ff4j.conf.XmlParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 9 with XmlParser

use of org.ff4j.conf.XmlParser 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);
}
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 10 with XmlParser

use of org.ff4j.conf.XmlParser 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);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) PropertyLogLevel(org.ff4j.property.PropertyLogLevel) 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)

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