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;
@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)));
}
}
+++ /dev/null
-/*
- * 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<String, NotificationChannel> subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, null);
-
- List<String> userLogins = propertiesDao.findUserIdsForFavouriteResource(Long.parseLong(notification.getFieldValue("projectId")));
- for (String userLogin : userLogins) {
- Collection<NotificationChannel> channels = subscribedRecipients.get(userLogin);
- for (NotificationChannel channel : channels) {
- context.addUser(userLogin, channel);
- }
- }
- }
-
-}
--- /dev/null
+/*
+ * 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<String, NotificationChannel> subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, projectId);
+
+ for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
+ String userLogin = channelsByRecipients.getKey();
+ for (NotificationChannel channel : channelsByRecipients.getValue()) {
+ context.addUser(userLogin, channel);
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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<String, NotificationChannel> subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, projectId);
+
+ for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
+ String userLogin = channelsByRecipients.getKey();
+ for (NotificationChannel channel : channelsByRecipients.getValue()) {
+ context.addUser(userLogin, channel);
+ }
+ }
+ }
+
+}
+++ /dev/null
-/*
- * 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<String, NotificationChannel> subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, null);
-
- List<String> userLogins = propertiesDao.findUserIdsForFavouriteResource(Long.parseLong(notification.getFieldValue("projectId")));
- for (String userLogin : userLogins) {
- Collection<NotificationChannel> channels = subscribedRecipients.get(userLogin);
- for (NotificationChannel channel : channels) {
- context.addUser(userLogin, channel);
- }
- }
- }
-
-}
#------------------------------------------------------------------------------
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
#------------------------------------------------------------------------------
+++ /dev/null
-/*
- * 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<String, NotificationChannel> 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);
- }
-
-}
--- /dev/null
+/*
+ * 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<String, NotificationChannel> 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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<String, NotificationChannel> 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);
+ }
+
+}
+++ /dev/null
-/*
- * 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<String, NotificationChannel> 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);
- }
-
-}