@Test public void testESDisabledAndSpringCloudEnabled() throws IOException { when(corePlugin.getRemotePropertiesConfigUrls()).thenReturn(Collections.singletonList(new URL("http://localhost/config.json"))); 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_multipleConfigUrls() throws IOException { when(corePlugin.getRemotePropertiesConfigUrls()).thenReturn( Arrays.asList(new URL("http://localhost/config1"), new URL("http://localhost/config2"), new URL("http://some.other/domain"))); when(corePlugin.getApplicationName()).thenReturn("myapplication"); initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); // Expecting 3 config source verify(configuration, times(3)).addConfigurationSourceAfter(any(RemotePropertiesConfigurationSource.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 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 testCorrectProperties() throws IOException { when(corePlugin.getRemotePropertiesConfigUrls()).thenReturn(Collections.singletonList(new URL("http://localhost/config.json"))); initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); ArgumentCaptor<RemotePropertiesConfigurationSource> configSourceCaptor = ArgumentCaptor.forClass(RemotePropertiesConfigurationSource.class); verify(configuration).addConfigurationSourceAfter(configSourceCaptor.capture(), eq(SimpleSource.class)); Assert.assertEquals("http://localhost/config.json", configSourceCaptor.getValue().getName()); }
@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(expected = IllegalStateException.class) public void testEsDownDeactivate() throws Exception { prepareESTest(); when(corePlugin.isDeactivateStagemonitorIfEsConfigSourceIsDown()).thenReturn(true); initializer.onConfigurationInitialized(new StagemonitorConfigurationSourceInitializer.ConfigInitializedArguments(configuration)); }