private Batch(Builder builder) { components = new ArrayList<>(); components.addAll(builder.components); if (builder.environment != null) { components.add(builder.environment); } if (builder.globalProperties != null) { globalProperties.putAll(builder.globalProperties); } if (builder.isEnableLoggingConfiguration()) { loggingConfig = new LoggingConfiguration(builder.environment).setProperties(globalProperties); if (builder.logOutput != null) { loggingConfig.setLogOutput(builder.logOutput); } } }
@Test public void testDefaultFormat() { assertThat(new LoggingConfiguration(null) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); }
@Test public void shouldNotBeVerboseByDefault() { assertThat(new LoggingConfiguration(null) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); }
@Before public void setUp() { out = new ByteArrayOutputStream(); conf = new LoggingConfiguration(); listener = new SimpleLogListener(); }
@Test public void shouldNotSetBlankFormat() { assertThat(new LoggingConfiguration(null).setFormat(null) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); assertThat(new LoggingConfiguration(null).setFormat("") .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); assertThat(new LoggingConfiguration(null).setFormat(" ") .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); } }
@Test public void test_log_level_property() { Map<String, String> properties = Maps.newHashMap(); LoggingConfiguration conf = new LoggingConfiguration(null).setProperties(properties); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo("INFO"); properties.put("sonar.log.level", "INFO"); conf = new LoggingConfiguration(null).setProperties(properties); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo("INFO"); properties.put("sonar.log.level", "DEBUG"); conf = new LoggingConfiguration(null).setProperties(properties); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo("DEBUG"); properties.put("sonar.log.level", "TRACE"); conf = new LoggingConfiguration(null).setProperties(properties); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo("DEBUG"); }
@Test public void test_log_listener_setter() { LogOutput listener = mock(LogOutput.class); assertThat(new LoggingConfiguration(null).setLogOutput(listener).getLogOutput()).isEqualTo(listener); }
@Test public void testSetVerbose() { assertThat(new LoggingConfiguration(null).setVerbose(true) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_VERBOSE); assertThat(new LoggingConfiguration(null).setVerbose(false) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); assertThat(new LoggingConfiguration(null).setRootLevel("ERROR") .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo("ERROR"); }
@Test public void testSetFormat() { assertThat(new LoggingConfiguration(null).setFormat("%d %level") .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo("%d %level"); }
@Test public void testSetVerboseAnalysis() { Map<String, String> props = Maps.newHashMap(); LoggingConfiguration conf = new LoggingConfiguration(null).setProperties(props); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); props.put("sonar.verbose", "true"); conf.setProperties(props); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_VERBOSE); }
@Test public void test_deprecated_log_properties() { Map<String, String> properties = Maps.newHashMap(); assertThat(new LoggingConfiguration(null).setProperties(properties) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); properties.put("sonar.verbose", "true"); LoggingConfiguration conf = new LoggingConfiguration(null).setProperties(properties); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_VERBOSE); properties.put("sonar.verbose", "false"); conf = new LoggingConfiguration(null).setProperties(properties); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); properties.put("sonar.verbose", "false"); properties.put("sonar.log.profilingLevel", "FULL"); conf = new LoggingConfiguration(null).setProperties(properties); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo("DEBUG"); properties.put("sonar.verbose", "false"); properties.put("sonar.log.profilingLevel", "BASIC"); conf = new LoggingConfiguration(null).setProperties(properties); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo("DEBUG"); }
@Test public void testMavenFormat() { assertThat(new LoggingConfiguration(new EnvironmentInformation("maven", "1.0")) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_MAVEN); }
static LoggingConfiguration create(@Nullable EnvironmentInformation environment) { return new LoggingConfiguration(environment); }
private Batch(Builder builder) { components = new ArrayList<>(); components.addAll(builder.components); if (builder.environment != null) { components.add(builder.environment); } if (builder.globalProperties != null) { globalProperties.putAll(builder.globalProperties); } if (builder.isEnableLoggingConfiguration()) { loggingConfig = new LoggingConfiguration(builder.environment).setProperties(globalProperties); if (builder.logOutput != null) { loggingConfig.setLogOutput(builder.logOutput); } } }
private Batch(Builder builder) { components = Lists.newArrayList(); components.addAll(builder.components); if (builder.environment != null) { components.add(builder.environment); } if (builder.bootstrapProperties != null) { bootstrapProperties.putAll(builder.bootstrapProperties); } if (builder.isEnableLoggingConfiguration()) { loggingConfig = new LoggingConfiguration(builder.environment).setProperties(bootstrapProperties); if (builder.logOutput != null) { loggingConfig.setLogOutput(builder.logOutput); } } }