ApplicationVersionActivationStrategy implements ActivationStrategy { @Override public boolean isActive(FeatureState featureState, FeatureUser user) { String allowedVersionsParam = featureState.getParameter(PARAM_VERSIONS); if (Strings.isNotBlank(allowedVersionsParam)) { String currentVersion = SystemProperty.applicationVersion.get(); if (Strings.isNotBlank(currentVersion)) { List<String> allowedVersions = Strings.splitAndTrim(allowedVersionsParam, "[\\s,]+"); for (String allowedVersion : allowedVersions) { if (currentVersion.startsWith(allowedVersion)) { return true; } } } } return false; }  @Override String getId(); @Override String getName(); @Override boolean isActive(FeatureState featureState, FeatureUser user); @Override Parameter[] getParameters(); static final String ID; static final String PARAM_VERSIONS; }
@Test public void shouldReturnTrueWhenAtLeastOneOfTheVersionsMatchServerCurrentVersion() { ApplicationVersionActivationStrategy strategy = new ApplicationVersionActivationStrategy(); FeatureState state = aVersionState(CURRENT_VERSION + ",alpha,dev,uat"); boolean active = strategy.isActive(state, aFeatureUser(JOHN)); assertTrue(active); }
@Test public void shouldReturnFalseWhenNoneOfTheVersionsMatchTheServerCurrentVersion() { ApplicationVersionActivationStrategy strategy = new ApplicationVersionActivationStrategy(); FeatureState state = aVersionState("test,alpha,dev,uat,rc1"); boolean active = strategy.isActive(state, aFeatureUser(JOHN)); assertFalse(active); }
@Test public void shouldReturnFalseForEmptyVersion() { ApplicationVersionActivationStrategy strategy = new ApplicationVersionActivationStrategy(); FeatureState state = aVersionState(""); boolean active = strategy.isActive(state, aFeatureUser(JOHN)); assertFalse(active); }
@Test public void shouldReturnFalseForNullVersion() { ApplicationVersionActivationStrategy strategy = new ApplicationVersionActivationStrategy(); FeatureState state = aVersionState(null); boolean active = strategy.isActive(state, aFeatureUser(JOHN)); assertFalse(active); }
@Test public void shouldReturnFalseWhenCurrentVersionCannotBeResolved() { SystemProperty.applicationVersion.set(""); ApplicationVersionActivationStrategy strategy = new ApplicationVersionActivationStrategy(); FeatureState state = aVersionState(CURRENT_VERSION); boolean active = strategy.isActive(state, aFeatureUser(JOHN)); assertFalse(active); }
@Test public void shouldReturnTrueWhenMatchesServerCurrentVersion() { ApplicationVersionActivationStrategy strategy = new ApplicationVersionActivationStrategy(); FeatureState state = aVersionState(CURRENT_VERSION); boolean active = strategy.isActive(state, aFeatureUser(JOHN)); assertTrue(active); }