Package org.togglz.core.repository

Examples of org.togglz.core.repository.FeatureState


     * @return
     */
    @SuppressWarnings("unchecked")
    private FeatureState createFeatureState(final Feature feature, final Entity featureEntity) {
        final Boolean enabled = (Boolean) featureEntity.getProperty(ENABLED);
        final FeatureState state = new FeatureState(feature, enabled);

        final String strategyId = (String) featureEntity.getProperty(STRATEGY_ID);
        if (!Strings.isNullOrEmpty(strategyId)) {
            state.setStrategyId(strategyId.trim());
        }

        final List<String> strategyParamsNames = (List<String>) featureEntity.getProperty(STRATEGY_PARAMS_NAMES);
        final List<String> strategyParamsValues = (List<String>) featureEntity.getProperty(STRATEGY_PARAMS_VALUES);
        if (strategyParamsNames != null && strategyParamsValues != null && !strategyParamsNames.isEmpty()
            && !strategyParamsValues.isEmpty() && strategyParamsNames.size() == strategyParamsValues.size()) {
            for (int i = 0; i < strategyParamsNames.size(); i++) {
                state.setParameter(strategyParamsNames.get(i), strategyParamsValues.get(i));
            }
        }
        return state;
    }
View Full Code Here


        this.expiration = Expiration.byDeltaMillis(ttlInSeconds);
    }

    @Override
    public FeatureState getFeatureState(Feature feature) {
        FeatureState state = (FeatureState) cache.get(key(feature.name()));
        if (state == null) {
            state = delegate.getFeatureState(feature);
            cache.put(key(feature.name()), state, getExpiration());
        }
        return state;
View Full Code Here

        try {

            // modify FEATURE1 and FEATURE2, don't touch FEATURE3
            FileBasedStateRepository repo = new FileBasedStateRepository(file);
            repo.setFeatureState(new FeatureState(MyFeature.FEATURE1, false));
            repo.setFeatureState(new FeatureState(MyFeature.FEATURE2, true)
                .setStrategyId("some-strategy").setParameter("myparam", "myvalue"));

            Properties newProps = readPropertiesFile(file);

            assertThat(newProps.size(), is(5));
View Full Code Here

        try {

            FileBasedStateRepository repo = new FileBasedStateRepository(file);

            FeatureState state = repo.getFeatureState(MyFeature.FEATURE1);
            state.setParameter("other", "something-else");
            repo.setFeatureState(state);

            Properties newProps = readPropertiesFile(file);

            assertThat(newProps.size(), is(4));
View Full Code Here

        try {

            FileBasedStateRepository repo = new FileBasedStateRepository(file);

            FeatureState state = repo.getFeatureState(MyFeature.FEATURE1);
            state.setParameter("myparam", null);
            repo.setFeatureState(state);

            Properties newProps = readPropertiesFile(file);

            assertThat(newProps.size(), is(2));
View Full Code Here

        try {

            FileBasedStateRepository repo = new FileBasedStateRepository(file);

            FeatureState state = repo.getFeatureState(MyFeature.FEATURE1);
            state.setStrategyId("something");
            repo.setFeatureState(state);

            Properties newProps = readPropertiesFile(file);

            assertThat(newProps.size(), is(2));
View Full Code Here

        try {

            FileBasedStateRepository repo = new FileBasedStateRepository(file);

            FeatureState state = repo.getFeatureState(MyFeature.FEATURE1);
            state.setStrategyId(null);
            repo.setFeatureState(state);

            Properties newProps = readPropertiesFile(file);

            assertThat(newProps.size(), is(1));
View Full Code Here

        try {

            FileBasedStateRepository repo = new FileBasedStateRepository(file);

            FeatureState state = repo.getFeatureState(MyFeature.FEATURE1);
            state.enable();
            repo.setFeatureState(state);

            Properties newProps = readPropertiesFile(file);

            assertThat(newProps.size(), is(3));
View Full Code Here

        try {

            FileBasedStateRepository repo = new FileBasedStateRepository(file);

            FeatureState state = repo.getFeatureState(MyFeature.FEATURE1);
            state.disable();
            repo.setFeatureState(state);

            Properties newProps = readPropertiesFile(file);

            assertThat(newProps.size(), is(3));
View Full Code Here

             */

            FileBasedStateRepository repo = new FileBasedStateRepository(file);

            // FEATURE1: enabled, strategy set by migration code, one property containing user list
            FeatureState state1 = repo.getFeatureState(MyFeature.FEATURE1);
            assertEquals(true, state1.isEnabled());
            assertEquals(UsernameActivationStrategy.ID, state1.getStrategyId());
            assertEquals(1, state1.getParameterNames().size());
            assertEquals("chkal,tester", state1.getParameter(UsernameActivationStrategy.PARAM_USERS));

            // FEATURE2: disabled, no strategy, no parameters
            FeatureState state2 = repo.getFeatureState(MyFeature.FEATURE2);
            assertEquals(false, state2.isEnabled());
            assertEquals(null, state2.getStrategyId());
            assertEquals(0, state2.getParameterNames().size());

            // FEATURE3: enabled, no strategy, no parameters
            FeatureState state3 = repo.getFeatureState(MyFeature.FEATURE3);
            assertEquals(true, state3.isEnabled());
            assertEquals(null, state2.getStrategyId());
            assertEquals(0, state3.getParameterNames().size());

            FeatureState state4 = repo.getFeatureState(MyFeature.FEATURE4);
            assertNull(state4);

            /*
             * Now change one feature and check the new format is persisted
             */
 
View Full Code Here

TOP

Related Classes of org.togglz.core.repository.FeatureState

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.