aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common/src/test
diff options
context:
space:
mode:
authorBogdana <bogdana.kushnir@sonarsource.com>2024-08-14 12:14:51 +0200
committersonartech <sonartech@sonarsource.com>2024-08-16 20:02:59 +0000
commitb92557753cae7fbd44dc105b121268ae3f3f6557 (patch)
treeb63db53baa6274ef725cf88a274dd7719c2d875c /server/sonar-server-common/src/test
parentf789c234d2212a3bce79b337b9c631799312bd34 (diff)
downloadsonarqube-b92557753cae7fbd44dc105b121268ae3f3f6557.tar.gz
sonarqube-b92557753cae7fbd44dc105b121268ae3f3f6557.zip
SONAR-22641 update info for email config host telemetry
Diffstat (limited to 'server/sonar-server-common/src/test')
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProviderTest.java30
1 files changed, 28 insertions, 2 deletions
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 90a3b51d997..1eb691373e2 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
@@ -21,6 +21,8 @@ package org.sonar.server.notification.email.telemetry;
import java.util.Optional;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
@@ -37,7 +39,7 @@ class EmailConfigHostTelemetryProviderTest {
private final DbSession dbSession = mock(DbSession.class);
@Test
- void getValue_returnsTheRightEmailConfHost() {
+ void emailConfigHostTelemetryProvider_returnCorrectFields() {
EmailConfigHostTelemetryProvider emailConfigHostTelemetryProvider = new EmailConfigHostTelemetryProvider(dbClient);
String host = "smtp.office365.com";
@@ -47,6 +49,30 @@ class EmailConfigHostTelemetryProviderTest {
assertThat(emailConfigHostTelemetryProvider.getMetricKey()).isEqualTo("email_conf_host");
assertThat(emailConfigHostTelemetryProvider.getGranularity()).isEqualTo(Granularity.WEEKLY);
assertThat(emailConfigHostTelemetryProvider.getDimension()).isEqualTo(Dimension.INSTALLATION);
- assertThat(emailConfigHostTelemetryProvider.getValue()).isEqualTo(Optional.of(host));
+ assertThat(emailConfigHostTelemetryProvider.getValue()).isEqualTo(Optional.of("office365.com"));
+ }
+
+ @ParameterizedTest
+ @MethodSource("hostAndExpectedDomainValues")
+ void getValue_returnsTheCorrectlyExtractedTopLevelDomain(String host, String domain) {
+ EmailConfigHostTelemetryProvider emailConfigHostTelemetryProvider = new EmailConfigHostTelemetryProvider(dbClient);
+
+ when(dbClient.openSession(false)).thenReturn(dbSession);
+ when(dbClient.internalPropertiesDao().selectByKey(dbSession, EMAIL_CONFIG_SMTP_HOST)).thenReturn(Optional.of(host));
+
+ assertThat(emailConfigHostTelemetryProvider.getValue()).isEqualTo(Optional.of(domain));
+ }
+
+ private static Object[][] hostAndExpectedDomainValues() {
+ return new Object[][]{
+ {"", "EMPTY_DOMAIN"},
+ {"smtpasad.org.sdf", "DOMAIN_NOT_UNDER_PUBLIC_SUFFIX"},
+ {"127.0.0.0", "NOT_VALID_DOMAIN_NAME"},
+ {"smtp.office365.com", "office365.com"},
+ {"outlook.office365.com/smthng/extra", "office365.com"},
+ {"my.domain.org/", "domain.org"},
+ {"http://smtp.gmail.com", "gmail.com"},
+ {"https://smtp.office365.com/smthng/extra", "office365.com"}
+ };
}
}