@Override public Optional<ExperimentalFeature> getFeature(String featureId) { return features.stream() .filter(feature -> feature.getFeatureId().equals(featureId)) .map(feature -> (ExperimentalFeature) feature) .findAny(); }
@Override public boolean isFeatureEnabled(String featureId) { Optional<ExperimentalFeature> optional = getFeature(featureId); if (optional.isPresent()) { return optional.get().isEnabled(); } return true; }
@Override public void updateExperimentalFeature(String featureId, boolean enabled) { if (isExperimentalEnabled()) { Optional<ExperimentalFeature> optional = session.getFeaturesRegistry().getFeature(featureId); if (optional.isPresent()) { ExperimentalFeatureImpl feature = (ExperimentalFeatureImpl) optional.get(); if (feature.isEnabled() != enabled) { feature.setEnabled(enabled); event.fire(new NonPortableExperimentalFeatureModifiedEvent(feature)); } } } }
@Test public void testNotifyFeatureUpdate() { initService(true); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.updateExperimentalFeature(feature.getFeatureId(), feature.isEnabled()); checkNotifyFeatureUpdate(feature); }
@Override public void store(final ExperimentalFeatureImpl feature) { List<ExperimentalFeatureImpl> registeredFeatures = (List<ExperimentalFeatureImpl>) getFeatures(); Optional<ExperimentalFeatureImpl> optional = registeredFeatures.stream() .filter(registeredFeature -> registeredFeature.getFeatureId().equals(feature.getFeatureId())) .findAny(); if (optional.isPresent()) { ExperimentalFeatureImpl registeredFeature = optional.get(); registeredFeature.setEnabled(feature.isEnabled()); doStoreFeatures(registeredFeatures, () -> this.maybeNotifyFeatureUpdate(feature)); } }
@Override public boolean isFeatureEnabled(String featureId) { ExperimentalFeaturesRegistryImpl registry = getFeaturesRegistry(); if(!registry.getFeature(featureId).isPresent()) { return true; } return isExperimentalEnabled() && getFeaturesRegistry().isFeatureEnabled(featureId); }
private void initService(boolean experimentalEnabled) { List<ExperimentalFeatureImpl> features = new ArrayList<>(); features.add(new ExperimentalFeatureImpl(FEATURE_1, true)); features.add(new ExperimentalFeatureImpl(FEATURE_2, true)); features.add(new ExperimentalFeatureImpl(FEATURE_3, false)); registry = spy(new ExperimentalFeaturesRegistryImpl(features)); when(backendService.getExperimentalFeaturesSession()).thenReturn(new ExperimentalFeaturesSessionImpl(experimentalEnabled, registry)); service.loadRegistry(); } }
@Test public void testNotifyFeatureUpdateViaEvent() { initService(true); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.onGlobalFeatureModified(new PortableExperimentalFeatureModifiedEvent(feature)); checkNotifyFeatureUpdate(feature); }
private void testLoad(boolean enableAll) { if (!enableAll) { features.forEach(feature -> feature.setEnabled(true)); } group.init(GROUP_KEY, new ArrayList<>(features), callback); checkClear(); verify(view).setLabel(GROUP_KEY); checkSetEnableAllLabel(enableAll, 1); }
private ExperimentalFeaturesRegistryImpl loadRegistry() { List<ExperimentalFeatureImpl> features = new ArrayList<>(); features.addAll(userStorage.getFeatures()); features.addAll(globalStorage.getFeatures()); return new ExperimentalFeaturesRegistryImpl(features); }
@Test public void testNotifyFeatureUpdate() { initService(true); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.updateExperimentalFeature(feature.getFeatureId(), feature.isEnabled()); checkNotifyFeatureUpdate(feature); }
@Override public void updateExperimentalFeature(String featureId, boolean enabled) { if (isExperimentalEnabled()) { Optional<ExperimentalFeature> optional = session.getFeaturesRegistry().getFeature(featureId); if (optional.isPresent()) { ExperimentalFeatureImpl feature = (ExperimentalFeatureImpl) optional.get(); if (feature.isEnabled() != enabled) { feature.setEnabled(enabled); event.fire(new NonPortableExperimentalFeatureModifiedEvent(feature)); } } } }
@Override public void store(final ExperimentalFeatureImpl feature) { List<ExperimentalFeatureImpl> registeredFeatures = (List<ExperimentalFeatureImpl>) getFeatures(); Optional<ExperimentalFeatureImpl> optional = registeredFeatures.stream() .filter(registeredFeature -> registeredFeature.getFeatureId().equals(feature.getFeatureId())) .findAny(); if (optional.isPresent()) { ExperimentalFeatureImpl registeredFeature = optional.get(); registeredFeature.setEnabled(feature.isEnabled()); doStoreFeatures(registeredFeatures, () -> this.maybeNotifyFeatureUpdate(feature)); } }
@Override public boolean isFeatureEnabled(String featureId) { ExperimentalFeaturesRegistryImpl registry = getFeaturesRegistry(); if(!registry.getFeature(featureId).isPresent()) { return true; } return isExperimentalEnabled() && getFeaturesRegistry().isFeatureEnabled(featureId); }
private void initService(boolean experimentalEnabled) { List<ExperimentalFeatureImpl> features = new ArrayList<>(); features.add(new ExperimentalFeatureImpl(FEATURE_1, true)); features.add(new ExperimentalFeatureImpl(FEATURE_2, true)); features.add(new ExperimentalFeatureImpl(FEATURE_3, false)); registry = spy(new ExperimentalFeaturesRegistryImpl(features)); when(backendService.getExperimentalFeaturesSession()).thenReturn(new ExperimentalFeaturesSessionImpl(experimentalEnabled, registry)); service.loadRegistry(); } }
@Override public boolean isFeatureEnabled(String featureId) { Optional<ExperimentalFeature> optional = getFeature(featureId); if (optional.isPresent()) { return optional.get().isEnabled(); } return true; }
@Override public Optional<ExperimentalFeature> getFeature(String featureId) { return features.stream() .filter(feature -> feature.getFeatureId().equals(featureId)) .map(feature -> (ExperimentalFeature) feature) .findAny(); }
@Test public void testNotifyFeatureUpdateViaEvent() { initService(true); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.onGlobalFeatureModified(new PortableExperimentalFeatureModifiedEvent(feature)); checkNotifyFeatureUpdate(feature); }
private ExperimentalFeaturesRegistryImpl loadRegistry() { List<ExperimentalFeatureImpl> features = new ArrayList<>(); features.addAll(userStorage.getFeatures()); features.addAll(globalStorage.getFeatures()); return new ExperimentalFeaturesRegistryImpl(features); }
@Test public void testNotifyFeatureUpdateWhenExperimentalDisabled() { initService(false); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.updateExperimentalFeature(feature.getFeatureId(), feature.isEnabled()); verify(event, never()).fire(any()); }