HeaderActivationStrategy implements ActivationStrategy { @Override public boolean isActive(FeatureState featureState, FeatureUser user) { HttpServletRequest request = HttpServletRequestHolder.get(); if (request == null || featureState == null || featureState.getFeature() == null) { return false; } String header = request.getHeader("X-Features"); if (header == null) { return false; } String[] split = header.split(","); return Arrays.stream(split).anyMatch(feature -> feature.equals(featureState.getFeature().name())); }  @Override String getId(); @Override String getName(); @Override boolean isActive(FeatureState featureState, FeatureUser user); @Override Parameter[] getParameters();  }
@Test public void shouldNotBeActiveWithANullRequestObject() { HttpServletRequestHolder.release(); boolean isActive = strategy.isActive(state, user); assertFalse(isActive); }
@Test public void shouldNotBeActiveWithNoHeaders() { when(request.getHeader(any())).thenReturn(null); boolean isActive = strategy.isActive(state, user); assertFalse(isActive); }
@Test public void shouldNotBeActiveWhenOnlyNonMatchingParametersArePresent() { Map<String, String[]> parameters = new HashMap<>(); parameters.put("somethingThatDoesNotMatch", new String[]{"true"}); parameters.put("somethingElse", new String[]{"aValue"}); when(request.getParameterMap()).thenReturn(parameters); boolean isActive = strategy.isActive(state, user); assertFalse(isActive); }
@Test public void shouldNotBeActiveWhenRequestHeaderDoesNotIncludeFeatureToggle() { when(request.getHeader("X-Features")).thenReturn("OTHERFEATURE,ANOTHERFEATURE"); boolean isActive = strategy.isActive(state, user); assertFalse(isActive); }
@Test public void shouldBeActiveWhenRequestHeaderIncludesFeatureToggle() { when(request.getHeader("X-Features")).thenReturn("FEATURE,ANOTHERFEATURE"); boolean isActive = strategy.isActive(state, user); assertTrue(isActive); }