Search in sources :

Example 16 with FlippingExecutionContext

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

the class ExpressionFlipStategyTest method testExplicitevaluate.

@Test
public void testExplicitevaluate() {
    ExpressionFlipStrategy efs = new ExpressionFlipStrategy();
    Assert.assertTrue(efs.evaluate("D", ff4j.getFeatureStore(), null));
    Assert.assertTrue(efs.evaluate("TOTO", ff4j.getFeatureStore(), null));
    FlippingExecutionContext fex = new FlippingExecutionContext();
    fex.putString(ExpressionFlipStrategy.PARAM_EXPRESSION, "D");
    Assert.assertTrue(efs.evaluate("D", ff4j.getFeatureStore(), fex));
    fex.putString(ExpressionFlipStrategy.PARAM_EXPRESSION, "TOTO");
    Assert.assertFalse(efs.evaluate("D", ff4j.getFeatureStore(), fex));
}
Also used : ExpressionFlipStrategy(org.ff4j.strategy.el.ExpressionFlipStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Test(org.junit.Test)

Example 17 with FlippingExecutionContext

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

the class FeatureJsonMarshallTest method testJsonUtils.

@Test
public void testJsonUtils() {
    FlippingStrategy ps = new FlippingStrategy() {

        public void init(String featureName, Map<String, String> initParam) {
        }

        public Map<String, String> getInitParams() {
            return null;
        }

        public boolean evaluate(String fn, FeatureStore s, FlippingExecutionContext ex) {
            return false;
        }
    };
    JsonUtils.flippingStrategyAsJson(ps);
}
Also used : FlippingStrategy(org.ff4j.core.FlippingStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Map(java.util.Map) FeatureStore(org.ff4j.core.FeatureStore) Test(org.junit.Test)

Example 18 with FlippingExecutionContext

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

the class FF4j method init.

/**
 * Initialization of background components.
 */
private synchronized void init() {
    // Execution Context
    FlippingExecutionContext context = new FlippingExecutionContext();
    this.currentExecutionContext.set(context);
    // Event Publisher
    if (eventPublisher == null) {
        eventPublisher = new EventPublisher(eventRepository);
        this.shutdownEventPublisher = true;
    }
    // Audit is enabled, proxified stores for auditing
    if (isEnableAudit()) {
        if (fstore != null && !(fstore instanceof FeatureStoreAuditProxy)) {
            this.fstore = new FeatureStoreAuditProxy(this, fstore);
        }
        if (pStore != null && !(pStore instanceof PropertyStoreAuditProxy)) {
            this.pStore = new PropertyStoreAuditProxy(this, pStore);
        }
    } else {
        // Audit is disabled but could have been enabled before... removing PROXY if relevant
        if (fstore != null && fstore instanceof FeatureStoreAuditProxy) {
            this.fstore = ((FeatureStoreAuditProxy) fstore).getTarget();
        }
        if (pStore != null && pStore instanceof PropertyStoreAuditProxy) {
            this.pStore = ((PropertyStoreAuditProxy) pStore).getTarget();
        }
    }
    // Flag as OK
    this.initialized = true;
}
Also used : PropertyStoreAuditProxy(org.ff4j.audit.proxy.PropertyStoreAuditProxy) EventPublisher(org.ff4j.audit.EventPublisher) FeatureStoreAuditProxy(org.ff4j.audit.proxy.FeatureStoreAuditProxy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext)

Example 19 with FlippingExecutionContext

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

the class FeatureTagDisable method eval.

/**
 * {@inheritDoc}
 */
protected boolean eval(FF4j ff4j, PageContext jspContext) {
    FlippingExecutionContext executionContext = new FlippingExecutionContext();
    if (isShareHttpSession()) {
        executionContext.putString("LOCALE", pageContext.getRequest().getLocalName());
        @SuppressWarnings("unchecked") Map<String, String[]> parameters = pageContext.getRequest().getParameterMap();
        for (Map.Entry<String, String[]> param : parameters.entrySet()) {
            String[] innerParams = param.getValue();
            if (innerParams != null) {
                StringBuilder sb = new StringBuilder();
                for (String innerParam : innerParams) {
                    sb.append(innerParam);
                    sb.append(",");
                }
                String expression = sb.toString();
                executionContext.putString(param.getKey(), expression.substring(0, expression.length() - 1));
            }
        }
    }
    return !ff4j.check(getFeatureid(), executionContext);
}
Also used : FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Map(java.util.Map)

Example 20 with FlippingExecutionContext

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

the class FeatureTest method testFlipExecContext3.

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

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