@Test public void importYaml_should_be_same_asXMLImport() { InputStream xmlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.xml"); InputStream ymlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.yml"); XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(xmlFile); FF4jConfiguration ymlConfig = new YamlParser().parseConfigurationFile(ymlFile); assertEquals(xmlConfig.getFeatures().size(), ymlConfig.getFeatures().size()); assertEquals(xmlConfig.getProperties().size(), ymlConfig.getProperties().size()); Feature f1Xml = xmlConfig.getFeatures().get("first"); Feature f1Yml = ymlConfig.getFeatures().get("first"); assertEquals(f1Xml.getDescription(), f1Yml.getDescription()); assertEquals(f1Xml.getCustomProperties().size(), f1Yml.getCustomProperties().size()); 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()); }
@Override @SuppressWarnings("unchecked") public FF4jConfiguration parseConfigurationFile(InputStream inputStream) { Util.assertNotNull(inputStream, "Cannot read file stream is empty, check readability and path."); Map<?,?> yamlConfigFile = safeYaml.load(inputStream); Map<?,?> ff4jYamlMap = (Map<?, ?>) yamlConfigFile.get(FF4J_TAG); FF4jConfiguration ff4jConfig = new FF4jConfiguration(); if (ff4jYamlMap != null) { if (ff4jYamlMap.containsKey(GLOBAL_AUDIT_TAG)) { ff4jConfig.setAudit(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUDIT_TAG).toString())); } if (ff4jYamlMap.containsKey(GLOBAL_AUTOCREATE)) { ff4jConfig.setAutoCreate(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUTOCREATE).toString())); } ff4jConfig.getProperties() .putAll(parseProperties((List<Map<String, Object>>) ff4jYamlMap.get(PROPERTIES_TAG)) ); parseFeatures(ff4jConfig, (List<Map<String, Object>>) ff4jYamlMap.get(FEATURES_TAG)); } return ff4jConfig; }
YamlParser implements FF4jConfigurationParser<FF4jConfiguration> { @Override @SuppressWarnings("unchecked") public FF4jConfiguration parseConfigurationFile(InputStream inputStream) { Util.assertNotNull(inputStream, "Cannot read file stream is empty, check readability and path."); Map<?,?> yamlConfigFile = safeYaml.load(inputStream); Map<?,?> ff4jYamlMap = (Map<?, ?>) yamlConfigFile.get(FF4J_TAG); FF4jConfiguration ff4jConfig = new FF4jConfiguration(); if (ff4jYamlMap != null) { if (ff4jYamlMap.containsKey(GLOBAL_AUDIT_TAG)) { ff4jConfig.setAudit(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUDIT_TAG).toString())); } if (ff4jYamlMap.containsKey(GLOBAL_AUTOCREATE)) { ff4jConfig.setAutoCreate(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUTOCREATE).toString())); } ff4jConfig.getProperties() .putAll(parseProperties((List<Map<String, Object>>) ff4jYamlMap.get(PROPERTIES_TAG)) ); parseFeatures(ff4jConfig, (List<Map<String, Object>>) ff4jYamlMap.get(FEATURES_TAG)); } return ff4jConfig; } }
YamlParser implements FF4jConfigurationParser<FF4jConfiguration> { @Override @SuppressWarnings("unchecked") public FF4jConfiguration parseConfigurationFile(InputStream inputStream) { Util.assertNotNull(inputStream, "Cannot read file stream is empty, check readability and path."); Map<?,?> yamlConfigFile = safeYaml.load(inputStream); Map<?,?> ff4jYamlMap = (Map<?, ?>) yamlConfigFile.get(FF4J_TAG); FF4jConfiguration ff4jConfig = new FF4jConfiguration(); if (ff4jYamlMap != null) { if (ff4jYamlMap.containsKey(GLOBAL_AUDIT_TAG)) { ff4jConfig.setAudit(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUDIT_TAG).toString())); } if (ff4jYamlMap.containsKey(GLOBAL_AUTOCREATE)) { ff4jConfig.setAutoCreate(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUTOCREATE).toString())); } ff4jConfig.getProperties() .putAll(parseProperties((List<Map<String, Object>>) ff4jYamlMap.get(PROPERTIES_TAG)) ); parseFeatures(ff4jConfig, (List<Map<String, Object>>) ff4jYamlMap.get(FEATURES_TAG)); } return ff4jConfig; } YamlParser(); }
YamlParser implements FF4jConfigurationParser<FF4jConfiguration> { @Override @SuppressWarnings("unchecked") public FF4jConfiguration parseConfigurationFile(InputStream inputStream) { Util.assertNotNull(inputStream, "Cannot read file stream is empty, check readability and path."); Map<?,?> yamlConfigFile = safeYaml.load(inputStream); Map<?,?> ff4jYamlMap = (Map<?, ?>) yamlConfigFile.get(FF4J_TAG); FF4jConfiguration ff4jConfig = new FF4jConfiguration(); if (ff4jYamlMap != null) { if (ff4jYamlMap.containsKey(GLOBAL_AUDIT_TAG)) { ff4jConfig.setAudit(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUDIT_TAG).toString())); } if (ff4jYamlMap.containsKey(GLOBAL_AUTOCREATE)) { ff4jConfig.setAutoCreate(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUTOCREATE).toString())); } ff4jConfig.getProperties() .putAll(parseProperties((List<Map<String, Object>>) ff4jYamlMap.get(PROPERTIES_TAG)) ); parseFeatures(ff4jConfig, (List<Map<String, Object>>) ff4jYamlMap.get(FEATURES_TAG)); } return ff4jConfig; } YamlParser(); @Override InputStream export(FF4jConfiguration ff4jConfig); @Override @SuppressWarnings("unchecked") FF4jConfiguration parseConfigurationFile(InputStream inputStream); }
YamlParser implements FF4jConfigurationParser<FF4jConfiguration> { @Override @SuppressWarnings("unchecked") public FF4jConfiguration parseConfigurationFile(InputStream inputStream) { Util.assertNotNull(inputStream, "Cannot read file stream is empty, check readability and path."); Map<?,?> yamlConfigFile = safeYaml.load(inputStream); Map<?,?> ff4jYamlMap = (Map<?, ?>) yamlConfigFile.get(FF4J_TAG); FF4jConfiguration ff4jConfig = new FF4jConfiguration(); if (ff4jYamlMap != null) { if (ff4jYamlMap.containsKey(GLOBAL_AUDIT_TAG)) { ff4jConfig.setAudit(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUDIT_TAG).toString())); } if (ff4jYamlMap.containsKey(GLOBAL_AUTOCREATE)) { ff4jConfig.setAutoCreate(Boolean.valueOf(ff4jYamlMap.get(GLOBAL_AUTOCREATE).toString())); } ff4jConfig.getProperties() .putAll(parseProperties((List<Map<String, Object>>) ff4jYamlMap.get(PROPERTIES_TAG)) ); parseFeatures(ff4jConfig, (List<Map<String, Object>>) ff4jYamlMap.get(FEATURES_TAG)); } return ff4jConfig; } YamlParser(); @Override InputStream export(FF4jConfiguration ff4jConfig); @Override @SuppressWarnings("unchecked") FF4jConfiguration parseConfigurationFile(InputStream inputStream);  }