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(); } }
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 testWrongNotifyFeatureUpdateViaEvent() { initService(true); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, true); service.onGlobalFeatureModified(new PortableExperimentalFeatureModifiedEvent(feature)); verify(event, never()).fire(any()); feature = new ExperimentalFeatureImpl(WRONG_FEATURE_ID, true); service.onGlobalFeatureModified(new PortableExperimentalFeatureModifiedEvent(feature)); verify(event, never()).fire(any()); }
@Test public void testStoreFeature() throws IOException { testRegularLoad(); storage.store(new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, true)); verify(ioService, never()).newOutputStream(any()); verify(ioService, never()).startBatch(fileSystem); verify(ioService, never()).endBatch(); storage.store(new ExperimentalFeatureImpl(FEATURE_1, false)); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(FEATURE_1, false), new ExperimentalFeatureImpl(FEATURE_2, false), new ExperimentalFeatureImpl(FEATURE_3, true)); }
@Test public void testWrongNotifyFeatureUpdateViaEvent() { initService(true); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, true); service.onGlobalFeatureModified(new PortableExperimentalFeatureModifiedEvent(feature)); verify(event, never()).fire(any()); feature = new ExperimentalFeatureImpl(WRONG_FEATURE_ID, true); service.onGlobalFeatureModified(new PortableExperimentalFeatureModifiedEvent(feature)); verify(event, never()).fire(any()); }
@Test public void testStoreFeature() throws IOException { testRegularLoad(); storage.store(new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, true)); verify(ioService, never()).newOutputStream(any()); verify(ioService, never()).startBatch(fileSystem); verify(ioService, never()).endBatch(); storage.store(new ExperimentalFeatureImpl(FEATURE_1, false)); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(FEATURE_1, false), new ExperimentalFeatureImpl(FEATURE_2, false), new ExperimentalFeatureImpl(FEATURE_3, true)); }
@Test public void testFirstLoad() { storage.init(); verifyInit(); verify(ioService).exists(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, false)); }
@Test public void testFirstLoad() { storage.init(); verifyInit(); List<ExperimentalFeatureImpl> features = new ArrayList<>(storage.getFeatures()); verify(ioService).exists(any()); verify(ioService, never()).newInputStream(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(features, new ExperimentalFeatureImpl(FEATURE_1, false), new ExperimentalFeatureImpl(FEATURE_2, false), new ExperimentalFeatureImpl(FEATURE_3, false)); }
@Test public void testFirstLoad() { storage.init(); verifyInit(); verify(ioService).exists(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, false)); }
@Test public void testRegularLoad() throws IOException { Path path = fileSystem.getPath(storage.getStoragePath()); ioService.write(path, IOUtils.toString(getClass().getResourceAsStream("/test/global/regularFeatures.txt"), Charset.defaultCharset())); storage.init(); verifyInit(); verify(ioService, times(2)).exists(any()); verify(ioService).newInputStream(any()); verify(ioService, never()).newOutputStream(any()); verify(ioService, never()).startBatch(fileSystem); verify(ioService, never()).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, true), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, true)); }
@Test public void testNotifyFeatureUpdateWhenExperimentalDisabledViaEvent() { initService(false); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.onGlobalFeatureModified(new PortableExperimentalFeatureModifiedEvent(feature)); verify(event, never()).fire(any()); }
@Test public void testNotifyFeatureUpdateWhenExperimentalDisabledViaEvent() { initService(false); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.onGlobalFeatureModified(new PortableExperimentalFeatureModifiedEvent(feature)); verify(event, never()).fire(any()); }
@Test public void testFirstLoad() { storage.init(); verifyInit(); List<ExperimentalFeatureImpl> features = new ArrayList<>(storage.getFeatures()); verify(ioService).exists(any()); verify(ioService, never()).newInputStream(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(features, new ExperimentalFeatureImpl(FEATURE_1, false), new ExperimentalFeatureImpl(FEATURE_2, false), new ExperimentalFeatureImpl(FEATURE_3, false)); }
@Test public void testExtraFeaturesLoad() throws IOException { Path path = fileSystem.getPath(storage.getStoragePath()); ioService.write(path, IOUtils.toString(getClass().getResourceAsStream("/test/global/extraFeatures.txt"), Charset.defaultCharset())); storage.init(); verifyInit(); verify(ioService, times(2)).exists(any()); verify(ioService).newInputStream(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, true), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, true)); }
@Test public void testWrongNotifyFeatureUpdate() { initService(true); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, true); service.updateExperimentalFeature(feature.getFeatureId(), feature.isEnabled()); verify(event, never()).fire(any()); feature = new ExperimentalFeatureImpl(WRONG_FEATURE_ID, true); service.updateExperimentalFeature(feature.getFeatureId(), feature.isEnabled()); verify(event, never()).fire(any()); }
@Test public void testExtraFeaturesLoad() throws IOException { Path path = fileSystem.getPath(storage.getStoragePath()); ioService.write(path, IOUtils.toString(getClass().getResourceAsStream("/test/global/extraFeatures.txt"), Charset.defaultCharset())); storage.init(); verifyInit(); verify(ioService, times(2)).exists(any()); verify(ioService).newInputStream(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, true), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, true)); }
@Test public void testNotifyFeatureUpdateWhenExperimentalDisabled() { initService(false); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.updateExperimentalFeature(feature.getFeatureId(), feature.isEnabled()); verify(event, never()).fire(any()); }
@Test public void testNotifyFeatureUpdateWhenExperimentalDisabled() { initService(false); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.updateExperimentalFeature(feature.getFeatureId(), feature.isEnabled()); verify(event, never()).fire(any()); }
@Test public void testNotifyFeatureUpdateViaEvent() { initService(true); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.onGlobalFeatureModified(new PortableExperimentalFeatureModifiedEvent(feature)); checkNotifyFeatureUpdate(feature); }
@Test public void testNotifyFeatureUpdate() { initService(true); ExperimentalFeatureImpl feature = new ExperimentalFeatureImpl(FEATURE_1, false); service.updateExperimentalFeature(feature.getFeatureId(), feature.isEnabled()); checkNotifyFeatureUpdate(feature); }