package org.sonar.server.notification.email.telemetry;
import java.util.Optional;
-
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.telemetry.core.Dimension;
@Override
public Optional<String> getValue() {
try (DbSession dbSession = dbClient.openSession(false)) {
- return dbClient.internalPropertiesDao().selectByKey(dbSession, EMAIL_CONFIG_SMTP_AUTH_METHOD);
+ return Optional.of(dbClient.internalPropertiesDao().selectByKey(dbSession, EMAIL_CONFIG_SMTP_AUTH_METHOD).orElse("NOT_SET"));
}
}
}
import com.google.common.net.InternetDomainName;
import java.util.Optional;
-
import org.apache.commons.lang3.StringUtils;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
}
@Override
- public Granularity getGranularity() {
- return Granularity.WEEKLY;
+ public TelemetryDataType getType() {
+ return TelemetryDataType.STRING;
}
@Override
- public TelemetryDataType getType() {
- return TelemetryDataType.STRING;
+ public Granularity getGranularity() {
+ return Granularity.WEEKLY;
}
@Override
public Optional<String> getValue() {
try (DbSession dbSession = dbClient.openSession(false)) {
- return dbClient.internalPropertiesDao()
+ return Optional.of(dbClient.internalPropertiesDao()
.selectByKey(dbSession, EMAIL_CONFIG_SMTP_HOST)
- .map(EmailConfigHostTelemetryProvider::extractDomain);
+ .map(EmailConfigHostTelemetryProvider::extractDomain)
+ .orElse("NOT_SET"));
}
}
import static org.mockito.Mockito.when;
import static org.sonar.server.email.EmailSmtpConfiguration.EMAIL_CONFIG_SMTP_AUTH_METHOD;
import static org.sonar.server.email.EmailSmtpConfiguration.EMAIL_CONFIG_SMTP_AUTH_METHOD_DEFAULT;
+
import org.sonar.telemetry.core.Dimension;
import org.sonar.telemetry.core.Granularity;
assertThat(emailConfigAuthMethodTelemetryProvider.getDimension()).isEqualTo(Dimension.INSTALLATION);
assertThat(emailConfigAuthMethodTelemetryProvider.getValue()).isEqualTo(Optional.of("BASIC"));
}
+
+ @Test
+ void getValue_returnsNotSetWhenEmpty() {
+ EmailConfigAuthMethodTelemetryProvider emailConfigAuthMethodTelemetryProvider = new EmailConfigAuthMethodTelemetryProvider(dbClient);
+
+ when(dbClient.openSession(false)).thenReturn(dbSession);
+ when(dbClient.internalPropertiesDao().selectByKey(dbSession, EMAIL_CONFIG_SMTP_AUTH_METHOD)).thenReturn(Optional.empty());
+
+ assertThat(emailConfigAuthMethodTelemetryProvider.getValue()).isEqualTo(Optional.of("NOT_SET"));
+ }
}
assertThat(emailConfigHostTelemetryProvider.getValue()).isEqualTo(Optional.of(domain));
}
+ @Test
+ void getValue_returnsNotSetWhenEmpty() {
+ EmailConfigHostTelemetryProvider emailConfigHostTelemetryProvider = new EmailConfigHostTelemetryProvider(dbClient);
+
+ when(dbClient.openSession(false)).thenReturn(dbSession);
+ when(dbClient.internalPropertiesDao().selectByKey(dbSession, EMAIL_CONFIG_SMTP_HOST)).thenReturn(Optional.empty());
+
+ assertThat(emailConfigHostTelemetryProvider.getValue()).isEqualTo(Optional.of("NOT_SET"));
+ }
+
private static Object[][] hostAndExpectedDomainValues() {
- return new Object[][]{
+ return new Object[][] {
{"", "EMPTY_DOMAIN"},
{"smtpasad.org.sdf", "DOMAIN_NOT_UNDER_PUBLIC_SUFFIX"},
{"127.0.0.0", "NOT_VALID_DOMAIN_NAME"},