]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4824 support branches when filtering recipients on their perms 2618/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 3 Oct 2017 15:41:32 +0000 (17:41 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 4 Oct 2017 09:39:06 +0000 (11:39 +0200)
by querying permissions in DB with component key rather than component uuid
as computing the target branch's key from the branch's key is easy

34 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
server/sonar-server/src/main/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcher.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java
server/sonar-server/src/main/java/org/sonar/server/event/NewAlerts.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java
server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java
server/sonar-server/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/event/NewAlertsTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java

index 56ff394b3eb06bdef0080431cc7942e95f404ecb..9e8538b5217c7955c0e5b93e846276d410b75386 100644 (file)
@@ -177,10 +177,10 @@ public class AuthorizationDao implements Dao {
     return mapper(dbSession).selectLoginsWithGlobalPermission(ADMINISTER.getKey());
   }
 
-  public Set<String> keepAuthorizedLoginsOnProject(DbSession dbSession, Set<String> logins, String projectUuid, String permission) {
+  public Set<String> keepAuthorizedLoginsOnProject(DbSession dbSession, Set<String> logins, String projectKey, String permission) {
     return executeLargeInputsIntoSet(
       logins,
-      partitionOfLogins -> mapper(dbSession).keepAuthorizedLoginsOnProject(partitionOfLogins, projectUuid, permission),
+      partitionOfLogins -> mapper(dbSession).keepAuthorizedLoginsOnProject(partitionOfLogins, projectKey, permission),
       partitionSize -> partitionSize / 3);
   }
 
index 1c788ea1019947cf6cbead8ed5bf63b4c2bead54..3a7043bfb13362729b65c643451e6283f290a3f9 100644 (file)
@@ -63,7 +63,7 @@ public interface AuthorizationMapper {
 
   List<String> selectQualityProfileAdministratorLogins(@Param("permission") String permission);
 
-  Set<String> keepAuthorizedLoginsOnProject(@Param("logins") List<String> logins, @Param("projectUuid") String projectUuid, @Param("permission") String permission);
+  Set<String> keepAuthorizedLoginsOnProject(@Param("logins") List<String> logins, @Param("projectKey") String projectKey, @Param("permission") String permission);
 
   List<String> selectLoginsWithGlobalPermission(@Param("permission") String permission);
 }
index db9f924d2f2dd272722bd3da94d0eb691d35eeb8..46b1d3b4a7c7dcbcdd91db8b1b77e10fc3334b30 100644 (file)
@@ -66,9 +66,9 @@ public class PropertiesDao implements Dao {
    *
    * @return the list of Subscriber (maybe be empty - obviously)
    */
-  public Set<Subscriber> findUsersForNotification(String notificationDispatcherKey, String notificationChannelKey, @Nullable String projectUuid) {
+  public Set<Subscriber> findUsersForNotification(String notificationDispatcherKey, String notificationChannelKey, @Nullable String projectKey) {
     try (DbSession session = mybatis.openSession(false)) {
-      return getMapper(session).findUsersForNotification(NOTIFICATION_PREFIX + notificationDispatcherKey + "." + notificationChannelKey, projectUuid);
+      return getMapper(session).findUsersForNotification(NOTIFICATION_PREFIX + notificationDispatcherKey + "." + notificationChannelKey, projectKey);
     }
   }
 
index 2d9c75df052f24bda3f00bc9c3fa48e2a776629e..4472156d45005ad2086642bb6b452f4099b95c90 100644 (file)
@@ -26,7 +26,7 @@ import org.apache.ibatis.annotations.Param;
 
 public interface PropertiesMapper {
 
-  Set<Subscriber> findUsersForNotification(@Param("notifKey") String notificationKey, @Nullable @Param("projectUuid") String projectUuid);
+  Set<Subscriber> findUsersForNotification(@Param("notifKey") String notificationKey, @Nullable @Param("projectKey") String projectKey);
 
   List<PropertyDto> selectGlobalProperties();
 
index b43ede52e6932423d0e0ee86ae840685571ac856..60f105b4ede4b6176d5df5d6cf3ff7cb790621c1 100644 (file)
       SELECT u.login
       FROM users u
       INNER JOIN user_roles ur ON ur.user_id = u.id
-      INNER JOIN projects p ON p.uuid = #{projectUuid,jdbcType=VARCHAR}
+      INNER JOIN projects p ON p.kee = #{projectKey,jdbcType=VARCHAR}
       WHERE
         ur.organization_uuid = p.organization_uuid
         AND ur.resource_id = p.id
 
       SELECT u.login
       FROM users u
-      INNER JOIN projects p ON p.uuid = #{projectUuid,jdbcType=VARCHAR}
+      INNER JOIN projects p ON p.kee = #{projectKey,jdbcType=VARCHAR}
       INNER JOIN group_roles gr ON gr.organization_uuid = p.organization_uuid
       INNER JOIN groups_users gu ON gr.group_id = gu.group_id
       WHERE
 
       SELECT u.login
       FROM users u
-      INNER JOIN projects p ON p.uuid = #{projectUuid,jdbcType=VARCHAR}
+      INNER JOIN projects p ON p.kee = #{projectKey,jdbcType=VARCHAR}
       WHERE
         p.private = ${_false}
         AND u.login IN <foreach collection="logins" open="(" close=")" item="login" separator=",">#{login}</foreach>
index b41fa68b0b45a08c2ac6c86d17fe1512f0eaa178..f5571ebe90f87c6e1492047d3540fc37496817bd 100644 (file)
@@ -22,7 +22,7 @@
       ${_false} as "global"
     FROM
       users u
-    INNER JOIN projects c on c.uuid = #{projectUuid,jdbcType=VARCHAR}
+    INNER JOIN projects c on c.kee = #{projectKey,jdbcType=VARCHAR}
     INNER JOIN properties p ON p.user_id = u.id
     WHERE
       p.prop_key = #{notifKey,jdbcType=VARCHAR}
index 693266f67228d7cf892b47bccdf24567fbad72b7..951f8011a034d9424446e45218a04d8e82d08cc4 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.core.permission.ProjectPermissions;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.user.GroupDto;
@@ -61,6 +62,7 @@ public class AuthorizationDaoTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
+  private final Random random = new Random();
   private DbSession dbSession = db.getSession();
   private AuthorizationDao underTest = new AuthorizationDao();
   private OrganizationDto organization;
@@ -70,7 +72,7 @@ public class AuthorizationDaoTest {
   private Set<Long> randomPublicProjectIds;
   private Set<Long> randomPrivateProjectIds;
   private Set<Integer> randomExistingUserIds;
-  private String randomPermission = "p" + new Random().nextInt();
+  private String randomPermission = "p" + random.nextInt();
 
   @Before
   public void setUp() throws Exception {
@@ -78,15 +80,15 @@ public class AuthorizationDaoTest {
     user = db.users().insertUser();
     group1 = db.users().insertGroup(organization, "group1");
     group2 = db.users().insertGroup(organization, "group2");
-    randomExistingUserIds = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5)))
+    randomExistingUserIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
       .map(i -> db.users().insertUser().getId())
       .boxed()
       .collect(MoreCollectors.toSet());
-    randomPublicProjectIds = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5)))
+    randomPublicProjectIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
       .mapToLong(i -> db.components().insertPublicProject(organization).getId())
       .boxed()
       .collect(MoreCollectors.toSet());
-    randomPrivateProjectIds = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5)))
+    randomPrivateProjectIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
       .mapToLong(i -> db.components().insertPrivateProject(organization).getId())
       .boxed()
       .collect(MoreCollectors.toSet());
