aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-email-notifications-plugin
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-28 14:15:45 +0100
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-29 18:01:15 +0100
commit4fa03eea720ef2067bb2f920edd6c3f8f0080b85 (patch)
tree9a7080a1777ec7f4751263ce7bc0e78938d8f9b8 /plugins/sonar-email-notifications-plugin
parentc964f2ea5fc57d72d19d7f2bfbedf9fe62c7c33c (diff)
downloadsonarqube-4fa03eea720ef2067bb2f920edd6c3f8f0080b85.tar.gz
sonarqube-4fa03eea720ef2067bb2f920edd6c3f8f0080b85.zip
SONAR-3959 Add notification type on NotificationDispatcher
Diffstat (limited to 'plugins/sonar-email-notifications-plugin')
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProject.java12
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProject.java16
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java30
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java4
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java17
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java18
6 files changed, 47 insertions, 50 deletions
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProject.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProject.java
index 38a46a6ca49..5b073afdd79 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProject.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProject.java
@@ -19,7 +19,6 @@
*/
package org.sonar.plugins.emailnotifications.alerts;
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationDispatcher;
import org.sonar.core.properties.PropertiesDao;
@@ -36,17 +35,16 @@ public class AlertsOnMyFavouriteProject extends NotificationDispatcher {
private PropertiesDao propertiesDao;
public AlertsOnMyFavouriteProject(PropertiesDao propertiesDao) {
+ super("alerts");
this.propertiesDao = propertiesDao;
}
@Override
public void dispatch(Notification notification, Context context) {
- if (StringUtils.equals(notification.getType(), "alerts")) {
- Long projectId = Long.parseLong(notification.getFieldValue("projectId"));
- List<String> userLogins = propertiesDao.findUserIdsForFavouriteResource(projectId);
- for (String userLogin : userLogins) {
- context.addUser(userLogin);
- }
+ Long projectId = Long.parseLong(notification.getFieldValue("projectId"));
+ List<String> userLogins = propertiesDao.findUserIdsForFavouriteResource(projectId);
+ for (String userLogin : userLogins) {
+ context.addUser(userLogin);
}
}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProject.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProject.java
index d0db106f056..cb101e4a023 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProject.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProject.java
@@ -19,13 +19,12 @@
*/
package org.sonar.plugins.emailnotifications.newviolations;
-import java.util.List;
-
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationDispatcher;
import org.sonar.core.properties.PropertiesDao;
+import java.util.List;
+
/**
* This dispatcher means: "notify me when new violations are introduced on projects that I flagged as favourite".
*
@@ -36,17 +35,16 @@ public class NewViolationsOnMyFavouriteProject extends NotificationDispatcher {
private PropertiesDao propertiesDao;
public NewViolationsOnMyFavouriteProject(PropertiesDao propertiesDao) {
+ super("new-violations");
this.propertiesDao = propertiesDao;
}
@Override
public void dispatch(Notification notification, Context context) {
- if (StringUtils.equals(notification.getType(), "new-violations")) {
- Long projectId = Long.parseLong(notification.getFieldValue("projectId"));
- List<String> userLogins = propertiesDao.findUserIdsForFavouriteResource(projectId);
- for (String userLogin : userLogins) {
- context.addUser(userLogin);
- }
+ Long projectId = Long.parseLong(notification.getFieldValue("projectId"));
+ List<String> userLogins = propertiesDao.findUserIdsForFavouriteResource(projectId);
+ for (String userLogin : userLogins) {
+ context.addUser(userLogin);
}
}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java
index 047b6269d1c..582c21d7367 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java
@@ -30,22 +30,24 @@ import org.sonar.api.notifications.NotificationDispatcher;
*/
public class ChangesInReviewAssignedToMeOrCreatedByMe extends NotificationDispatcher {
+ public ChangesInReviewAssignedToMeOrCreatedByMe() {
+ super("review-changed");
+ }
+
@Override
public void dispatch(Notification notification, Context context) {
- if (StringUtils.startsWith(notification.getType(), "review")) {
- String author = notification.getFieldValue("author"); // author of change
- String creator = notification.getFieldValue("creator"); // creator of review
- String oldAssignee = notification.getFieldValue("old.assignee"); // previous assignee
- String assignee = notification.getFieldValue("assignee"); // current assignee
- if (creator != null && !StringUtils.equals(author, creator)) {
- context.addUser(creator);
- }
- if (oldAssignee != null && !StringUtils.equals(author, oldAssignee)) {
- context.addUser(oldAssignee);
- }
- if (assignee != null && !StringUtils.equals(author, assignee)) {
- context.addUser(assignee);
- }
+ String author = notification.getFieldValue("author");
+ String creator = notification.getFieldValue("creator");
+ String oldAssignee = notification.getFieldValue("old.assignee");
+ String assignee = notification.getFieldValue("assignee");
+ if (creator != null && !StringUtils.equals(author, creator)) {
+ context.addUser(creator);
+ }
+ if (oldAssignee != null && !StringUtils.equals(author, oldAssignee)) {
+ context.addUser(oldAssignee);
+ }
+ if (assignee != null && !StringUtils.equals(author, assignee)) {
+ context.addUser(assignee);
}
}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java
index fe29748d332..7bf49f0c2ad 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java
@@ -39,7 +39,7 @@ public class AlertsOnMyFavouriteProjectTest {
NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
AlertsOnMyFavouriteProject dispatcher = new AlertsOnMyFavouriteProject(null);
Notification notification = new Notification("other-notif");
- dispatcher.dispatch(notification, context);
+ dispatcher.performDispatch(notification, context);
verify(context, never()).addUser(any(String.class));
}
@@ -52,7 +52,7 @@ public class AlertsOnMyFavouriteProjectTest {
AlertsOnMyFavouriteProject dispatcher = new AlertsOnMyFavouriteProject(propertiesDao);
Notification notification = new Notification("alerts").setFieldValue("projectId", "34");
- dispatcher.dispatch(notification, context);
+ dispatcher.performDispatch(notification, context);
verify(context).addUser("user1");
verify(context).addUser("user2");
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java
index 5a4b1adce3a..4e8e66e002e 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java
@@ -19,6 +19,12 @@
*/
package org.sonar.plugins.emailnotifications.newviolations;
+import com.google.common.collect.Lists;
+import org.junit.Test;
+import org.sonar.api.notifications.Notification;
+import org.sonar.api.notifications.NotificationDispatcher;
+import org.sonar.core.properties.PropertiesDao;
+
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -26,13 +32,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import org.junit.Test;
-import org.sonar.api.notifications.Notification;
-import org.sonar.api.notifications.NotificationDispatcher;
-import org.sonar.core.properties.PropertiesDao;
-
-import com.google.common.collect.Lists;
-
public class NewViolationsOnMyFavouriteProjectTest {
@Test
@@ -40,7 +39,7 @@ public class NewViolationsOnMyFavouriteProjectTest {
NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
NewViolationsOnMyFavouriteProject dispatcher = new NewViolationsOnMyFavouriteProject(null);
Notification notification = new Notification("other-notif");
- dispatcher.dispatch(notification, context);
+ dispatcher.performDispatch(notification, context);
verify(context, never()).addUser(any(String.class));
}
@@ -53,7 +52,7 @@ public class NewViolationsOnMyFavouriteProjectTest {
NewViolationsOnMyFavouriteProject dispatcher = new NewViolationsOnMyFavouriteProject(propertiesDao);
Notification notification = new Notification("new-violations").setFieldValue("projectId", "34");
- dispatcher.dispatch(notification, context);
+ dispatcher.performDispatch(notification, context);
verify(context).addUser("user1");
verify(context).addUser("user2");
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
index a2e2f215771..b0f89604bc4 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
@@ -19,15 +19,15 @@
*/
package org.sonar.plugins.emailnotifications.reviews;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationDispatcher;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
public class ChangesInReviewAssignedToMeOrCreatedByMeTest {
private NotificationDispatcher.Context context;
@@ -46,7 +46,7 @@ public class ChangesInReviewAssignedToMeOrCreatedByMeTest {
.setFieldValue("creator", "simon")
.setFieldValue("old.assignee", "godin")
.setFieldValue("assignee", "freddy");
- dispatcher.dispatch(notification, context);
+ dispatcher.performDispatch(notification, context);
verify(context).addUser("simon");
verify(context).addUser("godin");
@@ -56,9 +56,9 @@ public class ChangesInReviewAssignedToMeOrCreatedByMeTest {
@Test
public void doNotDispatchToAuthorOfChanges() {
- dispatcher.dispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("creator", "simon"), context);
- dispatcher.dispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("assignee", "simon"), context);
- dispatcher.dispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("old.assignee", "simon"), context);
+ dispatcher.performDispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("creator", "simon"), context);
+ dispatcher.performDispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("assignee", "simon"), context);
+ dispatcher.performDispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("old.assignee", "simon"), context);
verifyNoMoreInteractions(context);
}
@@ -66,7 +66,7 @@ public class ChangesInReviewAssignedToMeOrCreatedByMeTest {
@Test
public void shouldNotDispatch() {
Notification notification = new Notification("other");
- dispatcher.dispatch(notification, context);
+ dispatcher.performDispatch(notification, context);
verifyNoMoreInteractions(context);
}