Package org.ff4j.core

Examples of org.ff4j.core.FeatureXmlParser


     *            inpustream from configuration file
     * @throws IOException
     *             Error raised if the configuration cannot be read
     */
    private void opImportFile(InputStream in) throws IOException {
        Map<String, Feature> mapsOfFeat = new FeatureXmlParser().parseConfigurationFile(in);
        for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) {
            if (getFf4j().getStore().exist(feature.getKey())) {
                getFf4j().getStore().update(feature.getValue());
            } else {
                getFf4j().getStore().create(feature.getValue());
View Full Code Here


     * @throws IOException
     *             error when building response
     */
    private void opExportFile(HttpServletResponse res) throws IOException {
        Map<String, Feature> features = getFf4j().getStore().readAll();
        InputStream in = new FeatureXmlParser().exportFeatures(features);
        ServletOutputStream sos = null;
        try {
            sos = res.getOutputStream();
            res.setContentType("text/xml");
            res.setHeader("Content-Disposition", "attachment; filename=\"ff4j.xml\"");
View Full Code Here

*/
public class FeatureXmlParserTest {
    @Test
    public void testLoaderXMLFile() {
        InputStream in = getClass().getClassLoader().getResourceAsStream("test-featureXmlParserTest-ok.xml");
        Map<String, Feature> features = new FeatureXmlParser().parseConfigurationFile(in);

        Assert.assertEquals(7, features.size());
        Assert.assertTrue(features.containsKey("f0"));
        Assert.assertNotNull(features.get("f0").getDescription());
        Assert.assertNotNull(features.get("f0").getPermissions());
View Full Code Here

    }

    @Test(expected = IllegalArgumentException.class)
    public void testSaxException() {
        InputStream in = new ByteArrayInputStream("<TOTO>Invalid</TOTO2>".getBytes());
        new FeatureXmlParser().parseConfigurationFile(in);
    }
View Full Code Here

        new FeatureXmlParser().parseConfigurationFile(in);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNullFile() {
        new FeatureXmlParser().parseConfigurationFile(null);
    }
View Full Code Here

    }

    @Test(expected = IllegalArgumentException.class)
    public void testLoaderRequiredUid() {
        InputStream in = getClass().getClassLoader().getResourceAsStream("test-featureXmlParserTest-ko-uidrequired.xml");
        new FeatureXmlParser().parseConfigurationFile(in);
    }
View Full Code Here

    }

    @Test(expected = IllegalArgumentException.class)
    public void testLoaderRequiredEnable() {
        InputStream in = getClass().getClassLoader().getResourceAsStream("test-featureXmlParserTest-ko-enablerequired.xml");
        new FeatureXmlParser().parseConfigurationFile(in);
    }
View Full Code Here

    @Test(expected = IllegalArgumentException.class)
    public void testLoaderLoadInvalidStream() throws IOException {
        InputStream in = getClass().getClassLoader().getResourceAsStream("test-featureXmlParserTest-ok.xml");
        in.close();
        new FeatureXmlParser().parseConfigurationFile(in);
    }
View Full Code Here

    }

    @Test
    public void importThenExport() throws IOException {
        // Given
        FeatureXmlParser parser = new FeatureXmlParser();
        InputStream in = getClass().getClassLoader().getResourceAsStream("test-featureXmlParserTest-import-export.xml");
        Map<String, Feature> features = parser.parseConfigurationFile(in);
        Assert.assertNotNull(features);
        // When
        InputStream in2 = parser.exportFeatures(features);
        // Then
        // output is OK
        Map<String, Feature> features2 = parser.parseConfigurationFile(in2);
        Assert.assertNotNull(features2);
        Assert.assertEquals(features.size(), features2.size());
    }
View Full Code Here

     *
     * @return
     * @throws IOException
     */
    public InputStream exportFeatures() throws IOException {
        return new FeatureXmlParser().exportFeatures(getStore().readAll());
    }
View Full Code Here

TOP

Related Classes of org.ff4j.core.FeatureXmlParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.