diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2019-03-26 17:26:21 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-04-23 10:37:53 +0200 |
commit | a9503346ee526d2d5cee4b74658736ec62846a69 (patch) | |
tree | 5ab12098e8fe0ff6b82f204c6441dd4c942c199c /server/sonar-server | |
parent | bab362aa98858b5ce1cc8a0442bf05f98c237d5f (diff) | |
download | sonarqube-a9503346ee526d2d5cee4b74658736ec62846a69.tar.gz sonarqube-a9503346ee526d2d5cee4b74658736ec62846a69.zip |
SONAR-11753 move "QG change" notification classes to single package
Diffstat (limited to 'server/sonar-server')
4 files changed, 3 insertions, 214 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/notification/ws/DispatchersImpl.java b/server/sonar-server/src/main/java/org/sonar/server/notification/ws/DispatchersImpl.java index 9c755aebced..5800cca5d34 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/notification/ws/DispatchersImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notification/ws/DispatchersImpl.java @@ -26,7 +26,7 @@ import java.util.function.Predicate; import org.sonar.api.Startable; import org.sonar.api.config.Configuration; import org.sonar.process.ProcessProperties; -import org.sonar.server.event.NewAlerts; +import org.sonar.server.qualitygate.notification.NewAlerts; import org.sonar.server.issue.notification.DoNotFixNotificationHandler; import org.sonar.server.issue.notification.NewIssuesNotificationHandler; import org.sonar.server.notification.NotificationCenter; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index e10db664628..bdb47697472 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -64,7 +64,7 @@ import org.sonar.server.es.RecoveryIndexer; import org.sonar.server.es.metadata.EsDbCompatibilityImpl; import org.sonar.server.es.metadata.MetadataIndex; import org.sonar.server.es.metadata.MetadataIndexDefinition; -import org.sonar.server.event.NewAlerts; +import org.sonar.server.qualitygate.notification.NewAlerts; import org.sonar.server.extension.CoreExtensionBootstraper; import org.sonar.server.extension.CoreExtensionStopper; import org.sonar.server.favorite.FavoriteModule; diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java deleted file mode 100644 index 164abbbaf72..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.notification.email; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.config.EmailSettings; -import org.sonar.api.notifications.Notification; -import org.sonar.plugins.emailnotifications.api.EmailMessage; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class AlertsEmailTemplateTest { - - private AlertsEmailTemplate template; - - @Before - public void setUp() { - EmailSettings configuration = mock(EmailSettings.class); - when(configuration.getServerBaseURL()).thenReturn("http://nemo.sonarsource.org"); - template = new AlertsEmailTemplate(configuration); - } - - @Test - public void shouldNotFormatIfNotCorrectNotification() { - Notification notification = new Notification("other-notif"); - EmailMessage message = template.format(notification); - assertThat(message, nullValue()); - } - - @Test - public void shouldFormatAlertWithSeveralMessages() { - Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "false"); - - EmailMessage message = template.format(notification); - assertThat(message.getMessageId(), is("alerts/45")); - assertThat(message.getSubject(), is("Quality gate status changed on \"Foo\"")); - assertThat(message.getMessage(), is("" + - "Project: Foo\n" + - "Version: V1-SNAP\n" + - "Quality gate status: Red (was Green)\n" + - "\n" + - "Quality gate thresholds:\n" + - " - violations > 4\n" + - " - coverage < 75%\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo")); - } - - @Test - public void shouldFormatAlertWithSeveralMessagesOnBranch() { - Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "false") - .setFieldValue("branch", "feature"); - - EmailMessage message = template.format(notification); - assertThat(message.getMessageId(), is("alerts/45")); - assertThat(message.getSubject(), is("Quality gate status changed on \"Foo (feature)\"")); - assertThat(message.getMessage(), is("" + - "Project: Foo\n" + - "Branch: feature\n" + - "Version: V1-SNAP\n" + - "Quality gate status: Red (was Green)\n" + - "\n" + - "Quality gate thresholds:\n" + - " - violations > 4\n" + - " - coverage < 75%\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo&branch=feature")); - } - - @Test - public void shouldFormatNewAlertWithSeveralMessages() { - Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "true"); - - EmailMessage message = template.format(notification); - assertThat(message.getMessageId(), is("alerts/45")); - assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\"")); - assertThat(message.getMessage(), is("" + - "Project: Foo\n" + - "Version: V1-SNAP\n" + - "Quality gate status: Red (was Green)\n" + - "\n" + - "New quality gate thresholds:\n" + - " - violations > 4\n" + - " - coverage < 75%\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo")); - } - - @Test - public void shouldFormatNewAlertWithOneMessage() { - Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true"); - - EmailMessage message = template.format(notification); - assertThat(message.getMessageId(), is("alerts/45")); - assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\"")); - assertThat(message.getMessage(), is("" + - "Project: Foo\n" + - "Version: V1-SNAP\n" + - "Quality gate status: Red (was Green)\n" + - "\n" + - "New quality gate threshold: violations > 4\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo")); - } - - @Test - public void shouldFormatNewAlertWithoutVersion() { - Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true") - .setFieldValue("projectVersion", null); - - EmailMessage message = template.format(notification); - assertThat(message.getMessageId(), is("alerts/45")); - assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\"")); - assertThat(message.getMessage(), is("" + - "Project: Foo\n" + - "Quality gate status: Red (was Green)\n" + - "\n" + - "New quality gate threshold: violations > 4\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo")); - } - - @Test - public void shouldFormatNewAlertWithOneMessageOnBranch() { - Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true") - .setFieldValue("branch", "feature"); - - EmailMessage message = template.format(notification); - assertThat(message.getMessageId(), is("alerts/45")); - assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo (feature)\"")); - assertThat(message.getMessage(), is("" + - "Project: Foo\n" + - "Branch: feature\n" + - "Version: V1-SNAP\n" + - "Quality gate status: Red (was Green)\n" + - "\n" + - "New quality gate threshold: violations > 4\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo&branch=feature")); - } - - @Test - public void shouldFormatBackToGreenMessage() { - Notification notification = createNotification("Green (was Red)", "", "OK", "false"); - - EmailMessage message = template.format(notification); - assertThat(message.getMessageId(), is("alerts/45")); - assertThat(message.getSubject(), is("\"Foo\" is back to green")); - assertThat(message.getMessage(), is("" + - "Project: Foo\n" + - "Version: V1-SNAP\n" + - "Quality gate status: Green (was Red)\n" + - "\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo")); - } - - @Test - public void shouldFormatBackToGreenMessageOnBranch() { - Notification notification = createNotification("Green (was Red)", "", "OK", "false") - .setFieldValue("branch", "feature"); - - EmailMessage message = template.format(notification); - assertThat(message.getMessageId(), is("alerts/45")); - assertThat(message.getSubject(), is("\"Foo (feature)\" is back to green")); - assertThat(message.getMessage(), is("" + - "Project: Foo\n" + - "Branch: feature\n" + - "Version: V1-SNAP\n" + - "Quality gate status: Green (was Red)\n" + - "\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo&branch=feature")); - } - - private Notification createNotification(String alertName, String alertText, String alertLevel, String isNewAlert) { - Notification notification = new Notification("alerts") - .setFieldValue("projectName", "Foo") - .setFieldValue("projectKey", "org.sonar.foo:foo") - .setFieldValue("projectId", "45") - .setFieldValue("projectVersion", "V1-SNAP") - .setFieldValue("alertName", alertName) - .setFieldValue("alertText", alertText) - .setFieldValue("alertLevel", alertLevel) - .setFieldValue("isNewAlert", isNewAlert); - return notification; - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/ws/DispatchersImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/ws/DispatchersImplTest.java index 5aa8aec6f5d..8b6c25b88fe 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notification/ws/DispatchersImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notification/ws/DispatchersImplTest.java @@ -22,7 +22,7 @@ package org.sonar.server.notification.ws; import org.junit.Test; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.notifications.NotificationChannel; -import org.sonar.server.event.NewAlerts; +import org.sonar.server.qualitygate.notification.NewAlerts; import org.sonar.server.issue.notification.DoNotFixNotificationHandler; import org.sonar.server.issue.notification.MyNewIssuesNotificationHandler; import org.sonar.server.issue.notification.NewIssuesNotificationHandler; |