Search in sources :

Example 11 with XmlParser

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

the class FeatureJsonMarshallTest method testEmbeddedQuoteJson.

@Test
public void testEmbeddedQuoteJson() throws Exception {
    Feature f = new FF4j(new XmlParser(), "test-feature-json1.xml").getFeature("embedded\"quote");
    assertMarshalling(f);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) FF4j(org.ff4j.FF4j) TestConstantsFF4j(org.ff4j.test.TestConstantsFF4j) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 12 with XmlParser

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

the class FeatureJsonMarshallTest method marshallOfficeHourFlippingStrategy.

/**
 * TDD.
 */
@Test
@Ignore
public void marshallOfficeHourFlippingStrategy() throws Exception {
    // When-Then
    Feature f = new FF4j(new XmlParser(), "test-strategy-officehour.xml").getFeature("first");
    assertMarshalling(f);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) FF4j(org.ff4j.FF4j) TestConstantsFF4j(org.ff4j.test.TestConstantsFF4j) Feature(org.ff4j.core.Feature) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with XmlParser

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

the class InMemoryFeatureStore method loadConf.

/**
 * Load configuration through FF4J.vml file.
 *
 * @param conf
 *            xml filename
 */
private void loadConf(InputStream xmlIN) {
    if (xmlIN == null) {
        throw new IllegalArgumentException("Cannot parse feature stream");
    }
    this.featuresMap = new XmlParser().parseConfigurationFile(xmlIN).getFeatures();
    buildGroupsFromFeatures();
}
Also used : XmlParser(org.ff4j.conf.XmlParser)

Example 14 with XmlParser

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

the class XmlParserTest method testParseXMLWithSpecialCharacters.

@Test
public void testParseXMLWithSpecialCharacters() throws IOException {
    // Given a config file with Special Characters in XML
    XmlConfig xmlConfig1 = parseFile("test-parser-specialchars.xml");
    // When parsed the special characters are replaced by expected values
    Assert.assertEquals("description \"&>OK<'", xmlConfig1.getFeatures().get("first").getDescription());
    // When parsed values protected by CDATA to interpret special chars
    Assert.assertTrue(xmlConfig1.getFeatures().get("first").getCustomProperties().get("prop2").getFixedValues().contains("https://en.wikipedia.org/w/index.php?title=XML&action=edit&section=4"));
    // Given XmlConfig with special char
    ByteArrayInputStream bais = (ByteArrayInputStream) new XmlParser().exportAll(xmlConfig1);
    // When converting back to XML data
    int n = bais.available();
    byte[] bytes = new byte[n];
    bais.read(bytes, 0, n);
    String s = new String(bytes, StandardCharsets.UTF_8);
    // Then special characters are escaped and values without quotes are protected with CDATA.
    Assert.assertTrue(s.contains("description &quot;&amp;&gt;OK&lt;&apos;"));
    Assert.assertTrue(s.contains("<![CDATA[https://en.wikipedia.org/w/index.php?title=XML&action=edit&section=4]]>"));
    // When parsing back to XML
    InputStream is = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
    XmlConfig xmlConfig2 = new XmlParser().parseConfigurationFile(is);
    // Then I get back the same values
    Assert.assertEquals(xmlConfig2.getFeatures().get("first").getDescription(), xmlConfig1.getFeatures().get("first").getDescription());
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 15 with XmlParser

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

the class FlipSecurityTests 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)

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