@@ -239,7 +241,7 @@ public class AuthorizationDaoTest {
 
   @Test
   public void keepAuthorizedProjectIds_returns_empty_for_group_AnyOne_for_non_existent_projects() {
-    Set<Long> randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5)))
+    Set<Long> randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
       .mapToLong(i -> 3_562 + i)
       .boxed()
       .collect(MoreCollectors.toSet());
@@ -250,7 +252,7 @@ public class AuthorizationDaoTest {
 
   @Test
   public void keepAuthorizedProjectIds_returns_empty_for_user_for_non_existent_projects() {
-    Set<Long> randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5)))
+    Set<Long> randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
       .mapToLong(i -> 9_666 + i)
       .boxed()
       .collect(MoreCollectors.toSet());
@@ -513,8 +515,8 @@ public class AuthorizationDaoTest {
 
   @Test
   public void keepAuthorizedUsersForRoleAndProject_returns_empty_for_non_existent_users() {
-    ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject(organization) : db.components().insertPrivateProject(organization);
-    Set<Integer> randomNonExistingUserIdsSet = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5)))
+    ComponentDto project = random.nextBoolean() ? db.components().insertPublicProject(organization) : db.components().insertPrivateProject(organization);
+    Set<Integer> randomNonExistingUserIdsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
       .map(i -> i + 1_990)
       .boxed()
       .collect(MoreCollectors.toSet());
@@ -1044,11 +1046,11 @@ public class AuthorizationDaoTest {
     db.users().insertMember(adminGroup, admin2);
     db.users().insertProjectPermissionOnGroup(adminGroup, UserRole.ADMIN, project);
 
-    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), project.uuid(), UserRole.USER))
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), project.getKey(), UserRole.USER))
       .containsOnly(user1.getLogin());
-    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin(), admin1.getLogin(), admin2.getLogin()), project.uuid(), UserRole.USER))
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin(), admin1.getLogin(), admin2.getLogin()), project.getKey(), UserRole.USER))
       .containsOnly(user1.getLogin(), admin1.getLogin(), admin2.getLogin());
-    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin(), admin1.getLogin(), admin2.getLogin()), project.uuid(), UserRole.ADMIN))
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin(), admin1.getLogin(), admin2.getLogin()), project.getKey(), UserRole.ADMIN))
       .containsOnly(admin1.getLogin(), admin2.getLogin());
   }
 
@@ -1080,17 +1082,60 @@ public class AuthorizationDaoTest {
     // user without role
     UserDto userWithNoRole = db.users().insertUser();
 
-    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(userWithNoRole.getLogin()), project.uuid(), UserRole.USER))
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(userWithNoRole.getLogin()), project.getKey(), UserRole.USER))
       .isEmpty();
-    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), project.uuid(), UserRole.USER))
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), project.getKey(), UserRole.USER))
       .containsOnly(user1.getLogin());
 
     Set<String> allLogins = newHashSet(admin1.getLogin(), admin2.getLogin(), user1.getLogin(), user2.getLogin(), userWithNoRole.getLogin());
 
     // Admin does not have the USER permission set
-    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, project.uuid(), UserRole.USER))
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, project.getKey(), UserRole.USER))
       .containsOnly(user1.getLogin(), user2.getLogin());
-    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, project.uuid(), UserRole.ADMIN))
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, project.getKey(), UserRole.ADMIN))
+      .containsOnly(admin1.getLogin(), admin2.getLogin());
+  }
+
+  @Test
+  public void keepAuthorizedLoginsOnProject_return_correct_users_on_branch() {
+    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto branch = db.components().insertProjectBranch(project, c -> c.setBranchType(random.nextBoolean() ? BranchType.SHORT : BranchType.LONG));
+
+    GroupDto userGroup = db.users().insertGroup(organization, "USERS");
+    GroupDto adminGroup = db.users().insertGroup(organization, "ADMIN");
+    db.users().insertProjectPermissionOnGroup(userGroup, UserRole.USER, project);
+    db.users().insertProjectPermissionOnGroup(adminGroup, UserRole.ADMIN, project);
+
+    // admin with "direct" ADMIN role
+    UserDto admin1 = db.users().insertUser();
+    db.users().insertProjectPermissionOnUser(admin1, UserRole.ADMIN, project);
+
+    // admin2 with ADMIN role through group
+    UserDto admin2 = db.users().insertUser();
+    db.users().insertMember(adminGroup, admin2);
+
+    // user1 with "direct" USER role
+    UserDto user1 = db.users().insertUser();
+    db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project);
+
+    // user2 with USER role through group
+    UserDto user2 = db.users().insertUser();
+    db.users().insertMember(userGroup, user2);
+
+    // user without role
+    UserDto userWithNoRole = db.users().insertUser();
+
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(userWithNoRole.getLogin()), branch.getKey(), UserRole.USER))
+      .isEmpty();
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), branch.getKey(), UserRole.USER))
+      .containsOnly(user1.getLogin());
+
+    Set<String> allLogins = newHashSet(admin1.getLogin(), admin2.getLogin(), user1.getLogin(), user2.getLogin(), userWithNoRole.getLogin());
+
+    // Admin does not have the USER permission set
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, branch.getKey(), UserRole.USER))
+      .containsOnly(user1.getLogin(), user2.getLogin());
+    assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, branch.getKey(), UserRole.ADMIN))
       .containsOnly(admin1.getLogin(), admin2.getLogin());
   }
 }
