use of org.ff4j.FF4j in project ff4j by ff4j.
the class FF4jTest method testImportFeatures.
@Test
public void testImportFeatures() {
FF4j ff4j = new FF4j();
List<Feature> listOfFeatures = new ArrayList<Feature>();
listOfFeatures.add(new Feature("f1", true, null, null, Util.set("USER")));
ff4j.importFeatures(listOfFeatures);
Assert.assertTrue(ff4j.exist("f1"));
// no Error
ff4j.importFeatures(null);
}
use of org.ff4j.FF4j in project ff4j by ff4j.
the class FF4jTest method enableDisableGroups.
@Test
public void enableDisableGroups() {
// Given
FF4j ff4j = new FF4j();
ff4j.audit();
ff4j.setFeatureStore(new InMemoryFeatureStore());
ff4j.createFeature("f1", true);
ff4j.createFeature("f2");
ff4j.getFeatureStore().addToGroup("f1", "g1");
ff4j.getFeatureStore().addToGroup("f2", "g1");
// When
ff4j.disableGroup("g1");
// Then
Assert.assertFalse(ff4j.getFeature("f1").isEnable());
Assert.assertFalse(ff4j.getFeature("f2").isEnable());
// When
ff4j.enableGroup("g1");
// Then
Assert.assertTrue(ff4j.getFeature("f1").isEnable());
Assert.assertTrue(ff4j.getFeature("f2").isEnable());
// When
ff4j.enable("f1");
ff4j.setFileName(null);
// Then
Assert.assertTrue(ff4j.getFeature("f1").isEnable());
}
use of org.ff4j.FF4j in project ff4j by ff4j.
the class FF4jTest method testFlipped.
@Test
public void testFlipped() {
FF4j ff4j = new FF4j().autoCreate(true).createFeature(new Feature("coco", true, "grp2", "", Arrays.asList(new String[] { "ROLEA" })));
Assert.assertTrue(ff4j.check("coco"));
ff4j.setAuthorizationsManager(mockAuthManager);
Assert.assertTrue(ff4j.check("coco"));
FlippingExecutionContext ex = new FlippingExecutionContext();
ex.putString("OK", "OK");
Assert.assertTrue(ff4j.check("coco", ex));
Assert.assertTrue(ff4j.checkOveridingStrategy("coco", mockFlipStrategy));
Assert.assertTrue(ff4j.checkOveridingStrategy("coco", null, null));
Assert.assertFalse(ff4j.checkOveridingStrategy("cocorico", mockFlipStrategy));
// Update Coverage
ff4j.setAuthManager("something");
}
use of org.ff4j.FF4j in project ff4j by ff4j.
the class FF4jTest method monitoringAudit.
@Test
public void monitoringAudit() {
// Given
FF4j ff4j = new FF4j();
ff4j.setEventPublisher(new EventPublisher());
ff4j.setEventRepository(new InMemoryEventRepository());
ff4j.removeCurrentContext();
ff4j.getCurrentContext();
// When
ff4j.stop();
// When
ff4j.setEventPublisher(null);
ff4j.getEventPublisher();
ff4j.stop();
// When
Event evt = new Event("f1", EventConstants.TARGET_FEATURE, "f2", EventConstants.ACTION_CHECK_OK);
Assert.assertNotNull(evt.toJson());
Assert.assertNotNull(evt.toString());
// When
EventPublisher ep = new EventPublisher();
new EventPublisher(ep.getRepository(), null);
ep.setRepository(new InMemoryEventRepository());
// Then
Assert.assertNotNull(ep.getRepository());
}
use of org.ff4j.FF4j in project ff4j by ff4j.
the class FF4jTest method testEmptyPermission.
@Test
public void testEmptyPermission() {
FF4j ff4j = new FF4j();
ff4j.createFeature("f1", true);
ff4j.setAuthorizationsManager(new DefinedPermissionSecurityManager("a", new HashSet<String>()));
Assert.assertTrue(ff4j.checkOveridingStrategy("f1", new PonderationStrategy(1d)));
Assert.assertTrue(ff4j.isAllowed(ff4j.getFeature("f1")));
}
Aggregations