Search in sources :

Example 16 with XmlParser

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

the class FlipSecurityTests2 method setUp.

@Before
public void setUp() throws Exception {
    securityCtx = SecurityContextHolder.getContext();
    // Init SpringSecurity Context
    SecurityContext context = new SecurityContextImpl();
    List<GrantedAuthority> listOfRoles = new ArrayList<GrantedAuthority>();
    listOfRoles.add(new SimpleGrantedAuthority("ROLE_USER"));
    User u1 = new User("user1", "user1", true, true, true, true, listOfRoles);
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(u1.getUsername(), u1.getPassword(), u1.getAuthorities());
    token.setDetails(u1);
    context.setAuthentication(token);
    SecurityContextHolder.setContext(context);
    // <--
    ff4j = new FF4j(new XmlParser(), "test-ff4j-security-spring.xml");
    ff4j.setAuthorizationsManager(new SpringSecurityAuthorisationManager());
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) XmlParser(org.ff4j.conf.XmlParser) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) User(org.springframework.security.core.userdetails.User) FF4j(org.ff4j.FF4j) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SecurityContext(org.springframework.security.core.context.SecurityContext) ArrayList(java.util.ArrayList) SpringSecurityAuthorisationManager(org.ff4j.security.SpringSecurityAuthorisationManager) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Before(org.junit.Before)

Example 17 with XmlParser

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

the class PropertiesParserTest method importProperties_should_be_same_asXMLImport.

@Test
public void importProperties_should_be_same_asXMLImport() {
    // Give XML an YAML files
    InputStream xmlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.xml");
    InputStream ymlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.properties");
    // When parsing those files
    XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(xmlFile);
    FF4jConfiguration propsConfig = new PropertiesParser().parseConfigurationFile(ymlFile);
    // Than both config are even
    assertEquals(xmlConfig.getFeatures().size(), propsConfig.getFeatures().size());
    assertEquals(xmlConfig.getProperties().size(), propsConfig.getProperties().size());
    // Custom-properties
    Feature f1Xml = xmlConfig.getFeatures().get("first");
    Feature f1props = propsConfig.getFeatures().get("first");
    assertEquals(f1Xml.getDescription(), f1props.getDescription());
    assertEquals(f1Xml.getCustomProperties().size(), f1props.getCustomProperties().size());
    // FlipStrategy & Permission
    Feature f3Xml = xmlConfig.getFeatures().get("third");
    Feature f3Props = propsConfig.getFeatures().get("third");
    assertEquals(f3Xml.getFlippingStrategy().getClass(), f3Props.getFlippingStrategy().getClass());
    assertEquals(f3Xml.getFlippingStrategy().getInitParams().get("expression"), f3Props.getFlippingStrategy().getInitParams().get("expression"));
    assertEquals(f3Xml.getPermissions(), f3Props.getPermissions());
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature) FF4jConfiguration(org.ff4j.conf.FF4jConfiguration) Test(org.junit.Test)

Example 18 with XmlParser

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

the class PropertiesParserTest method should_export_anyConfig_asProperties.

@Test
public void should_export_anyConfig_asProperties() {
    // Given an XML file
    InputStream xmlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.xml");
    // When loading config
    XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(xmlFile);
    // Then it possible to export as YAML
    new PropertiesParser().export(xmlConfig);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 19 with XmlParser

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

the class YamlParserTest method importYaml_should_be_same_asXMLImport.

@Test
public void importYaml_should_be_same_asXMLImport() {
    // Give XML an YAML files
    InputStream xmlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.xml");
    InputStream ymlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.yml");
    // When parsing those files
    XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(xmlFile);
    FF4jConfiguration ymlConfig = new YamlParser().parseConfigurationFile(ymlFile);
    // Than both config are even
    assertEquals(xmlConfig.getFeatures().size(), ymlConfig.getFeatures().size());
    assertEquals(xmlConfig.getProperties().size(), ymlConfig.getProperties().size());
    // Custom-properties
    Feature f1Xml = xmlConfig.getFeatures().get("first");
    Feature f1Yml = ymlConfig.getFeatures().get("first");
    assertEquals(f1Xml.getDescription(), f1Yml.getDescription());
    assertEquals(f1Xml.getCustomProperties().size(), f1Yml.getCustomProperties().size());
    // FlipStrategy & Permission
    Feature f3Xml = xmlConfig.getFeatures().get("third");
    Feature f3Yml = ymlConfig.getFeatures().get("third");
    assertEquals(f3Xml.getFlippingStrategy().getClass(), f3Yml.getFlippingStrategy().getClass());
    assertEquals(f3Xml.getFlippingStrategy().getInitParams().get("expression"), f3Yml.getFlippingStrategy().getInitParams().get("expression"));
    assertEquals(f3Xml.getPermissions(), f3Yml.getPermissions());
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature) FF4jConfiguration(org.ff4j.conf.FF4jConfiguration) Test(org.junit.Test)

Example 20 with XmlParser

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

the class YamlParserTest method should_export_anyConfig_asYaml.

@Test
public void should_export_anyConfig_asYaml() {
    // Given an XML file
    InputStream xmlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.xml");
    // When loading config
    XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(xmlFile);
    // Then it possible to export as YAML
    new YamlParser().export(xmlConfig);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) InputStream(java.io.InputStream) 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