index 1379ac1caf934e3aa706018eed5cc4e86b8c1cf5..c066f2caa83be2a914f65863aa4e217fbec50514 100644 (file)
@@ -101,10 +101,10 @@ public class PropertiesDaoTest {
     assertThat(underTest.findUsersForNotification("NewViolations", "Email", "uuid_78"))
       .isEmpty();
 
-    assertThat(underTest.findUsersForNotification("NewViolations", "Email", project1.uuid()))
+    assertThat(underTest.findUsersForNotification("NewViolations", "Email", project1.getKey()))
       .containsOnly(new Subscriber("user2", false));
 
-    assertThat(underTest.findUsersForNotification("NewViolations", "Email", project2.uuid()))
+    assertThat(underTest.findUsersForNotification("NewViolations", "Email", project2.getKey()))
       .isEmpty();
 
     assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", null))
@@ -113,10 +113,10 @@ public class PropertiesDaoTest {
     assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", "uuid_78"))
       .containsOnly(new Subscriber("user3", true));
 
-    assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", project1.uuid()))
+    assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", project1.getKey()))
       .containsOnly(new Subscriber("user2", false), new Subscriber("user3", true));
 
-    assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", project2.uuid()))
+    assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", project2.getKey()))
       .containsOnly(new Subscriber("user1", false), new Subscriber("user3", true), new Subscriber("user3", false));
   }
 
index ff3ad8346c2f06c076b4c865fcb98cad249d93ed..80ad8c0562543e2cae4aa68bad3f087dc3b85533 100644 (file)
@@ -55,9 +55,9 @@ public class ReportAnalysisFailureNotificationDispatcher extends NotificationDis
 
   @Override
   public void dispatch(Notification notification, Context context) {
-    String projectUuid = notification.getFieldValue("project.uuid");
-    Multimap<String, NotificationChannel> subscribedRecipients = manager.findSubscribedRecipientsForDispatcher(
-      this, projectUuid, REQUIRED_SUBSCRIBER_PERMISSIONS);
+    String projectKey = notification.getFieldValue("project.key");
+    Multimap<String, NotificationChannel> subscribedRecipients = manager
+      .findSubscribedRecipientsForDispatcher(this, projectKey, REQUIRED_SUBSCRIBER_PERMISSIONS);
 
     for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
       String userLogin = channelsByRecipients.getKey();
index 0718f982640253bc27c497ba315c9098bdb555ae..47476580719d74d3c7c27683bc270058adbc508d 100644 (file)
@@ -127,7 +127,6 @@ public class QualityGateEventsStep implements ComputationStep {
       .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label))
       .setFieldValue("projectName", project.getName())
       .setFieldValue("projectKey", project.getPublicKey())
-      .setFieldValue("projectUuid", project.getUuid())
       .setFieldValue("projectVersion", project.getReportAttributes().getVersion())
       .setFieldValue("alertName", label)
       .setFieldValue("alertText", rawStatus.getText())
index c145b30d61b4fd7845ba8c012c0ea91b2337137e..b54344cc019ff6a5121ede34ee021873cf5da36e 100644 (file)
@@ -127,7 +127,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
     IssueChangeNotification changeNotification = new IssueChangeNotification();
     changeNotification.setRuleName(rules.getByKey(issue.ruleKey()).getName());
     changeNotification.setIssue(issue);
-    changeNotification.setProject(project.getPublicKey(), project.getName(), getBranchName(), project.getUuid());
+    changeNotification.setProject(project.getPublicKey(), project.getName(), getBranchName());
     getComponentKey(issue).ifPresent(c -> changeNotification.setComponent(c.getPublicKey(), c.getName()));
     service.deliver(changeNotification);
   }
@@ -136,7 +136,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
     NewIssuesStatistics.Stats globalStatistics = statistics.globalStatistics();
     NewIssuesNotification notification = newIssuesNotificationFactory
       .newNewIssuesNotication()
-      .setProject(project.getPublicKey(), project.getUuid(), project.getName(), getBranchName())
+      .setProject(project.getPublicKey(), project.getName(), getBranchName())
       .setProjectVersion(project.getReportAttributes().getVersion())
       .setAnalysisDate(new Date(analysisDate))
       .setStatistics(project.getName(), globalStatistics)
@@ -155,7 +155,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
           .newMyNewIssuesNotification()
           .setAssignee(assignee);
         myNewIssuesNotification
-          .setProject(project.getPublicKey(), project.getUuid(), project.getName(), getBranchName())
+          .setProject(project.getPublicKey(), project.getName(), getBranchName())
           .setProjectVersion(project.getReportAttributes().getVersion())
           .setAnalysisDate(new Date(analysisDate))
           .setStatistics(project.getName(), assigneeStatistics)
