TogglzEndpoint { @WriteOperation public TogglzFeature setFeatureState(@Selector String name, boolean enabled) { final Feature feature = featureManager.getFeatures().stream() .filter(f -> f.name().equals(name)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Could not find feature with name " + name)); FeatureState featureState = changeFeatureStatus(feature, enabled); return new TogglzFeature(feature, featureState); } TogglzEndpoint(FeatureManager featureManager); @ReadOperation List<TogglzFeature> getAllFeatures(); @WriteOperation TogglzFeature setFeatureState(@Selector String name, boolean enabled);  }
@Test public void shouldEnableAFeature() { contextRunner.withConfiguration(AutoConfigurations.of( DispatcherServletPathConfig.class, TogglzAutoConfiguration.class, TogglzEndpointAutoConfiguration.class)) .withPropertyValues( "management.endpoints.web.exposure.include=*", "togglz.features.FEATURE_ONE.enabled: false") .run((context) -> { TogglzEndpoint endpoint = context.getBean(TogglzEndpoint.class); final TogglzFeature togglzFeature = endpoint.setFeatureState("FEATURE_ONE", true); assertTrue(togglzFeature.isEnabled()); }); }
@Test public void shouldDisableAFeature() { contextRunner.withConfiguration(AutoConfigurations.of( DispatcherServletPathConfig.class, TogglzAutoConfiguration.class, TogglzEndpointAutoConfiguration.class)) .withPropertyValues( "management.endpoints.web.exposure.include=*", "togglz.features.FEATURE_ONE.enabled: true") .run((context) -> { TogglzEndpoint endpoint = context.getBean(TogglzEndpoint.class); final TogglzFeature togglzFeature = endpoint.setFeatureState("FEATURE_ONE", false); assertFalse(togglzFeature.isEnabled()); }); }
@Test public void shouldThrowAnIllegalArgumentExceptionIfTheFeatureDoesNotExist() { contextRunner.withConfiguration(AutoConfigurations.of( DispatcherServletPathConfig.class, TogglzAutoConfiguration.class, TogglzEndpointAutoConfiguration.class)) .withPropertyValues("management.endpoints.web.exposure.include=*") .run((context) -> { TogglzEndpoint endpoint = context.getBean(TogglzEndpoint.class); assertThrows(IllegalArgumentException.class, () -> { final TogglzFeature togglzFeature = endpoint.setFeatureState("FEATURE_ONE", false); }); }); }