Search in sources :

Example 16 with FlippingStrategy

use of org.ff4j.core.FlippingStrategy in project ff4j by ff4j.

the class ClientFilterStrategyTest method testInitialisationProgram.

@Test
public void testInitialisationProgram() {
    FlippingStrategy fs = new ClientFilterStrategy("Pierre, Paul, Jacques");
    fs.init("f1", null);
    fs.init("f1", new HashMap<String, String>());
    new WhiteListStrategy();
    new WhiteListStrategy("Pierre");
    // Working
    new BlackListStrategy();
    FlippingStrategy bl2 = new BlackListStrategy("Pierre");
    FlippingExecutionContext context = new FlippingExecutionContext();
    context.putString("clientHostName", "localhost");
    Assert.assertTrue(bl2.evaluate("f1", new InMemoryFeatureStore(), context));
    context.putString("clientHostName", "Pierre");
    Assert.assertFalse(bl2.evaluate("f1", new InMemoryFeatureStore(), context));
}
Also used : ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) BlackListStrategy(org.ff4j.strategy.BlackListStrategy) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FlippingStrategy(org.ff4j.core.FlippingStrategy) WhiteListStrategy(org.ff4j.strategy.WhiteListStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Example 17 with FlippingStrategy

use of org.ff4j.core.FlippingStrategy in project ff4j by ff4j.

the class FeatureStoreJCacheTest method testUpdateFeatureCoreData.

/**
 * TDD.
 */
@Test
public void testUpdateFeatureCoreData() {
    // Parameters
    String newDescription = "new-description";
    FlippingStrategy newStrategy = new PonderationStrategy(0.12);
    // Given
    assertFf4j.assertThatFeatureExist(F1);
    Assert.assertFalse(newDescription.equals(testedStore.read(F1).getDescription()));
    // When
    Feature fpBis = testedStore.read(F1);
    fpBis.setDescription(newDescription);
    fpBis.setFlippingStrategy(newStrategy);
    testedStore.update(fpBis);
    // Then
    Feature updatedFeature = testedStore.read(F1);
    Assert.assertTrue(newDescription.equals(updatedFeature.getDescription()));
    Assert.assertNotNull(updatedFeature.getFlippingStrategy());
    Assert.assertEquals(newStrategy.toString(), updatedFeature.getFlippingStrategy().toString());
}
Also used : PonderationStrategy(org.ff4j.strategy.PonderationStrategy) FlippingStrategy(org.ff4j.core.FlippingStrategy) PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 18 with FlippingStrategy

use of org.ff4j.core.FlippingStrategy in project ff4j by ff4j.

the class FeatureStoreNeo4jLimitTest method testChangeGroup.

@Test
public void testChangeGroup() {
    try (Transaction tx = graphDb.beginTx()) {
        graphDb.execute("CREATE " + " (h0:FF4J_FEATURE_GROUP { name:'h0' }),\n" + " (h1:FF4J_FEATURE { uid:'h1', enable:false, description:'second', roles:['USER'] }),\n" + " (h1)-[:MEMBER_OF]->(h0);");
        tx.success();
    }
    Feature f1 = testedStore.read("h1");
    Property<?> newP = new PropertyString("ppp", "vvv");
    newP.setDescription("a description");
    f1.addProperty(newP);
    FlippingStrategy fs = new PonderationStrategy(0.1);
    fs.getInitParams().put("p1", "v1");
    fs.getInitParams().put("p2", "v2");
    f1.setFlippingStrategy(fs);
    f1.setGroup("g2");
    testedStore.update(f1);
    Assert.assertEquals("g2", testedStore.read("h1").getGroup());
    f1.getFlippingStrategy().getInitParams().put("p3", "v3");
    testedStore.update(f1);
    testedStore.setGraphDb(testedStore.getGraphDb());
}
Also used : PonderationStrategy(org.ff4j.strategy.PonderationStrategy) PropertyString(org.ff4j.property.PropertyString) Transaction(org.neo4j.graphdb.Transaction) FlippingStrategy(org.ff4j.core.FlippingStrategy) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Aggregations

FlippingStrategy (org.ff4j.core.FlippingStrategy)18 Feature (org.ff4j.core.Feature)9 PropertyString (org.ff4j.property.PropertyString)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 FlippingExecutionContext (org.ff4j.core.FlippingExecutionContext)4 PonderationStrategy (org.ff4j.strategy.PonderationStrategy)4 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)2 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 NodeList (org.w3c.dom.NodeList)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 FeatureStore (org.ff4j.core.FeatureStore)1 FeatureAccessException (org.ff4j.exception.FeatureAccessException)1