Package org.togglz.core.manager

Examples of org.togglz.core.manager.FeatureManager


    }

    @Override
    public void process(RequestEvent event) throws IOException {

        FeatureManager featureManager = event.getFeatureManager();
        HttpServletRequest request = event.getRequest();
        HttpServletResponse response = event.getResponse();

        // identify the feature
        Feature feature = null;
        String featureAsString = request.getParameter("f");
        for (Feature f : featureManager.getFeatures()) {
            if (f.name().equals(featureAsString)) {
                feature = f;
            }
        }
        if (feature == null) {
            response.sendError(403);
            return;
        }

        FeatureMetaData metadata = featureManager.getMetaData(feature);
        List<ActivationStrategy> impls = featureManager.getActivationStrategies();
        FeatureModel featureModel = new FeatureModel(feature, metadata, impls);

        // GET requests for this feature
        if ("GET".equals(request.getMethod())) {

            FeatureState state = featureManager.getFeatureState(feature);
            featureModel.populateFromFeatureState(state);

            renderEditPage(event, featureModel);

        }

        // POST requests for this feature
        if ("POST".equals(request.getMethod())) {

            featureModel.restoreFromRequest(request);

            // no validation errors
            if (featureModel.isValid()) {

                FeatureState state = featureModel.toFeatureState();
                featureManager.setFeatureState(state);
                response.sendRedirect("index");

            }

            // got validation errors
View Full Code Here


        Boolean bootstrap = config.isPerformBootstrap();

        // try to autodetect whether bootstrapping is required
        if (bootstrap == null) {

            FeatureManager existingFeatureManager = FeatureContext.getFeatureManagerOrNull();

            if (existingFeatureManager == null) {
                log.debug("Could not find any existing FeatureManager");
                bootstrap = true;
            } else {
                log.debug("Found existing FeatureManager: " + existingFeatureManager.getName());
                bootstrap = false;
            }

        }
View Full Code Here

public class FeatureMapTest {

    @Test
    public void canBootstrapViaConstructor() {
        FeatureManager featureManager = mock(FeatureManager.class);
        Set<Feature> features = new HashSet<Feature>();
        String name1 = "Feature 1";
        String name2 = "Feature 2";
        Feature feature1 = mock(Feature.class, name1);
        Feature feature2 = mock(Feature.class, name2);
        features.add(feature1);
        features.add(feature2);
        when(featureManager.getFeatures()).thenReturn(features);
        when(feature1.name()).thenReturn(name1);
        when(feature2.name()).thenReturn(name2);
        when(featureManager.isActive(featureNamed(name1))).thenReturn(true);
        when(featureManager.isActive(featureNamed(name2))).thenReturn(false);
        Map<Object, Boolean> map = new FeatureMap(featureManager);
        assertThat(map.size(), equalTo(2));
        assertThat(map.isEmpty(), is(false));
        assertThat(map.get(name1), equalTo(true));
        assertThat(map.get(name2), equalTo(false));
View Full Code Here

        List<Feature> features = Arrays.<Feature>asList(
            new NamedFeature("f1"),
            new NamedFeature("f2")
            );

        FeatureManager featureManager = mock(FeatureManager.class);
        when(featureManager.getFeatures()).thenReturn(new HashSet<Feature>(features));

        FeatureMap map = new FeatureMap(featureManager);

        assertThat(map).hasSize(2);
View Full Code Here

    }

    @Test
    public void shouldSupportLookupByFeatureName() {

        FeatureManager featureManager = mock(FeatureManager.class);
        when(featureManager.isActive(featureNamed("test"))).thenReturn(true);

        FeatureMap map = new FeatureMap(featureManager);

        assertThat(map.get("test")).isEqualTo(true);
        assertThat(map.get("other")).isEqualTo(false);
View Full Code Here

    }

    @Test
    public void shouldSupportLookupByFeatureInstance() {

        FeatureManager featureManager = mock(FeatureManager.class);
        when(featureManager.isActive(featureNamed("test"))).thenReturn(true);

        FeatureMap map = new FeatureMap(featureManager);

        assertThat(map.get(new NamedFeature("test"))).isEqualTo(true);
        assertThat(map.get(new NamedFeature("other"))).isEqualTo(false);
View Full Code Here

    /**
     * Binds a FeatureManager to the thread before starting each test
     */
    @Before
    public void before() {
        FeatureManager featureManager = new FeatureManagerBuilder()
                .featureEnum(MyFeature.class)
                .stateRepository(new InMemoryStateRepository())
                .userProvider(new NoOpUserProvider())
                .build();
        ThreadLocalFeatureManagerProvider.bind(featureManager);
View Full Code Here

    /**
     * The first test requires a FeatureManager
     */
    @Test
    public void firstTest() {
        FeatureManager featureManager = FeatureContext.getFeatureManager();
        assertNotNull(featureManager);
    }
View Full Code Here

    /**
     * The second test also
     */
    @Test
    public void secondTest() {
        FeatureManager featureManager = FeatureContext.getFeatureManager();
        assertNotNull(featureManager);
    }
View Full Code Here

TOP

Related Classes of org.togglz.core.manager.FeatureManager

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.