aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorBogdana <bogdana.kushnir@sonarsource.com>2024-08-29 17:53:16 +0200
committersonartech <sonartech@sonarsource.com>2024-09-02 20:02:50 +0000
commit65adee146c1e2c630e54868899a2d90d41502aaf (patch)
treeb056b7ecb1b54960b99d27012349c4f01c384d91 /server/sonar-server-common
parent7ca382eedb1038d7b87378e3ab0099107f0fc039 (diff)
downloadsonarqube-65adee146c1e2c630e54868899a2d90d41502aaf.tar.gz
sonarqube-65adee146c1e2c630e54868899a2d90d41502aaf.zip
SONAR-22641 fix values for telemetry smtp config when Optional.empty() returned
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java3
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java14
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProviderTest.java11
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProviderTest.java12
4 files changed, 30 insertions, 10 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java
index c360e9eef1e..4ed588eb9b5 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java
@@ -20,7 +20,6 @@
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;
@@ -60,7 +59,7 @@ public class EmailConfigAuthMethodTelemetryProvider implements TelemetryDataProv
@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"));
}
}
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java
index 4486478fe04..e2fe55be6af 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java
@@ -21,7 +21,6 @@ package org.sonar.server.notification.email.telemetry;
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;
@@ -50,21 +49,22 @@ public class EmailConfigHostTelemetryProvider implements TelemetryDataProvider<S
}
@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"));
}
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProviderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProviderTest.java
index 6efc28365e0..3e0d1b00376 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProviderTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProviderTest.java
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.mock;
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;
@@ -49,4 +50,14 @@ class EmailConfigAuthMethodTelemetryProviderTest {
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"));
+ }
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProviderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProviderTest.java
index 1eb691373e2..c0af9a1a6d8 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProviderTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProviderTest.java
@@ -63,8 +63,18 @@ class EmailConfigHostTelemetryProviderTest {
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"},