All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.otto.edison.testsupport.togglz.TogglzTestConfiguration Maven / Gradle / Ivy

There is a newer version: 3.3.3
Show newest version
package de.otto.edison.testsupport.togglz;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.togglz.core.Feature;
import org.togglz.core.context.FeatureContext;
import org.togglz.core.manager.TogglzConfig;
import org.togglz.core.repository.StateRepository;
import org.togglz.core.repository.mem.InMemoryStateRepository;
import org.togglz.core.user.FeatureUser;
import org.togglz.core.user.NoOpUserProvider;
import org.togglz.core.user.SimpleFeatureUser;
import org.togglz.core.user.UserProvider;

@Configuration
@ConditionalOnClass(name = "de.otto.edison.togglz.configuration.TogglzConfiguration")
public class TogglzTestConfiguration {

    @Bean
    @Profile("test")
    public UserProvider userProvider() {
        return () -> new SimpleFeatureUser("someName", false);
    }

    @Bean
    @Profile("test")
    public TogglzConfig togglzConfig() {
        return new TogglzConfig() {
            @Override
            public Class getFeatureClass() {
                return EmptyTestFeatures.class;
            }

            @Override
            public StateRepository getStateRepository() {
                return new InMemoryStateRepository();
            }

            @Override
            public UserProvider getUserProvider() {
                return new NoOpUserProvider();
            }
        };
    }

    public enum EmptyTestFeatures implements Feature {

        ;

        public boolean isActive() {
            return FeatureContext.getFeatureManager().isActive(this);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy