From: Fabrice Bellingard Date: Tue, 19 Feb 2013 14:23:15 +0000 (+0100) Subject: SONAR-4100 Update default notification dispatchers X-Git-Tag: 3.5~100 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1412a3035b48fdf83f4096663b320d7637118600;p=sonarqube.git SONAR-4100 Update default notification dispatchers - AlertsOnMyFavouriteProject => NewAlerts - NewViolationsOnMyFavouriteProject => NewViolationsOnFirstDiffPeriod --- diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index 2e42100b525..07f2c9fe38d 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -41,9 +41,9 @@ import org.sonar.plugins.core.dashboards.ProjectReviewsDashboard; import org.sonar.plugins.core.dashboards.ProjectTimeMachineDashboard; import org.sonar.plugins.core.measurefilters.MyFavouritesFilter; import org.sonar.plugins.core.measurefilters.ProjectFilter; -import org.sonar.plugins.core.notifications.alerts.AlertsOnMyFavouriteProject; +import org.sonar.plugins.core.notifications.alerts.NewAlerts; import org.sonar.plugins.core.notifications.reviews.ChangesInReviewAssignedToMeOrCreatedByMe; -import org.sonar.plugins.core.notifications.violations.NewViolationsOnMyFavouriteProject; +import org.sonar.plugins.core.notifications.violations.NewViolationsOnFirstDifferentialPeriod; import org.sonar.plugins.core.security.ApplyProjectRolesDecorator; import org.sonar.plugins.core.sensors.BranchCoverageDecorator; import org.sonar.plugins.core.sensors.CheckAlertThresholds; @@ -401,123 +401,125 @@ public final class CorePlugin extends SonarPlugin { @SuppressWarnings("unchecked") public List getExtensions() { return ImmutableList.of( - DefaultResourceTypes.class, - UserManagedMetrics.class, - Periods.class, + DefaultResourceTypes.class, + UserManagedMetrics.class, + Periods.class, - // languages - Java.class, + // languages + Java.class, - // pages - Lcom4Viewer.class, - TestsViewer.class, + // pages + Lcom4Viewer.class, + TestsViewer.class, - // measure filters - ProjectFilter.class, - MyFavouritesFilter.class, + // measure filters + ProjectFilter.class, + MyFavouritesFilter.class, - // widgets - AlertsWidget.class, - CoverageWidget.class, - ItCoverageWidget.class, - CommentsDuplicationsWidget.class, - DescriptionWidget.class, - ComplexityWidget.class, - RulesWidget.class, - SizeWidget.class, - EventsWidget.class, - CustomMeasuresWidget.class, - TimelineWidget.class, - TimeMachineWidget.class, - HotspotMetricWidget.class, - HotspotMostViolatedResourcesWidget.class, - HotspotMostViolatedRulesWidget.class, - MyReviewsWidget.class, - ProjectReviewsWidget.class, - FalsePositiveReviewsWidget.class, - ReviewsPerDeveloperWidget.class, - PlannedReviewsWidget.class, - UnplannedReviewsWidget.class, - ActionPlansWidget.class, - ReviewsMetricsWidget.class, - TreemapWidget.class, - MeasureFilterListWidget.class, - MeasureFilterTreemapWidget.class, - WelcomeWidget.class, + // widgets + AlertsWidget.class, + CoverageWidget.class, + ItCoverageWidget.class, + CommentsDuplicationsWidget.class, + DescriptionWidget.class, + ComplexityWidget.class, + RulesWidget.class, + SizeWidget.class, + EventsWidget.class, + CustomMeasuresWidget.class, + TimelineWidget.class, + TimeMachineWidget.class, + HotspotMetricWidget.class, + HotspotMostViolatedResourcesWidget.class, + HotspotMostViolatedRulesWidget.class, + MyReviewsWidget.class, + ProjectReviewsWidget.class, + FalsePositiveReviewsWidget.class, + ReviewsPerDeveloperWidget.class, + PlannedReviewsWidget.class, + UnplannedReviewsWidget.class, + ActionPlansWidget.class, + ReviewsMetricsWidget.class, + TreemapWidget.class, + MeasureFilterListWidget.class, + MeasureFilterTreemapWidget.class, + WelcomeWidget.class, - // dashboards - ProjectDefaultDashboard.class, - ProjectHotspotDashboard.class, - ProjectReviewsDashboard.class, - ProjectTimeMachineDashboard.class, - GlobalDefaultDashboard.class, + // dashboards + ProjectDefaultDashboard.class, + ProjectHotspotDashboard.class, + ProjectReviewsDashboard.class, + ProjectTimeMachineDashboard.class, + GlobalDefaultDashboard.class, - // chart - XradarChart.class, - DistributionBarChart.class, - DistributionAreaChart.class, + // chart + XradarChart.class, + DistributionBarChart.class, + DistributionAreaChart.class, - // colorizers - JavaColorizerFormat.class, + // colorizers + JavaColorizerFormat.class, - // batch - ProfileSensor.class, - ProfileEventsSensor.class, - ProjectLinksSensor.class, - UnitTestDecorator.class, - VersionEventsSensor.class, - CheckAlertThresholds.class, - GenerateAlertEvents.class, - ViolationsDecorator.class, - WeightedViolationsDecorator.class, - ViolationsDensityDecorator.class, - LineCoverageDecorator.class, - CoverageDecorator.class, - BranchCoverageDecorator.class, - ItLineCoverageDecorator.class, - ItCoverageDecorator.class, - ItBranchCoverageDecorator.class, - OverallLineCoverageDecorator.class, - OverallCoverageDecorator.class, - OverallBranchCoverageDecorator.class, - ApplyProjectRolesDecorator.class, - CommentDensityDecorator.class, - NoSonarFilter.class, - DirectoriesDecorator.class, - FilesDecorator.class, - ReviewNotifications.class, - ReviewWorkflowDecorator.class, - ManualMeasureDecorator.class, - ManualViolationInjector.class, - ViolationSeverityUpdater.class, - IndexProjectPostJob.class, - ReviewsMeasuresDecorator.class, + // batch + ProfileSensor.class, + ProfileEventsSensor.class, + ProjectLinksSensor.class, + UnitTestDecorator.class, + VersionEventsSensor.class, + CheckAlertThresholds.class, + GenerateAlertEvents.class, + ViolationsDecorator.class, + WeightedViolationsDecorator.class, + ViolationsDensityDecorator.class, + LineCoverageDecorator.class, + CoverageDecorator.class, + BranchCoverageDecorator.class, + ItLineCoverageDecorator.class, + ItCoverageDecorator.class, + ItBranchCoverageDecorator.class, + OverallLineCoverageDecorator.class, + OverallCoverageDecorator.class, + OverallBranchCoverageDecorator.class, + ApplyProjectRolesDecorator.class, + CommentDensityDecorator.class, + NoSonarFilter.class, + DirectoriesDecorator.class, + FilesDecorator.class, + ReviewNotifications.class, + ReviewWorkflowDecorator.class, + ManualMeasureDecorator.class, + ManualViolationInjector.class, + ViolationSeverityUpdater.class, + IndexProjectPostJob.class, + ReviewsMeasuresDecorator.class, - // time machine - TendencyDecorator.class, - VariationDecorator.class, - ViolationTrackingDecorator.class, - ViolationPersisterDecorator.class, - NewViolationsDecorator.class, - TimeMachineConfigurationPersister.class, - NewCoverageFileAnalyzer.class, - NewItCoverageFileAnalyzer.class, - NewOverallCoverageFileAnalyzer.class, - NewCoverageAggregator.class, + // time machine + TendencyDecorator.class, + VariationDecorator.class, + ViolationTrackingDecorator.class, + ViolationPersisterDecorator.class, + NewViolationsDecorator.class, + TimeMachineConfigurationPersister.class, + NewCoverageFileAnalyzer.class, + NewItCoverageFileAnalyzer.class, + NewOverallCoverageFileAnalyzer.class, + NewCoverageAggregator.class, - // notifications - // Notify incoming violations on my favourite projects - NewViolationsOnMyFavouriteProject.class, - NotificationDispatcherMetadata.create("NewViolationsOnMyFavouriteProject") - .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true)), - // Notify alerts on my favourite projects - AlertsOnMyFavouriteProject.class, - NotificationDispatcherMetadata.create("AlertsOnMyFavouriteProject") - .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true)), - // Notify reviews changes - ChangesInReviewAssignedToMeOrCreatedByMe.class, - NotificationDispatcherMetadata.create("ChangesInReviewAssignedToMeOrCreatedByMe") - .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true)) - .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true))); + // notifications + // Notify incoming violations on my favourite projects + NewViolationsOnFirstDifferentialPeriod.class, + NotificationDispatcherMetadata.create("NewViolationsOnFirstDifferentialPeriod") + .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true)) + .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true)), + // Notify alerts on my favourite projects + NewAlerts.class, + NotificationDispatcherMetadata.create("NewAlerts") + .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true)) + .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true)), + // Notify reviews changes + ChangesInReviewAssignedToMeOrCreatedByMe.class, + NotificationDispatcherMetadata.create("ChangesInReviewAssignedToMeOrCreatedByMe") + .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true)) + .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true))); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/AlertsOnMyFavouriteProject.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/AlertsOnMyFavouriteProject.java deleted file mode 100644 index ebf874b358c..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/AlertsOnMyFavouriteProject.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.core.notifications.alerts; - -import com.google.common.collect.Multimap; -import org.sonar.api.notifications.Notification; -import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.api.notifications.NotificationManager; -import org.sonar.core.properties.PropertiesDao; - -import java.util.Collection; -import java.util.List; - -/** - * This dispatcher means: "notify me when alerts are raised on projects that I flagged as favourite". - * - * @since 3.5 - */ -public class AlertsOnMyFavouriteProject extends NotificationDispatcher { - - private NotificationManager notificationManager; - private PropertiesDao propertiesDao; - - public AlertsOnMyFavouriteProject(NotificationManager notificationManager, PropertiesDao propertiesDao) { - super("alerts"); - this.notificationManager = notificationManager; - this.propertiesDao = propertiesDao; - } - - @Override - public void dispatch(Notification notification, Context context) { - // "null" is passed as a 2nd argument because this dispatcher is not a per-project dispatcher - Multimap subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, null); - - List userLogins = propertiesDao.findUserIdsForFavouriteResource(Long.parseLong(notification.getFieldValue("projectId"))); - for (String userLogin : userLogins) { - Collection channels = subscribedRecipients.get(userLogin); - for (NotificationChannel channel : channels) { - context.addUser(userLogin, channel); - } - } - } - -} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java new file mode 100644 index 00000000000..2cf210aeb6d --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java @@ -0,0 +1,58 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.notifications.alerts; + +import com.google.common.collect.Multimap; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; +import org.sonar.api.notifications.NotificationDispatcher; +import org.sonar.api.notifications.NotificationManager; + +import java.util.Collection; +import java.util.Map; + +/** + * This dispatcher means: "notify me each new alert event". + * + * @since 3.5 + */ +public class NewAlerts extends NotificationDispatcher { + + private NotificationManager notificationManager; + + public NewAlerts(NotificationManager notificationManager) { + super("alerts"); + this.notificationManager = notificationManager; + } + + @Override + public void dispatch(Notification notification, Context context) { + int projectId = Integer.parseInt(notification.getFieldValue("projectId")); + Multimap subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, projectId); + + for (Map.Entry> channelsByRecipients : subscribedRecipients.asMap().entrySet()) { + String userLogin = channelsByRecipients.getKey(); + for (NotificationChannel channel : channelsByRecipients.getValue()) { + context.addUser(userLogin, channel); + } + } + } + +} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnFirstDifferentialPeriod.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnFirstDifferentialPeriod.java new file mode 100644 index 00000000000..78f979703b9 --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnFirstDifferentialPeriod.java @@ -0,0 +1,58 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.notifications.violations; + +import com.google.common.collect.Multimap; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; +import org.sonar.api.notifications.NotificationDispatcher; +import org.sonar.api.notifications.NotificationManager; + +import java.util.Collection; +import java.util.Map; + +/** + * This dispatcher means: "notify me when new violations are introduced during the first differential period". + * + * @since 2.14 + */ +public class NewViolationsOnFirstDifferentialPeriod extends NotificationDispatcher { + + private NotificationManager notificationManager; + + public NewViolationsOnFirstDifferentialPeriod(NotificationManager notificationManager) { + super("new-violations"); + this.notificationManager = notificationManager; + } + + @Override + public void dispatch(Notification notification, Context context) { + int projectId = Integer.parseInt(notification.getFieldValue("projectId")); + Multimap subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, projectId); + + for (Map.Entry> channelsByRecipients : subscribedRecipients.asMap().entrySet()) { + String userLogin = channelsByRecipients.getKey(); + for (NotificationChannel channel : channelsByRecipients.getValue()) { + context.addUser(userLogin, channel); + } + } + } + +} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnMyFavouriteProject.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnMyFavouriteProject.java deleted file mode 100644 index 4220db3716c..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnMyFavouriteProject.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.core.notifications.violations; - -import com.google.common.collect.Multimap; -import org.sonar.api.notifications.Notification; -import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.api.notifications.NotificationManager; -import org.sonar.core.properties.PropertiesDao; - -import java.util.Collection; -import java.util.List; - -/** - * This dispatcher means: "notify me when new violations are introduced on projects that I flagged as favourite". - * - * @since 2.14 - */ -public class NewViolationsOnMyFavouriteProject extends NotificationDispatcher { - - private NotificationManager notificationManager; - private PropertiesDao propertiesDao; - - public NewViolationsOnMyFavouriteProject(NotificationManager notificationManager, PropertiesDao propertiesDao) { - super("new-violations"); - this.notificationManager = notificationManager; - this.propertiesDao = propertiesDao; - } - - @Override - public void dispatch(Notification notification, Context context) { - // "null" is passed as a 2nd argument because this dispatcher is not a per-project dispatcher - Multimap subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, null); - - List userLogins = propertiesDao.findUserIdsForFavouriteResource(Long.parseLong(notification.getFieldValue("projectId"))); - for (String userLogin : userLogins) { - Collection channels = subscribedRecipients.get(userLogin); - for (NotificationChannel channel : channels) { - context.addUser(userLogin, channel); - } - } - } - -} diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 15885bd4f62..85546ebccd8 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -1521,8 +1521,8 @@ server_id_configuration.does_not_match_organisation_pattern=Organisation does no #------------------------------------------------------------------------------ notification.channel.EmailNotificationChannel=Email notification.dispatcher.ChangesInReviewAssignedToMeOrCreatedByMe=Changes in review assigned to me or created by me -notification.dispatcher.NewViolationsOnMyFavouriteProject=New violations on my favourite projects introduced during the first differential view period -notification.dispatcher.AlertsOnMyFavouriteProject=Alert events on my favourite projects +notification.dispatcher.NewViolationsOnFirstDifferentialPeriod=New violations introduced during the first differential period +notification.dispatcher.NewAlerts=New alerts #------------------------------------------------------------------------------ diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/AlertsOnMyFavouriteProjectTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/AlertsOnMyFavouriteProjectTest.java deleted file mode 100644 index 16e865dbf46..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/AlertsOnMyFavouriteProjectTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.core.notifications.alerts; - -import org.sonar.plugins.core.notifications.alerts.AlertsOnMyFavouriteProject; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.sonar.api.notifications.Notification; -import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.api.notifications.NotificationManager; -import org.sonar.core.properties.PropertiesDao; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class AlertsOnMyFavouriteProjectTest { - - @Mock - private NotificationManager notificationManager; - - @Mock - private PropertiesDao propertiesDao; - - @Mock - private NotificationDispatcher.Context context; - - @Mock - private NotificationChannel emailChannel; - - @Mock - private NotificationChannel twitterChannel; - - private AlertsOnMyFavouriteProject dispatcher; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - dispatcher = new AlertsOnMyFavouriteProject(notificationManager, propertiesDao); - } - - @Test - public void shouldNotDispatchIfNotAlertsNotification() throws Exception { - Notification notification = new Notification("other-notif"); - dispatcher.performDispatch(notification, context); - - verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); - } - - @Test - public void shouldDispatchToUsersWhoHaveSubscribedAndFlaggedProjectAsFavourite() { - Multimap recipients = HashMultimap.create(); - recipients.put("user1", emailChannel); - recipients.put("user2", twitterChannel); - when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, null)).thenReturn(recipients); - when(propertiesDao.findUserIdsForFavouriteResource(34L)).thenReturn(Lists.newArrayList("user2", "user3")); - - Notification notification = new Notification("alerts").setFieldValue("projectId", "34"); - dispatcher.performDispatch(notification, context); - - verify(context).addUser("user2", twitterChannel); - verifyNoMoreInteractions(context); - } - -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java new file mode 100644 index 00000000000..c0d124e35c5 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java @@ -0,0 +1,84 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.notifications.alerts; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; +import org.sonar.api.notifications.NotificationDispatcher; +import org.sonar.api.notifications.NotificationManager; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +public class NewAlertsTest { + + @Mock + private NotificationManager notificationManager; + + @Mock + private NotificationDispatcher.Context context; + + @Mock + private NotificationChannel emailChannel; + + @Mock + private NotificationChannel twitterChannel; + + private NewAlerts dispatcher; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + dispatcher = new NewAlerts(notificationManager); + } + + @Test + public void shouldNotDispatchIfNotAlertsNotification() throws Exception { + Notification notification = new Notification("other-notif"); + dispatcher.performDispatch(notification, context); + + verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); + } + + @Test + public void shouldDispatchToUsersWhoHaveSubscribedAndFlaggedProjectAsFavourite() { + Multimap recipients = HashMultimap.create(); + recipients.put("user1", emailChannel); + recipients.put("user2", twitterChannel); + when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, 34)).thenReturn(recipients); + + Notification notification = new Notification("alerts").setFieldValue("projectId", "34"); + dispatcher.performDispatch(notification, context); + + verify(context).addUser("user1", emailChannel); + verify(context).addUser("user2", twitterChannel); + verifyNoMoreInteractions(context); + } + +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnFirstDifferentialPeriodTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnFirstDifferentialPeriodTest.java new file mode 100644 index 00000000000..c58adbf39e7 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnFirstDifferentialPeriodTest.java @@ -0,0 +1,84 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.notifications.violations; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; +import org.sonar.api.notifications.NotificationDispatcher; +import org.sonar.api.notifications.NotificationManager; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +public class NewViolationsOnFirstDifferentialPeriodTest { + + @Mock + private NotificationManager notificationManager; + + @Mock + private NotificationDispatcher.Context context; + + @Mock + private NotificationChannel emailChannel; + + @Mock + private NotificationChannel twitterChannel; + + private NewViolationsOnFirstDifferentialPeriod dispatcher; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + dispatcher = new NewViolationsOnFirstDifferentialPeriod(notificationManager); + } + + @Test + public void shouldNotDispatchIfNotNewViolationsNotification() throws Exception { + Notification notification = new Notification("other-notif"); + dispatcher.performDispatch(notification, context); + + verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); + } + + @Test + public void shouldDispatchToUsersWhoHaveSubscribedAndFlaggedProjectAsFavourite() { + Multimap recipients = HashMultimap.create(); + recipients.put("user1", emailChannel); + recipients.put("user2", twitterChannel); + when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, 34)).thenReturn(recipients); + + Notification notification = new Notification("new-violations").setFieldValue("projectId", "34"); + dispatcher.performDispatch(notification, context); + + verify(context).addUser("user1", emailChannel); + verify(context).addUser("user2", twitterChannel); + verifyNoMoreInteractions(context); + } + +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnMyFavouriteProjectTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnMyFavouriteProjectTest.java deleted file mode 100644 index 47130b2b977..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/violations/NewViolationsOnMyFavouriteProjectTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.core.notifications.violations; - -import org.sonar.plugins.core.notifications.violations.NewViolationsOnMyFavouriteProject; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.sonar.api.notifications.Notification; -import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.api.notifications.NotificationManager; -import org.sonar.core.properties.PropertiesDao; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class NewViolationsOnMyFavouriteProjectTest { - - @Mock - private NotificationManager notificationManager; - - @Mock - private PropertiesDao propertiesDao; - - @Mock - private NotificationDispatcher.Context context; - - @Mock - private NotificationChannel emailChannel; - - @Mock - private NotificationChannel twitterChannel; - - private NewViolationsOnMyFavouriteProject dispatcher; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - dispatcher = new NewViolationsOnMyFavouriteProject(notificationManager, propertiesDao); - } - - @Test - public void shouldNotDispatchIfNotNewViolationsNotification() throws Exception { - Notification notification = new Notification("other-notif"); - dispatcher.performDispatch(notification, context); - - verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); - } - - @Test - public void shouldDispatchToUsersWhoHaveSubscribedAndFlaggedProjectAsFavourite() { - Multimap recipients = HashMultimap.create(); - recipients.put("user1", emailChannel); - recipients.put("user2", twitterChannel); - when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, null)).thenReturn(recipients); - when(propertiesDao.findUserIdsForFavouriteResource(34L)).thenReturn(Lists.newArrayList("user2", "user3")); - - Notification notification = new Notification("new-violations").setFieldValue("projectId", "34"); - dispatcher.performDispatch(notification, context); - - verify(context).addUser("user2", twitterChannel); - verifyNoMoreInteractions(context); - } - -}