Search in sources :

Example 81 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class LogbackHelperTest method apply_does_not_set_level_if_sonar_global_level_is_TRACE.

@Test
public void apply_does_not_set_level_if_sonar_global_level_is_TRACE() {
    Properties properties = new Properties();
    properties.setProperty("sonar.log.level", Level.TRACE.toString());
    assertThat(underTest.getRootContext().getLogger("fii").getLevel()).isNull();
    LoggerContext context = underTest.apply(newLogLevelConfig().offUnlessTrace("fii").build(), new Props(properties));
    assertThat(context.getLogger("fii").getLevel()).isNull();
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 82 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class LogbackHelperTest method apply_set_level_to_OFF_if_sonar_global_level_is_not_set.

@Test
public void apply_set_level_to_OFF_if_sonar_global_level_is_not_set() {
    LoggerContext context = underTest.apply(newLogLevelConfig().offUnlessTrace("fii").build(), new Props(new Properties()));
    assertThat(context.getLogger("fii").getLevel()).isEqualTo(Level.OFF);
}
Also used : Props(org.sonar.process.Props) Properties(java.util.Properties) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 83 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class LogbackHelperTest method log_to_console_setting_disabled.

@Test
public void log_to_console_setting_disabled() {
    Properties properties = new Properties();
    properties.setProperty("sonar.log.console", "false");
    assertThat(underTest.isAllLogsToConsoleEnabled(new Props(properties))).isFalse();
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) Test(org.junit.Test)

Example 84 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class EsSettingsTest method configureAuthentication_givenClusterSearchPasswordProvidedButKeystorePathMissing_throwException.

@Test
public void configureAuthentication_givenClusterSearchPasswordProvidedButKeystorePathMissing_throwException() throws Exception {
    Props props = minProps(true);
    props.set(CLUSTER_SEARCH_PASSWORD.getKey(), "qwerty");
    EsSettings settings = new EsSettings(props, new EsInstallation(props), system);
    assertThatThrownBy(settings::build).isInstanceOf(MessageException.class).hasMessage("CLUSTER_ES_KEYSTORE property need to be set when using elastic search authentication");
}
Also used : MessageException(org.sonar.process.MessageException) Props(org.sonar.process.Props) Test(org.junit.Test)

Example 85 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class EsSettingsTest method minProps.

private Props minProps(boolean cluster, @Nullable String host, @Nullable String port) throws IOException {
    File homeDir = temp.newFolder();
    Props props = new Props(new Properties());
    ServiceLoaderWrapper serviceLoaderWrapper = mock(ServiceLoaderWrapper.class);
    when(serviceLoaderWrapper.load()).thenReturn(ImmutableSet.of());
    new ProcessProperties(serviceLoaderWrapper).completeDefaults(props);
    props.set(PATH_HOME.getKey(), homeDir.getAbsolutePath());
    props.set(Property.CLUSTER_ENABLED.getKey(), Boolean.toString(cluster));
    if (cluster) {
        ofNullable(host).ifPresent(h -> props.set(CLUSTER_NODE_ES_HOST.getKey(), h));
        ofNullable(port).ifPresent(p -> props.set(CLUSTER_NODE_ES_PORT.getKey(), p));
        ofNullable(host).ifPresent(h -> props.set(CLUSTER_NODE_SEARCH_HOST.getKey(), h));
        ofNullable(port).ifPresent(p -> props.set(CLUSTER_NODE_SEARCH_PORT.getKey(), p));
        ofNullable(port).ifPresent(h -> props.set(CLUSTER_ES_HOSTS.getKey(), h));
    } else {
        ofNullable(host).ifPresent(h -> props.set(SEARCH_HOST.getKey(), h));
        ofNullable(port).ifPresent(p -> props.set(SEARCH_PORT.getKey(), p));
    }
    return props;
}
Also used : ServiceLoaderWrapper(org.sonar.core.extension.ServiceLoaderWrapper) Props(org.sonar.process.Props) Properties(java.util.Properties) ProcessProperties(org.sonar.process.ProcessProperties) File(java.io.File) ProcessProperties(org.sonar.process.ProcessProperties)

Aggregations

Props (org.sonar.process.Props)143 Test (org.junit.Test)119 Properties (java.util.Properties)71 File (java.io.File)44 MessageException (org.sonar.process.MessageException)21 ProcessProperties (org.sonar.process.ProcessProperties)19 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)13 Settings (org.elasticsearch.common.settings.Settings)7 NodeHealth (org.sonar.process.cluster.health.NodeHealth)6 InetAddress (java.net.InetAddress)5 LoggerContext (ch.qos.logback.classic.LoggerContext)4 Tomcat (org.apache.catalina.startup.Tomcat)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assert.fail (org.junit.Assert.fail)3 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)3 Mockito (org.mockito.Mockito)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.verify (org.mockito.Mockito.verify)3