Search in sources :

Example 11 with FF4j

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);
}
Also used : FF4j(org.ff4j.FF4j) ArrayList(java.util.ArrayList) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 12 with FF4j

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());
}
Also used : FF4j(org.ff4j.FF4j) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) Test(org.junit.Test)

Example 13 with FF4j

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");
}
Also used : FF4j(org.ff4j.FF4j) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 14 with FF4j

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());
}
Also used : EventPublisher(org.ff4j.audit.EventPublisher) FF4j(org.ff4j.FF4j) InMemoryEventRepository(org.ff4j.audit.repository.InMemoryEventRepository) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 15 with FF4j

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")));
}
Also used : PonderationStrategy(org.ff4j.strategy.PonderationStrategy) FF4j(org.ff4j.FF4j) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FF4j (org.ff4j.FF4j)60 Test (org.junit.Test)41 Before (org.junit.Before)9 Feature (org.ff4j.core.Feature)8 ArrayList (java.util.ArrayList)4 PropertyString (org.ff4j.property.PropertyString)4 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)4 AssertFf4j (org.ff4j.test.AssertFf4j)4 InMemoryPropertyStore (org.ff4j.property.store.InMemoryPropertyStore)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 PropertyStoreAuditProxy (org.ff4j.audit.proxy.PropertyStoreAuditProxy)2 InMemoryCacheManager (org.ff4j.cache.InMemoryCacheManager)2 FeatureStore (org.ff4j.core.FeatureStore)2 PropertyDate (org.ff4j.property.PropertyDate)2 PropertyStore (org.ff4j.property.store.PropertyStore)2 SpringSecurityAuthorisationManager (org.ff4j.security.SpringSecurityAuthorisationManager)2 TestConstantsFF4j (org.ff4j.test.TestConstantsFF4j)2 ApiConfig (org.ff4j.web.ApiConfig)2 ApiConfigBuilder (org.ff4j.web.ApiConfigBuilder)2