StagemonitorCoreConfigurationSourceInitializer extends StagemonitorConfigurationSourceInitializer { @Override public void onConfigurationInitialized(ConfigInitializedArguments configInitializedArguments) throws IOException { final CorePlugin corePlugin = configInitializedArguments.getConfiguration().getConfig(CorePlugin.class); final Collection<String> elasticsearchConfigurationSourceIds = corePlugin.getElasticsearchConfigurationSourceProfiles(); if (!elasticsearchConfigurationSourceIds.isEmpty()) { addElasticsearchConfigurationSources(configInitializedArguments.getConfiguration(), corePlugin, elasticsearchConfigurationSourceIds); } if (!corePlugin.getRemotePropertiesConfigUrls().isEmpty()) { logger.debug("RemotePropertiesConfigurationSource is enabled"); addRemotePropertiesConfigurationSources(configInitializedArguments.getConfiguration(), corePlugin); } }  @Override void modifyConfigurationSources(ModifyArguments modifyArguments); @Override void onConfigurationInitialized(ConfigInitializedArguments configInitializedArguments);  }
@Test(expected = IllegalStateException.class) public void testEsDownDeactivate() throws Exception { prepareESTest(); when(corePlugin.isDeactivateStagemonitorIfEsConfigSourceIsDown()).thenReturn(true); initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); }
@Test public void testEsDown() throws Exception { prepareESTest(); when(corePlugin.isDeactivateStagemonitorIfEsConfigSourceIsDown()).thenReturn(false); initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); verify(configuration).addConfigurationSourceAfter(any(ElasticsearchConfigurationSource.class), eq(SimpleSource.class)); }
@Test public void testESEnabledAndSpringCloudDisabled() throws IOException { prepareESTest(); initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); verify(configuration, never()).addConfigurationSourceAfter(any(RemotePropertiesConfigurationSource.class), eq(SimpleSource.class)); verify(configuration).addConfigurationSourceAfter(any(ElasticsearchConfigurationSource.class), eq(SimpleSource.class)); }
@Test public void testESDisabledAndSpringCloudEnabled() throws IOException { when(corePlugin.getRemotePropertiesConfigUrls()).thenReturn(Collections.singletonList(new URL("http: initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); verify(configuration).addConfigurationSourceAfter(any(RemotePropertiesConfigurationSource.class), eq(SimpleSource.class)); verify(configuration, never()).addConfigurationSourceAfter(any(ElasticsearchConfigurationSource.class), eq(SimpleSource.class)); }
@Test public void testSpringCloud_missingServerAddress() throws IOException { initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); verify(configuration, never()).addConfigurationSourceAfter(any(RemotePropertiesConfigurationSource.class), eq(SimpleSource.class)); }
@Test public void testCorrectProperties() throws IOException { when(corePlugin.getRemotePropertiesConfigUrls()).thenReturn(Collections.singletonList(new URL("http: initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); ArgumentCaptor<RemotePropertiesConfigurationSource> configSourceCaptor = ArgumentCaptor.forClass(RemotePropertiesConfigurationSource.class); verify(configuration).addConfigurationSourceAfter(configSourceCaptor.capture(), eq(SimpleSource.class)); Assert.assertEquals("http: }
@Test public void testSpringCloud_multipleConfigUrls() throws IOException { when(corePlugin.getRemotePropertiesConfigUrls()).thenReturn( Arrays.asList(new URL("http: when(corePlugin.getApplicationName()).thenReturn("myapplication"); initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); verify(configuration, times(3)).addConfigurationSourceAfter(any(RemotePropertiesConfigurationSource.class), eq(SimpleSource.class)); }