We are currently attempting to implement the Togglz library in Spring-MVC.
We currently manage the toggles in our code from our MyFeatures.java
file in the following way:
import org.togglz.core.Feature;
import org.togglz.core.annotation.EnabledByDefault;
import org.togglz.core.annotation.Label;
import org.togglz.core.context.FeatureContext;
public enum MyFeatures implements Feature {
@Label("A Feature")
MY_FEATURE;
public boolean isActive() {
return FeatureContext.getFeatureManager().isActive(this);
}
}
and then in our actual classes with:
if (MyFeatures.MY_FEATURE.isActive()) {
// some code...
}
This works well but we have a deficiency in our tests where we do the following:
@Rule
public TogglzRule togglzRule = TogglzRule.allDisabled(MyFeatures.class);
// some tests, then:
if (MyFeatures.MY_FEATURE.isActive()) {
// some feature dependent test...
}
The issue here is that our toggles in MyFeature.java
are defaulted to disabled, and toggled on/off from either our UI or within this MyFeatures.java
file. BUT... our toggles in the tests are defaulted to enabled and toggled on/off with either the line:
@Rule
public TogglzRule togglzRule = TogglzRule.allDisabled(MyFeatures.class);
or individually in each test.
This is AT LEAST two places we have to toggle off our features, maybe more if we have more tests using those features, so my question is:
Is it possible to control all the Togglz feature toggles from a single place, regardless of whether they are in the code or the tests?