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);
}
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);
}
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();
}
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§ion=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 "&>OK<'"));
Assert.assertTrue(s.contains("<![CDATA[https://en.wikipedia.org/w/index.php?title=XML&action=edit§ion=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());
}
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());
}
Aggregations