index 87804f12be299f3b98c9c5f9196e2383c3cf5926..f298a824a51a64df77fd70dcb56096b71e348fdd 100644 (file)
@@ -58,10 +58,10 @@ public class NewAlerts extends NotificationDispatcher {
 
   @Override
   public void dispatch(Notification notification, Context context) {
-    String projectUuid = notification.getFieldValue("projectUuid");
-    if (projectUuid != null) {
-      Multimap<String, NotificationChannel> subscribedRecipients = notifications.findSubscribedRecipientsForDispatcher(
-        this, projectUuid, ALL_MUST_HAVE_ROLE_USER);
+    String projectKey = notification.getFieldValue("projectKey");
+    if (projectKey != null) {
+      Multimap<String, NotificationChannel> subscribedRecipients = notifications
+          .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER);
 
       for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
         String userLogin = channelsByRecipients.getKey();
index 7a5eb221ac521a0dc5ae5c1137d56de3101d12cb..48673c575d488c94481ee4bc5acc84edc0e9fa06 100644 (file)
@@ -51,7 +51,6 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate {
   static final String FIELD_PROJECT_NAME = "projectName";
   static final String FIELD_PROJECT_KEY = "projectKey";
   static final String FIELD_PROJECT_DATE = "projectDate";
-  static final String FIELD_PROJECT_UUID = "projectUuid";
   static final String FIELD_PROJECT_VERSION = "projectVersion";
   static final String FIELD_ASSIGNEE = "assignee";
   static final String FIELD_BRANCH = "branch";
index 9f0031d9d816816363c5f241e1cac44aade3f4c9..26375d52a0902da35a9557f9ea1f176039887c52 100644 (file)
@@ -59,9 +59,9 @@ public class ChangesOnMyIssueNotificationDispatcher extends NotificationDispatch
 
   @Override
   public void dispatch(Notification notification, Context context) {
-    String projectUuid = notification.getFieldValue("projectUuid");
-    Multimap<String, NotificationChannel> subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(
-      this, projectUuid, ALL_MUST_HAVE_ROLE_USER);
+    String projectKey = notification.getFieldValue("projectKey");
+    Multimap<String, NotificationChannel> subscribedRecipients = notificationManager
+      .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER);
 
     // See available fields in the class IssueNotifications.
 
index 5c86e435af06fac51231217b65316077e512949c..14bf4f2cc7977454558c13da853e531e13db0ddc 100644 (file)
@@ -62,9 +62,9 @@ public class DoNotFixNotificationDispatcher extends NotificationDispatcher {
     String newResolution = notification.getFieldValue("new.resolution");
     if (Objects.equals(newResolution, Issue.RESOLUTION_FALSE_POSITIVE) || Objects.equals(newResolution, Issue.RESOLUTION_WONT_FIX)) {
       String author = notification.getFieldValue("changeAuthor");
-      String projectUuid = notification.getFieldValue("projectUuid");
-      Multimap<String, NotificationChannel> subscribedRecipients = notifications.findSubscribedRecipientsForDispatcher(
-        this, projectUuid, ALL_MUST_HAVE_ROLE_USER);
+      String projectKey = notification.getFieldValue("projectKey");
+      Multimap<String, NotificationChannel> subscribedRecipients = notifications
+        .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER);
       notify(author, context, subscribedRecipients);
     }
   }
index 58d6b7296c39f76d0bfaaf3cf664962ed6f616f3..f55046116925a76ff7efbe6df642d7a6089c6a8f 100644 (file)
@@ -54,12 +54,11 @@ public class IssueChangeNotification extends Notification {
   }
 
   public IssueChangeNotification setProject(ComponentDto project) {
-    return setProject(project.getKey(), project.name(), project.getBranch(), project.uuid());
+    return setProject(project.getKey(), project.name(), project.getBranch());
   }
 
-  public IssueChangeNotification setProject(String projectKey, String projectName, @Nullable String branch, String projectUuid) {
+  public IssueChangeNotification setProject(String projectKey, String projectName, @Nullable String branch) {
     setFieldValue("projectName", projectName);
-    setFieldValue("projectUuid", projectUuid);
     setFieldValue("projectKey", projectKey);
     if (branch != null) {
       setFieldValue("branch", branch);
index 3b50d87b305ee4c476e03ffc7e0e7b8d31060be8..46ed30b1db845372d2d786479add8539b96dc327 100644 (file)
@@ -55,10 +55,10 @@ public class MyNewIssuesNotificationDispatcher extends NotificationDispatcher {
 
   @Override
   public void dispatch(Notification notification, Context context) {
-    String projectUuid = notification.getFieldValue("projectUuid");
+    String projectKey = notification.getFieldValue("projectKey");
     String assignee = notification.getFieldValue("assignee");
-    Multimap<String, NotificationChannel> subscribedRecipients = manager.findSubscribedRecipientsForDispatcher(
-        this, projectUuid, ALL_MUST_HAVE_ROLE_USER);
+    Multimap<String, NotificationChannel> subscribedRecipients = manager
+        .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER);
 
     Collection<NotificationChannel> channels = subscribedRecipients.get(assignee);
     for (NotificationChannel channel : channels) {
index 3f5df507eb316b066c409d212b03f16a26055f3b..bc630d529a362af758e9596ff71bc392ca19bb45 100644 (file)
@@ -49,7 +49,6 @@ import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate
 import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_DATE;
 import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_KEY;
 import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_NAME;
-import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_UUID;
 import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE_TYPE;
 
 public class NewIssuesNotification extends Notification {
@@ -80,10 +79,9 @@ public class NewIssuesNotification extends Notification {
     return this;
   }
 
-  public NewIssuesNotification setProject(String projectKey, String projectUuid, String projectName, @Nullable String branchName) {
+  public NewIssuesNotification setProject(String projectKey, String projectName, @Nullable String branchName) {
     setFieldValue(FIELD_PROJECT_NAME, projectName);
     setFieldValue(FIELD_PROJECT_KEY, projectKey);
-    setFieldValue(FIELD_PROJECT_UUID, projectUuid);
     if (branchName != null) {
       setFieldValue(FIELD_BRANCH, branchName);
     }
index cd404a4af6c7b240db9a10bde09258da5d1d3188..feccf3d73e3cb1f830eabca41bd6c9009e1f7fcd 100644 (file)
@@ -56,9 +56,9 @@ public class NewIssuesNotificationDispatcher extends NotificationDispatcher {
 
   @Override
   public void dispatch(Notification notification, Context context) {
-    String projectUuid = notification.getFieldValue("projectUuid");
-    Multimap<String, NotificationChannel> subscribedRecipients = manager.findSubscribedRecipientsForDispatcher(
-      this, projectUuid, ALL_MUST_HAVE_ROLE_USER);
+    String projectKey = notification.getFieldValue("projectKey");
+    Multimap<String, NotificationChannel> subscribedRecipients = manager
+      .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER);
 
     for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
       String userLogin = channelsByRecipients.getKey();
index d7fd1c0b7f5a9932b1bb7f6f1821578be5fe24bf..96406bbacfb3565cae5f04cf3bee1af8311f8c4e 100644 (file)
@@ -118,13 +118,13 @@ public class DefaultNotificationManager implements NotificationManager {
    * {@inheritDoc}
    */
   @Override
-  public Multimap<String, NotificationChannel> findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, String projectUuid,
-    SubscriberPermissionsOnProject subscriberPermissionsOnProject) {
-    requireNonNull(projectUuid, "ProjectUUID is mandatory");
+  public Multimap<String, NotificationChannel> findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher,
+    String projectKey, SubscriberPermissionsOnProject subscriberPermissionsOnProject) {
+    requireNonNull(projectKey, "projectKey is mandatory");
     String dispatcherKey = dispatcher.getKey();
 
     Set<SubscriberAndChannel> subscriberAndChannels = Arrays.stream(notificationChannels)
-      .flatMap(notificationChannel -> toSubscriberAndChannels(dispatcherKey, projectUuid, notificationChannel))
+      .flatMap(notificationChannel -> toSubscriberAndChannels(dispatcherKey, projectKey, notificationChannel))
       .collect(Collectors.toSet());
 
     if (subscriberAndChannels.isEmpty()) {
@@ -133,7 +133,7 @@ public class DefaultNotificationManager implements NotificationManager {
 
     ImmutableSetMultimap.Builder<String, NotificationChannel> builder = ImmutableSetMultimap.builder();
     try (DbSession dbSession = dbClient.openSession(false)) {
-      Set<String> authorizedLogins = keepAuthorizedLogins(dbSession, projectUuid, subscriberAndChannels, subscriberPermissionsOnProject);
+      Set<String> authorizedLogins = keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, subscriberPermissionsOnProject);
       subscriberAndChannels.stream()
         .filter(subscriberAndChannel -> authorizedLogins.contains(subscriberAndChannel.getSubscriber().getLogin()))
         .forEach(subscriberAndChannel -> builder.put(subscriberAndChannel.getSubscriber().getLogin(), subscriberAndChannel.getChannel()));
@@ -141,27 +141,27 @@ public class DefaultNotificationManager implements NotificationManager {
     return builder.build();
   }
 
-  private Stream<SubscriberAndChannel> toSubscriberAndChannels(String dispatcherKey, String projectUuid, NotificationChannel notificationChannel) {
-    Set<Subscriber> usersForNotification = dbClient.propertiesDao().findUsersForNotification(dispatcherKey, notificationChannel.getKey(), projectUuid);
+  private Stream<SubscriberAndChannel> toSubscriberAndChannels(String dispatcherKey, String projectKey, NotificationChannel notificationChannel) {
+    Set<Subscriber> usersForNotification = dbClient.propertiesDao().findUsersForNotification(dispatcherKey, notificationChannel.getKey(), projectKey);
     return usersForNotification
       .stream()
       .map(login -> new SubscriberAndChannel(login, notificationChannel));
   }
 
-  private Set<String> keepAuthorizedLogins(DbSession dbSession, String projectUuid, Set<SubscriberAndChannel> subscriberAndChannels,
+  private Set<String> keepAuthorizedLogins(DbSession dbSession, String projectKey, Set<SubscriberAndChannel> subscriberAndChannels,
     SubscriberPermissionsOnProject requiredPermissions) {
     if (requiredPermissions.getGlobalSubscribers().equals(requiredPermissions.getProjectSubscribers())) {
-      return keepAuthorizedLogins(dbSession, projectUuid, subscriberAndChannels, null, requiredPermissions.getGlobalSubscribers());
+      return keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, null, requiredPermissions.getGlobalSubscribers());
     } else {
       return Stream
         .concat(
-          keepAuthorizedLogins(dbSession, projectUuid, subscriberAndChannels, true, requiredPermissions.getGlobalSubscribers()).stream(),
-          keepAuthorizedLogins(dbSession, projectUuid, subscriberAndChannels, false, requiredPermissions.getProjectSubscribers()).stream())
+          keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, true, requiredPermissions.getGlobalSubscribers()).stream(),
+          keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, false, requiredPermissions.getProjectSubscribers()).stream())
         .collect(Collectors.toSet());
     }
   }
 
-  private Set<String> keepAuthorizedLogins(DbSession dbSession, String projectUuid, Set<SubscriberAndChannel> subscriberAndChannels,
+  private Set<String> keepAuthorizedLogins(DbSession dbSession, String projectKey, Set<SubscriberAndChannel> subscriberAndChannels,
     @Nullable Boolean global, String permission) {
     Set<String> logins = subscriberAndChannels.stream()
       .filter(s -> global == null || s.getSubscriber().isGlobal() == global)
@@ -170,7 +170,7 @@ public class DefaultNotificationManager implements NotificationManager {
     if (logins.isEmpty()) {
       return Collections.emptySet();
     }
-    return dbClient.authorizationDao().keepAuthorizedLoginsOnProject(dbSession, logins, projectUuid, permission);
+    return dbClient.authorizationDao().keepAuthorizedLoginsOnProject(dbSession, logins, projectKey, permission);
   }
 
   private static final class SubscriberAndChannel {
index 82cad44378cf7a5bb46cd1523853fed6674e5a16..6b59aa6f5120fa12c3ef0d20ac07689dce514d7a 100644 (file)
@@ -78,8 +78,8 @@ public class ReportAnalysisFailureNotificationDispatcherTest {
   @Test
   public void performDispatch_adds_user_for_each_recipient_and_channel_for_the_component_uuid_in_the_notification() {
     when(notificationMock.getType()).thenReturn(ReportAnalysisFailureNotification.TYPE);
-    String projectUuid = randomAlphanumeric(9);
-    when(notificationMock.getFieldValue("project.uuid")).thenReturn(projectUuid);
+    String projectKey = randomAlphanumeric(9);
+    when(notificationMock.getFieldValue("project.key")).thenReturn(projectKey);
     HashMultimap<String, NotificationChannel> multimap = HashMultimap.create();
     String login1 = randomAlphanumeric(3);
     String login2 = randomAlphanumeric(3);
@@ -90,7 +90,7 @@ public class ReportAnalysisFailureNotificationDispatcherTest {
     multimap.put(login1, channel2);
     multimap.put(login2, channel2);
     multimap.put(login2, channel3);
-    when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectUuid, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER)))
+    when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectKey, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER)))
       .thenReturn(multimap);
 
     underTest.performDispatch(notificationMock, contextMock);
@@ -105,10 +105,10 @@ public class ReportAnalysisFailureNotificationDispatcherTest {
   @Test
   public void performDispatch_adds_no_user_if_notification_manager_returns_none() {
     when(notificationMock.getType()).thenReturn(ReportAnalysisFailureNotification.TYPE);
-    String projectUuid = randomAlphanumeric(9);
-    when(notificationMock.getFieldValue("project.uuid")).thenReturn(projectUuid);
+    String projectKey = randomAlphanumeric(9);
+    when(notificationMock.getFieldValue("project.key")).thenReturn(projectKey);
     HashMultimap<String, NotificationChannel> multimap = HashMultimap.create();
-    when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectUuid, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER)))
+    when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectKey, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER)))
       .thenReturn(multimap);
 
     underTest.performDispatch(notificationMock, contextMock);
index f0d821eb93b74d75b50fc8b019ef8b9411f15bb3..ef8923c092af4ceeffdcbace7daf0d20183f622c 100644 (file)
@@ -188,7 +188,6 @@ public class QualityGateEventsStepTest {
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
     assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
-    assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
     assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
     assertThat(notification.getFieldValue("branch")).isNull();
@@ -241,7 +240,6 @@ public class QualityGateEventsStepTest {
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
     assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
-    assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
     assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
     assertThat(notification.getFieldValue("branch")).isNull();
@@ -271,7 +269,6 @@ public class QualityGateEventsStepTest {
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
     assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
-    assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
     assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
     assertThat(notification.getFieldValue("branch")).isEqualTo(branchName);
@@ -293,7 +290,6 @@ public class QualityGateEventsStepTest {
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
     assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
-    assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
     assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
     assertThat(notification.getFieldValue("branch")).isEqualTo(null);
index 8646a7bb46c0255d26ba0555c9a0053bb978a263..0516536628cbddda9b7343fe645287467b9fb095 100644 (file)
@@ -144,7 +144,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
     underTest.execute();
 
     verify(notificationService).deliver(newIssuesNotificationMock);
-    verify(newIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getUuid(), PROJECT.getName(), null);
+    verify(newIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getName(), null);
     verify(newIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE));
     verify(newIssuesNotificationMock).setStatistics(eq(PROJECT.getName()), any(NewIssuesStatistics.Stats.class));
     verify(newIssuesNotificationMock).setDebt(ISSUE_DURATION);
@@ -207,7 +207,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
     underTest.execute();
 
     verify(notificationService).deliver(newIssuesNotificationMock);
-    verify(newIssuesNotificationMock).setProject(branch.getKey(), branch.uuid(), branch.longName(), BRANCH_NAME);
+    verify(newIssuesNotificationMock).setProject(branch.getKey(), branch.longName(), BRANCH_NAME);
     verify(newIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE));
     verify(newIssuesNotificationMock).setStatistics(eq(branch.longName()), any(NewIssuesStatistics.Stats.class));
     verify(newIssuesNotificationMock).setDebt(ISSUE_DURATION);
@@ -239,7 +239,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
     verify(notificationService).deliver(newIssuesNotificationMock);
     verify(notificationService).deliver(myNewIssuesNotificationMock);
     verify(myNewIssuesNotificationMock).setAssignee(ISSUE_ASSIGNEE);
-    verify(myNewIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getUuid(), PROJECT.getName(), null);
+    verify(myNewIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getName(), null);
     verify(myNewIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE));
     verify(myNewIssuesNotificationMock).setStatistics(eq(PROJECT.getName()), any(NewIssuesStatistics.Stats.class));
     verify(myNewIssuesNotificationMock).setDebt(ISSUE_DURATION);
@@ -425,7 +425,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
 
   private NewIssuesNotification createNewIssuesNotificationMock() {
     NewIssuesNotification notification = mock(NewIssuesNotification.class);
-    when(notification.setProject(anyString(), anyString(), anyString(), anyString())).thenReturn(notification);
+    when(notification.setProject(anyString(), anyString(), anyString())).thenReturn(notification);
     when(notification.setProjectVersion(anyString())).thenReturn(notification);
     when(notification.setAnalysisDate(any(Date.class))).thenReturn(notification);
     when(notification.setStatistics(anyString(), any(NewIssuesStatistics.Stats.class))).thenReturn(notification);
@@ -436,7 +436,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
   private MyNewIssuesNotification createMyNewIssuesNotificationMock() {
     MyNewIssuesNotification notification = mock(MyNewIssuesNotification.class);
     when(notification.setAssignee(anyString())).thenReturn(notification);
-    when(notification.setProject(anyString(), anyString(), anyString(), anyString())).thenReturn(notification);
+    when(notification.setProject(anyString(), anyString(), anyString())).thenReturn(notification);
     when(notification.setProjectVersion(anyString())).thenReturn(notification);
     when(notification.setAnalysisDate(any(Date.class))).thenReturn(notification);
     when(notification.setStatistics(anyString(), any(NewIssuesStatistics.Stats.class))).thenReturn(notification);
index bb20ef863d9e9c3ee31c7e59c6c98d92076ca475..62b3327fabcb359411392eb6fae538f2d2097540 100644 (file)
@@ -28,15 +28,20 @@ import org.sonar.api.web.UserRole;
 import org.sonar.server.notification.NotificationDispatcher;
 import org.sonar.server.notification.NotificationManager;
 
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+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 {
 
-  NotificationManager notificationManager = mock(NotificationManager.class);
-  NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
-  NotificationChannel emailChannel = mock(NotificationChannel.class);
-  NotificationChannel twitterChannel = mock(NotificationChannel.class);
-  NewAlerts dispatcher = new NewAlerts(notificationManager);
+  private NotificationManager notificationManager = mock(NotificationManager.class);
+  private NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
+  private NotificationChannel emailChannel = mock(NotificationChannel.class);
+  private NotificationChannel twitterChannel = mock(NotificationChannel.class);
+  private NewAlerts dispatcher = new NewAlerts(notificationManager);
 
   @Test
   public void should_not_dispatch_if_not_alerts_notification() {
@@ -51,9 +56,11 @@ public class NewAlertsTest {
     Multimap<String, NotificationChannel> recipients = HashMultimap.create();
     recipients.put("user1", emailChannel);
     recipients.put("user2", twitterChannel);
-    when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, "uuid_34", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
+    when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, "key_34", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER)))
+      .thenReturn(recipients);
 
-    Notification notification = new Notification("alerts").setFieldValue("projectUuid", "uuid_34");
+    Notification notification = new Notification("alerts")
+      .setFieldValue("projectKey", "key_34");
     dispatcher.performDispatch(notification, context);
 
     verify(context).addUser("user1", emailChannel);
@@ -62,11 +69,12 @@ public class NewAlertsTest {
   }
 
   @Test
-  public void should_not_dispatch_if_missing_project_id() {
+  public void should_not_dispatch_if_missing_project_key() {
     Multimap<String, NotificationChannel> recipients = HashMultimap.create();
     recipients.put("user1", emailChannel);
     recipients.put("user2", twitterChannel);
-    when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, "uuid_34", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
+    when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, "key_34", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER)))
+      .thenReturn(recipients);
 
     Notification notification = new Notification("alerts");
     dispatcher.performDispatch(notification, context);
index bf2b55409d6cbcb6b6cdfba4de97db5b566b8c0d..8e33f079c96b8b2fe6fb9d28b27d065fe7650e8f 100644 (file)
@@ -117,7 +117,6 @@ public class IssueUpdaterTest {
     assertThat(issueChangeNotification.getFieldValue("componentKey")).isEqualTo(file.getDbKey());
     assertThat(issueChangeNotification.getFieldValue("componentName")).isEqualTo(file.longName());
     assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.getDbKey());
-    assertThat(issueChangeNotification.getFieldValue("projectUuid")).isEqualTo(project.uuid());
     assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name());
     assertThat(issueChangeNotification.getFieldValue("ruleName")).isEqualTo(rule.getName());
     assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo("john");
index e58a9a71a60966dc2af2c33b33835c60c13cf50c..cad2fdc1ec2963057a5b1950ccc3ba87d2fc3967 100644 (file)
@@ -84,12 +84,11 @@ public class ChangesOnMyIssueNotificationDispatcherTest {
     recipients.put("simon", emailChannel);
     recipients.put("freddy", twitterChannel);
     recipients.put("godin", twitterChannel);
-    when(notifications.findSubscribedRecipientsForDispatcher(dispatcher, "uuid1",
-        new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
+    when(notifications.findSubscribedRecipientsForDispatcher(dispatcher, "struts",
+      new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
 
     Notification notification = new IssueChangeNotification()
       .setFieldValue("projectKey", "struts")
-      .setFieldValue("projectUuid", "uuid1")
       .setFieldValue("changeAuthor", "olivier")
       .setFieldValue("assignee", "freddy");
     dispatcher.performDispatch(notification, context);
@@ -113,7 +112,8 @@ public class ChangesOnMyIssueNotificationDispatcherTest {
         .setFieldValue("projectKey", "struts")
         .setFieldValue("projectUuid", "uuid1")
         .setFieldValue("changeAuthor", "simon")
-        .setFieldValue("assignee", "simon"), context);
+        .setFieldValue("assignee", "simon"),
+      context);
 
     // no change author
     dispatcher.performDispatch(new IssueChangeNotification().setFieldValue("projectKey", "struts")
index c1467623791e92122c702452de017344da39ebf1..7248080bd1843ba50034935ed695050a1cb6b3c8 100644 (file)
@@ -31,7 +31,13 @@ import org.sonar.server.notification.NotificationDispatcherMetadata;
 import org.sonar.server.notification.NotificationManager;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
 
 public class DoNotFixNotificationDispatcherTest {
   NotificationManager notifications = mock(NotificationManager.class);
@@ -62,10 +68,10 @@ public class DoNotFixNotificationDispatcherTest {
     recipients.put("simon", emailChannel);
     recipients.put("freddy", twitterChannel);
     recipients.put("godin", twitterChannel);
-    when(notifications.findSubscribedRecipientsForDispatcher(underTest, "uuid1", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
+    when(notifications.findSubscribedRecipientsForDispatcher(underTest, "struts", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
 
-    Notification fpNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts")
-      .setFieldValue("projectUuid", "uuid1")
+    Notification fpNotif = new IssueChangeNotification()
+      .setFieldValue("projectKey", "struts")
       .setFieldValue("changeAuthor", "godin")
       .setFieldValue("new.resolution", Issue.RESOLUTION_FALSE_POSITIVE)
       .setFieldValue("assignee", "freddy");
index 94ff9af63e89cce64e79fa37fd5b1117380afa0f..18a513ca9fffed8ab72cf78397259188dc605e03 100644 (file)
@@ -84,18 +84,16 @@ public class IssueChangeNotificationTest {
 
   @Test
   public void set_project_without_branch() {
-    IssueChangeNotification result = notification.setProject("MyService", "My Service", null, "uuid1");
+    IssueChangeNotification result = notification.setProject("MyService", "My Service", null);
     assertThat(result.getFieldValue("projectKey")).isEqualTo("MyService");
-    assertThat(result.getFieldValue("projectUuid")).isEqualTo("uuid1");
     assertThat(result.getFieldValue("projectName")).isEqualTo("My Service");
     assertThat(result.getFieldValue("branch")).isNull();
   }
 
   @Test
   public void set_project_with_branch() {
-    IssueChangeNotification result = notification.setProject("MyService", "My Service", "feature1", "uuid2");
+    IssueChangeNotification result = notification.setProject("MyService", "My Service", "feature1");
     assertThat(result.getFieldValue("projectKey")).isEqualTo("MyService");
-    assertThat(result.getFieldValue("projectUuid")).isEqualTo("uuid2");
     assertThat(result.getFieldValue("projectName")).isEqualTo("My Service");
     assertThat(result.getFieldValue("branch")).isEqualTo("feature1");
   }
index 90ac0f3d1a43ac6152977949e0db16ded69bce16..3e858e61915fa5c17381cca3f1e484923f1ab6b0 100644 (file)
@@ -170,7 +170,7 @@ public class IssueChangesEmailTemplateTest {
 
     Notification notification = new IssueChangeNotification()
       .setChangeAuthorLogin("simon")
-      .setProject("Struts", "org.apache:struts", null, "");
+      .setProject("Struts", "org.apache:struts", null);
 
     EmailMessage message = underTest.format(notification);
     assertThat(message.getFrom()).isEqualTo("Simon");
@@ -182,7 +182,7 @@ public class IssueChangesEmailTemplateTest {
 
     Notification notification = new IssueChangeNotification()
       .setChangeAuthorLogin("simon")
-      .setProject("Struts", "org.apache:struts", null, "");
+      .setProject("Struts", "org.apache:struts", null);
 
     EmailMessage message = underTest.format(notification);
     assertThat(message.getFrom()).isEqualTo("simon");
index 13092a3ba2f1f43eb361a11b2a844b3d9577b0df..f6ebece6a6847237adb0914df9808c494863a216 100644 (file)
@@ -224,7 +224,6 @@ public class MyNewIssuesEmailTemplateTest {
     return new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE)
       .setFieldValue("projectName", "Struts")
       .setFieldValue("projectKey", "org.apache:struts")
-      .setFieldValue("projectUuid", "ABCDE")
       .setFieldValue("projectDate", "2010-05-18T14:50:45+0000")
       .setFieldValue("assignee", "lo.gin")
       .setFieldValue(EFFORT + ".count", "1d3h")
index cb5f38c7f7a294ffc53afb214ccafba5fd0f37c7..6e54f8dbccec00e6df3afc60a4f0448358656d57 100644 (file)
@@ -59,11 +59,10 @@ public class MyNewIssuesNotificationDispatcherTest {
     Multimap<String, NotificationChannel> recipients = HashMultimap.create();
     recipients.put("user1", emailChannel);
     recipients.put("user2", twitterChannel);
-    when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, "uuid1", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
+    when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, "struts", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
 
     Notification notification = new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE)
       .setFieldValue("projectKey", "struts")
-      .setFieldValue("projectUuid", "uuid1")
       .setFieldValue("assignee", "user1");
     underTest.performDispatch(notification, context);
 
index 02872c4f408b6420ae2fdb089b5a562d92c9818c..e429096b27362edaa98d2a069b1cdb04c5e8760b 100644 (file)
@@ -228,7 +228,6 @@ public class NewIssuesEmailTemplateTest {
     return new Notification(NewIssuesNotification.TYPE)
       .setFieldValue("projectName", "Struts")
       .setFieldValue("projectKey", "org.apache:struts")
-      .setFieldValue("projectUuid", "ABCDE")
       .setFieldValue("projectDate", "2010-05-18T14:50:45+0000")
       .setFieldValue(EFFORT + ".count", "1d3h")
       .setFieldValue(RULE_TYPE + ".count", String.valueOf(count))
index c59fc50191be0d65d17c485d4d70d552655541c1..153b16774ab7b4bdbd54446c02d636da12c908c2 100644 (file)
@@ -57,11 +57,10 @@ public class NewIssuesNotificationDispatcherTest {
     Multimap<String, NotificationChannel> recipients = HashMultimap.create();
     recipients.put("user1", emailChannel);
     recipients.put("user2", twitterChannel);
-    when(notifications.findSubscribedRecipientsForDispatcher(dispatcher, "uuid1", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
+    when(notifications.findSubscribedRecipientsForDispatcher(dispatcher, "struts", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients);
 
     Notification notification = new Notification(NewIssuesNotification.TYPE)
-      .setFieldValue("projectKey", "struts")
-      .setFieldValue("projectUuid", "uuid1");
+      .setFieldValue("projectKey", "struts");
     dispatcher.performDispatch(notification, context);
 
     verify(context).addUser("user1", emailChannel);
index edcefd30ed2476d93eb5c5cf213d398d03a506c2..647a6e73532d0184a21f4b9909f476d45749f804 100644 (file)
@@ -83,20 +83,18 @@ public class NewIssuesNotificationTest {
 
   @Test
   public void set_project_without_branch() {
-    underTest.setProject("project-key", "project-uuid", "project-long-name", null);
+    underTest.setProject("project-key", "project-long-name", null);
 
     assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_NAME)).isEqualTo("project-long-name");
-    assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_UUID)).isEqualTo("project-uuid");
     assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_KEY)).isEqualTo("project-key");
     assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_BRANCH)).isNull();
   }
 
   @Test
   public void set_project_with_branch() {
-    underTest.setProject("project-key", "project-uuid", "project-long-name", "feature");
+    underTest.setProject("project-key", "project-long-name", "feature");
 
     assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_NAME)).isEqualTo("project-long-name");
-    assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_UUID)).isEqualTo("project-uuid");
     assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_KEY)).isEqualTo("project-key");
     assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_BRANCH)).isEqualTo("feature");
   }