Search in sources :

Example 21 with FlippingExecutionContext

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

the class FeatureTest method testFlipExecContext.

@Test
public void testFlipExecContext() {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("a", new Double(1D));
    parameters.put("b", new Integer(1));
    parameters.put("c", new Boolean(true));
    parameters.put("d", new Date());
    FlippingExecutionContext fec = new FlippingExecutionContext(parameters);
    fec.getDouble("a");
    fec.getInt("b");
    fec.getBoolean("c");
    fec.getDate("d");
}
Also used : HashMap(java.util.HashMap) PropertyString(org.ff4j.property.PropertyString) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Date(java.util.Date) Test(org.junit.Test)

Example 22 with FlippingExecutionContext

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

the class FeatureTest method testFlipExecContext7.

@Test(expected = IllegalArgumentException.class)
public void testFlipExecContext7() {
    Map<String, Object> parameters = new HashMap<String, Object>();
    FlippingExecutionContext fec = new FlippingExecutionContext();
    parameters.put("b", new Integer(1));
    fec.getString("b");
}
Also used : HashMap(java.util.HashMap) PropertyString(org.ff4j.property.PropertyString) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Test(org.junit.Test)

Example 23 with FlippingExecutionContext

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

the class ClientFilterStrategyTest method testFilterRequiredClientHostName.

@Test(expected = IllegalArgumentException.class)
public void testFilterRequiredClientHostName() {
    // Given
    Feature f1 = ff4j.getFeature(F1);
    Assert.assertNotNull(f1.getFlippingStrategy());
    org.ff4j.strategy.ClientFilterStrategy cStra = (ClientFilterStrategy) f1.getFlippingStrategy();
    Assert.assertNotNull(cStra.getInitParams());
    Assert.assertEquals(1, cStra.getInitParams().size());
    Assert.assertTrue(f1.isEnable());
    // When
    FlippingExecutionContext fex = new FlippingExecutionContext();
    fex.addValue(FEATURE_NEW, FEATURE_NEW);
    // Then
    ff4j.check(F1, fex);
}
Also used : ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Feature(org.ff4j.core.Feature) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Example 24 with FlippingExecutionContext

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

the class ClientFilterStrategyTest method testFilterInvalidClient.

@Test
public void testFilterInvalidClient() throws ParseException {
    // Given
    Feature f1 = ff4j.getFeature(F1);
    Assert.assertNotNull(f1.getFlippingStrategy());
    org.ff4j.strategy.ClientFilterStrategy cStra = (ClientFilterStrategy) f1.getFlippingStrategy();
    Assert.assertNotNull(cStra.getInitParams());
    Assert.assertEquals(1, cStra.getInitParams().size());
    Assert.assertTrue(f1.isEnable());
    // When (add invalid client name)
    FlippingExecutionContext fex = new FlippingExecutionContext();
    fex.addValue(ClientFilterStrategy.CLIENT_HOSTNAME, FEATURE_NEW);
    // Then
    Assert.assertFalse(ff4j.check(F1, fex));
}
Also used : ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Feature(org.ff4j.core.Feature) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Example 25 with FlippingExecutionContext

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

the class ClientFilterStrategyTest method testFilterOK.

@Test
public void testFilterOK() throws ParseException {
    // Given
    Feature f1 = ff4j.getFeature(F1);
    Assert.assertNotNull(f1.getFlippingStrategy());
    org.ff4j.strategy.ClientFilterStrategy cStra = (ClientFilterStrategy) f1.getFlippingStrategy();
    Assert.assertNotNull(cStra.getInitParams());
    Assert.assertEquals(1, cStra.getInitParams().size());
    Assert.assertTrue(f1.isEnable());
    // When (add correct client name)
    FlippingExecutionContext fex = new FlippingExecutionContext();
    fex.addValue(ClientFilterStrategy.CLIENT_HOSTNAME, "pierre");
    // Then
    Assert.assertTrue(ff4j.check(F1, fex));
    Assert.assertNotNull(cStra.toJson());
}
Also used : ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Feature(org.ff4j.core.Feature) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Aggregations

FlippingExecutionContext (org.ff4j.core.FlippingExecutionContext)28 Test (org.junit.Test)21 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)8 HashMap (java.util.HashMap)6 Feature (org.ff4j.core.Feature)6 PropertyString (org.ff4j.property.PropertyString)6 Map (java.util.Map)4 FlippingStrategy (org.ff4j.core.FlippingStrategy)4 ClientFilterStrategy (org.ff4j.strategy.ClientFilterStrategy)4 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)3 ServerFilterStrategy (org.ff4j.strategy.ServerFilterStrategy)3 Date (java.util.Date)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Calendar (java.util.Calendar)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 FF4j (org.ff4j.FF4j)1