Package org.ff4j.core

Examples of org.ff4j.core.Feature


    public void testPut_upsertUpdateRemoveAuthorization() {
        // Given
        assertFF4J.assertThatFeatureExist(F1);
        assertFF4J.assertThatFeatureHasRole(F1, ROLE_USER);
        // When
        Feature fNew = ff4j.getFeature(F1);
        fNew.getPermissions().remove(ROLE_USER);
        WebResource webResFeat = resourceFeatures().path(F1);
        ClientResponse res = webResFeat.put(ClientResponse.class, fNew.toString().getBytes());
        // Then HTTPResponse
        Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), res.getStatus());
        // Then Object Entity : null
        // Then
        assertFF4J.assertThatFeatureHasNotRole(F1, ROLE_USER);
View Full Code Here


        }
    }

    @Test
    public void testExpressionCustom() {
        Feature f = ff4j.getFeature("pond_6");
        Assert.assertEquals(new Double(0.6),
                Double.valueOf(((PonderationStrategy) f.getFlippingStrategy()).getInitParams().get("weight")));
        int nbOK = 0;
        int nbKO = 0;
        for (int i = 0; i < 1000; i++) {
            if (ff4j.check(f.getUid())) {
                nbOK++;
            } else {
                nbKO++;
            }
        }
View Full Code Here

    public void testGetFeature_DoesNotExistAutoCreate() {}

    @Test
    public void testFlipped() {
        FF4j ff4j = new FF4j().autoCreate(true).create(
                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");
View Full Code Here

    public void testPut_upsertUpdateAddAuthorization() {
        // Given
        assertFF4J.assertThatFeatureExist(F1);
        assertFF4J.assertThatFeatureHasNotRole(F1, ROLE_NEW);
        // When
        Feature fNew = ff4j.getFeature(F1);
        fNew.getPermissions().add(ROLE_NEW);
        WebResource webResFeat = resourceFeatures().path(F1);
        ClientResponse res = webResFeat.put(ClientResponse.class, fNew.toString().getBytes());
        // Then HTTPResponse
        Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), res.getStatus());
        // Then Object Entity : null
        // Then
        assertFF4J.assertThatFeatureHasRole(F1, ROLE_NEW);
View Full Code Here

     * @param executionContext
     *            current execution context
     * @return current feature status
     */
    public boolean check(String featureID, FlippingExecutionContext executionContext) {
        Feature fp = getFeature(featureID);
        boolean flipped = fp.isEnable();

        // If authorization manager provided, apply security filter
        if (flipped && getAuthorizationsManager() != null) {
            flipped = flipped && isAllowed(fp);
        }

        // If custom strategy has been defined, delegate flipping to
        if (flipped && fp.getFlippingStrategy() != null) {
            flipped = flipped && fp.getFlippingStrategy().evaluate(featureID, getStore(), executionContext);
        }

        // Any access is logged into audit system
        getEventPublisher().publish(featureID, flipped);

View Full Code Here

     * @param executionContext
     *            current execution context
     * @return
     */
    public boolean checkOveridingStrategy(String featureID, FlippingStrategy strats, FlippingExecutionContext executionContext) {
        Feature fp = getFeature(featureID);
        boolean flipped = fp.isEnable() && isAllowed(fp);
        if (strats != null) {
            flipped = flipped && strats.evaluate(featureID, getStore(), executionContext);
        }

        // Any modification done is logged into audit system
View Full Code Here

    public FF4j enable(String featureID) {
        try {
            getStore().enable(featureID);
        } catch (FeatureNotFoundException fnfe) {
            if (this.autocreate) {
                return create(new Feature(featureID, true));
            }
            throw fnfe;
        }
        getEventPublisher().publish(featureID, EventType.ENABLE);
        return this;
View Full Code Here

     *
     * @param featureID
     *            unique feature identifier.
     */
    public FF4j create(String featureName, boolean enable, String description) {
        return create(new Feature(featureName, enable, description));
    }
View Full Code Here

    public FF4j disable(String featureID) {
        try {
            getStore().disable(featureID);
        } catch (FeatureNotFoundException fnfe) {
            if (this.autocreate) {
                return create(new Feature(featureID, false));
            }
            throw fnfe;
        }
        getEventPublisher().publish(featureID, EventType.DISABLE);
        return this;
View Full Code Here

     * @param featureID
     *            target feature ID
     * @return target feature.
     */
    public Feature getFeature(String featureID) {
        Feature fp = null;
        try {
            fp = getStore().read(featureID);
        } catch (FeatureNotFoundException fnfe) {
            if (this.autocreate) {
                fp = new Feature(featureID, false);
                getStore().create(fp);
            } else {
                throw fnfe;
            }
        }
View Full Code Here

TOP

Related Classes of org.ff4j.core.Feature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.