Examples of FeatureState


Examples of org.togglz.core.repository.FeatureState

        update("F1", true, "myStrategy", map, null);

        /*
         * WHEN the repository reads the state
         */
        final FeatureState state = repository.getFeatureState(TestFeature.F1);

        /*
         * THEN the properties should be set like expected
         */
        assertNotNull(state);
        assertEquals(TestFeature.F1, state.getFeature());
        assertEquals(true, state.isEnabled());
        assertEquals("myStrategy", state.getStrategyId());
        assertEquals(1, state.getParameterNames().size());
        assertEquals("foobar", state.getParameter("param23"));

    }
View Full Code Here

Examples of org.togglz.core.repository.FeatureState

            is(Arrays.asList("foobar")));

        /*
         * WHEN the repository writes new state
         */
        final FeatureState state = new FeatureState(TestFeature.F1)
            .disable()
            .setStrategyId("someId")
            .setParameter("param", "foo");
        repository.setFeatureState(state);

View Full Code Here

Examples of org.togglz.core.repository.FeatureState

                    try {

                        if (resultSet.next()) {

                            boolean enabled = resultSet.getInt(Columns.FEATURE_ENABLED) > 0;
                            FeatureState state = new FeatureState(feature, enabled);

                            String strategyId = resultSet.getString(Columns.STRATEGY_ID);
                            if (Strings.isNotBlank(strategyId)) {
                                state.setStrategyId(strategyId.trim());
                            }

                            String paramData = resultSet.getString(Columns.STRATEGY_PARAMS);
                            if (Strings.isNotBlank(paramData)) {
                                Map<String, String> params = serializer.deserialize(paramData);
                                for (Entry<String, String> param : params.entrySet()) {
                                    state.setParameter(param.getKey(), param.getValue());
                                }
                            }

                            return state;
View Full Code Here

Examples of org.togglz.core.repository.FeatureState

    @Override
    public boolean isActive(Feature feature) {

        Validate.notNull(feature, "feature is required");

        FeatureState state = stateRepository.getFeatureState(feature);

        if (state == null) {
            return getMetaData(feature).isEnabledByDefault();
        }

        if (state.isEnabled()) {

            // if no strategy is selected, the decision is simple
            String strategyId = state.getStrategyId();
            if (strategyId == null) {
                return true;
            }

            FeatureUser user = userProvider.getCurrentUser();
View Full Code Here

Examples of org.togglz.core.repository.FeatureState

    }

    @Override
    public FeatureState getFeatureState(Feature feature) {
        Validate.notNull(feature, "feature is required");
        FeatureState state = stateRepository.getFeatureState(feature);
        if (state == null) {
            boolean enabled = getMetaData(feature).isEnabledByDefault();
            state = new FeatureState(feature, enabled);
        }
        return state;
    }
View Full Code Here

Examples of org.togglz.core.repository.FeatureState

        for (int i = 0; i < NUMBER_OF_FEATURES; i++) {

            // build up a feature state containing some data
            String name = "FEATURE" + i;
            Feature feature = new TestFeature(name);
            final FeatureState state = new FeatureState(feature)
                .setStrategyId("strategy-for-" + name)
                .setParameter("param-of-" + name, "some-value-of-" + name);

            // queue a thread writing that state
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    repo.setFeatureState(state);
                }
            });

        }

        // Step 2: Wait for all threads to finish
        executor.shutdown();
        executor.awaitTermination(5, TimeUnit.SECONDS);

        // Step 3: Verify the state written to the repository
        for (int i = 0; i < NUMBER_OF_FEATURES; i++) {

            // read the state
            String name = "FEATURE" + i;
            TestFeature feature = new TestFeature(name);
            FeatureState state = repo.getFeatureState(feature);

            // verify that the state is as expected
            assertThat(state).isNotNull();
            assertThat(state.getStrategyId()).isEqualTo("strategy-for-" + name);
            assertThat(state.getParameterMap())
                .hasSize(1)
                .contains(MapEntry.entry("param-of-" + name, "some-value-of-" + name));

        }
View Full Code Here

Examples of org.togglz.core.repository.FeatureState

    @Before
    public void setup() {
        delegate = Mockito.mock(StateRepository.class);
        // the mock supports the ENUM
        Mockito.when(delegate.getFeatureState(DummyFeature.TEST))
            .thenReturn(new FeatureState(DummyFeature.TEST, true));
        // and NamedFeature
        Mockito.when(delegate.getFeatureState(new NamedFeature("TEST")))
            .thenReturn(new FeatureState(DummyFeature.TEST, true));
    }
View Full Code Here

Examples of org.togglz.core.repository.FeatureState

            assertTrue(repository.getFeatureState(DummyFeature.TEST).isEnabled());
            Thread.sleep(10);
        }

        // now modify the feature state
        repository.setFeatureState(new FeatureState(DummyFeature.TEST, true));

        // do some lookups
        for (int i = 0; i < 5; i++) {
            assertTrue(repository.getFeatureState(DummyFeature.TEST).isEnabled());
            Thread.sleep(10);
View Full Code Here

Examples of org.togglz.core.repository.FeatureState

    }

    @Override
    public StateRepository getStateRepository() {
        InMemoryStateRepository repository = new InMemoryStateRepository();
        repository.setFeatureState(new FeatureState(JspTaglibFeature.ACTIVE_FEATURE, true));
        repository.setFeatureState(new FeatureState(JspTaglibFeature.INACTIVE_FEATURE, false));
        return repository;
    }
View Full Code Here

Examples of org.togglz.core.repository.FeatureState

    public FeatureState toFeatureState() {

        Validate.isTrue(getValidationErrors().isEmpty(),
            "Calling toFeatureState() is only allowed for a valid model");

        FeatureState state = new FeatureState(feature, enabled);

        if (strategy != null) {

            state.setStrategyId(strategy.getId());

            for (ParameterModel param : strategy.getParameters()) {
                state.setParameter(param.getId(), Strings.trimToNull(param.getValue()));
            }

        }

        return state;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.