use of org.ff4j.core.Feature in project ff4j by ff4j.
the class FF4jCliDisplay method displayFeatures.
/**
* Command line uptime
*/
public static void displayFeatures(Map<String, Feature> features) {
if (features == null || features.isEmpty()) {
System.out.println(" There are no features in the store");
}
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.println("+--------------------+--------+---------------+--------------------------------+");
System.out.print("|");
AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
System.out.print(" Feature names ");
AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.print("|");
AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
System.out.print(" State ");
AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.print("|");
AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
System.out.print(" Group ");
AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.print("|");
AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
System.out.print(" Roles ");
AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.println("|");
System.out.println("+--------------------+--------+---------------+--------------------------------+");
for (Feature feat : features.values()) {
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.print("| ");
AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.GREEN);
System.out.print(StringUtils.rightPad(feat.getUid(), 19));
AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.print("| ");
if (feat.isEnable()) {
AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.GREEN);
System.out.print(StringUtils.rightPad("ON", 7));
} else {
AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.RED);
System.out.print(StringUtils.rightPad("OFF", 7));
}
AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.print("| ");
AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.WHITE);
String groupName = "---";
if (!StringUtils.isEmpty(feat.getGroup())) {
groupName = feat.getGroup();
}
System.out.print(StringUtils.rightPad(groupName, 14));
AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.print("| ");
AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.WHITE);
String roles = feat.getPermissions().toString();
roles = roles.substring(1, roles.length() - 1);
if ("".equals(roles)) {
roles = "---";
}
System.out.print(StringUtils.rightPad(roles, 31));
AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.println("| ");
}
AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
System.out.println("+--------------------+--------+---------------+--------------------------------+");
}
use of org.ff4j.core.Feature 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());
}
use of org.ff4j.core.Feature in project ff4j by ff4j.
the class FF4j method checkOveridingStrategy.
/**
* Overriding strategy on feature.
*
* @param featureID
* feature unique identifier.
* @param executionContext
* current execution context
* @return
*/
public boolean checkOveridingStrategy(String featureID, FlippingStrategy strats, FlippingExecutionContext executionContext) {
Feature fp = getFeature(featureID);
boolean flipped = fp.isEnable() && isAllowed(fp);
if (strats != null) {
flipped = flipped && strats.evaluate(featureID, getFeatureStore(), executionContext);
}
publishCheck(featureID, flipped);
return flipped;
}
use of org.ff4j.core.Feature in project ff4j by ff4j.
the class FeatureStoreDynamoDBIT method addEmptyStringAsRole.
@Test
public void addEmptyStringAsRole() {
// given
Feature feature = testedStore.read(AWESOME);
Assert.assertTrue(feature.getPermissions().isEmpty());
// when
feature.getPermissions().add("");
testedStore.update(feature);
// then
Assert.assertTrue(feature.getPermissions().isEmpty());
}
use of org.ff4j.core.Feature in project ff4j by ff4j.
the class FeatureStoreArangoDB method getGroupFeatures.
private List<Feature> getGroupFeatures(String group) {
Predicate<Feature> groupNonNull = f -> Objects.nonNull(f.getGroup());
Predicate<Feature> groupMatch = f -> group.equals(f.getGroup());
try {
return getAllFeatures().stream().filter(groupNonNull.and(groupMatch)).collect(toList());
} catch (ArangoDBException e) {
throw new GroupNotFoundException(group);
}
}
Aggregations