]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10597 Update ISSUE_CHANGE#USER_LOGIN to USER_UUID
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 11 May 2018 09:06:31 +0000 (11:06 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 23 May 2018 18:20:48 +0000 (20:20 +0200)
82 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDbTester.java
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete-result.xml [deleted file]
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete.xml [deleted file]
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/empty.xml [deleted file]
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/insert-result.xml [deleted file]
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/selectChangelogOfNonClosedIssuesByComponent.xml [deleted file]
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/shared.xml [deleted file]
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update-result.xml [deleted file]
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update.xml [deleted file]
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_comment-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_diff-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues.xml
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueStorage.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java
server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ShortBranchIssueMergerTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/TransitionServiceTest.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/ws/AddCommentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/DeleteCommentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/EditCommentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_insert_new_issues-result.xml
server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_update_issues-result.xml
server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml
server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java
sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java
sonar-core/src/main/java/org/sonar/core/issue/IssueChangeContext.java
sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
sonar-core/src/test/java/org/sonar/core/issue/IssueChangeContextTest.java
sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java
sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueComment.java
tests/src/test/java/org/sonarqube/tests/issue/IssueChangelogTest.java
tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java
tests/src/test/java/org/sonarqube/tests/user/SonarCloudUpdateLoginDuringAuthenticationTest.java

index e5dfb2a5dfab88e98c3b32470d8aeeb5d9b20590..c77a5f650f9d8f9918d1d46f6ce12a616f4c5500 100644 (file)
@@ -83,14 +83,6 @@ public class ComponentDao implements Dao {
     return session.getMapper(ComponentMapper.class);
   }
 
-  public ComponentDto selectOrFailById(DbSession session, long id) {
-    Optional<ComponentDto> componentDto = selectById(session, id);
-    if (!componentDto.isPresent()) {
-      throw new RowNotFoundException(String.format("Component id does not exist: %d", id));
-    }
-    return componentDto.get();
-  }
-
   public Optional<ComponentDto> selectById(DbSession session, long id) {
     return Optional.fromNullable(mapper(session).selectById(id));
   }
index fa97adf11cdda67be76c4cde4667860e29960a46..8787c9ca93004acfe9203d601d8c0a87fe582694 100644 (file)
@@ -39,11 +39,6 @@ public class IssueChangeDao implements Dao {
       .collect(MoreCollectors.toList());
   }
 
-  public List<IssueChangeDto> selectChangelogOfNonClosedIssuesByComponent(DbSession session, String componentUuid) {
-    IssueChangeMapper mapper = mapper(session);
-    return mapper.selectChangelogOfNonClosedIssuesByComponent(componentUuid, IssueChangeDto.TYPE_FIELD_CHANGE);
-  }
-
   public List<IssueChangeDto> selectByTypeAndIssueKeys(DbSession session, Collection<String> issueKeys, String changeType) {
     return executeLargeInputs(issueKeys, issueKeys1 -> mapper(session).selectByIssuesAndType(issueKeys1, changeType));
   }
index b3af27e73731e2ae642b3741e0d472bb415c84f3..5c8dd1aa94fe6576d685795afa0583156888d583 100644 (file)
@@ -43,7 +43,10 @@ public final class IssueChangeDto implements Serializable {
   private Long id;
   private String kee;
   private String issueKey;
-  private String userLogin;
+  /**
+   * The column USER_LOGIN hasn't been renamed to USER_UUID because we don't know yet the cost of renaming a column on a table that can contain huge number of data
+   */
+  private String userUuid;
   private String changeType;
   private String changeData;
 
@@ -60,7 +63,7 @@ public final class IssueChangeDto implements Serializable {
     dto.setKey(comment.key());
     dto.setChangeType(IssueChangeDto.TYPE_COMMENT);
     dto.setChangeData(comment.markdownText());
-    dto.setUserLogin(comment.userLogin());
+    dto.setUserUuid(comment.userUuid());
     Date createdAt = requireNonNull(comment.createdAt(), "Comment created at must not be null");
     dto.setIssueChangeCreationDate(createdAt.getTime());
     return dto;
@@ -70,7 +73,7 @@ public final class IssueChangeDto implements Serializable {
     IssueChangeDto dto = newDto(issueKey);
     dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE);
     dto.setChangeData(diffs.toString());
-    dto.setUserLogin(diffs.userLogin());
+    dto.setUserUuid(diffs.userUuid());
     Date createdAt = requireNonNull(diffs.creationDate(), "Diffs created at must not be null");
     dto.setIssueChangeCreationDate(createdAt.getTime());
     return dto;
@@ -115,12 +118,12 @@ public final class IssueChangeDto implements Serializable {
   }
 
   @CheckForNull
-  public String getUserLogin() {
-    return userLogin;
+  public String getUserUuid() {
+    return userUuid;
   }
 
-  public IssueChangeDto setUserLogin(@Nullable String userLogin) {
-    this.userLogin = userLogin;
+  public IssueChangeDto setUserUuid(@Nullable String userUuid) {
+    this.userUuid = userUuid;
     return this;
   }
 
@@ -181,14 +184,14 @@ public final class IssueChangeDto implements Serializable {
       .setKey(kee)
       .setCreatedAt(new Date(getIssueChangeCreationDate()))
       .setUpdatedAt(updatedAt == null ? null : new Date(updatedAt))
-      .setUserLogin(userLogin)
+      .setUserUuid(userUuid)
       .setIssueKey(issueKey)
       .setNew(false);
   }
 
   public FieldDiffs toFieldDiffs() {
     return FieldDiffs.parse(changeData)
-      .setUserLogin(userLogin)
+      .setUserUuid(userUuid)
       .setCreationDate(new Date(getIssueChangeCreationDate()))
       .setIssueKey(issueKey);
   }
index b6216a313f1a480371df67705e4d1230af1ec56e..b176704c6727137c7a8de988eb64e461cab020c4 100644 (file)
@@ -42,5 +42,4 @@ public interface IssueChangeMapper {
 
   List<IssueChangeDto> selectByIssues(@Param("issueKeys") List<String> issueKeys);
 
-  List<IssueChangeDto> selectChangelogOfNonClosedIssuesByComponent(@Param("componentUuid") String componentUuid, @Param("changeType") String changeType);
 }
index 6f03a04bdafa78802627ad4bb0212fc8d80d8642..7eaebeb4eb5025349bff3970f622563d568220cf 100644 (file)
@@ -36,6 +36,7 @@ import static com.google.common.collect.Sets.newHashSet;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.apache.commons.lang.math.RandomUtils.nextInt;
+import static org.apache.commons.lang.math.RandomUtils.nextLong;
 
 public class IssueTesting {
 
@@ -70,6 +71,18 @@ public class IssueTesting {
       .setUpdatedAt(System.currentTimeMillis() - 500);
   }
 
+  public static IssueChangeDto newIssuechangeDto(IssueDto issue) {
+    return new IssueChangeDto()
+      .setKey("uuid_" + randomAlphabetic(10))
+      .setIssueKey(issue.getKey())
+      .setChangeData("data_" + randomAlphanumeric(40))
+      .setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE)
+      .setUserUuid("userUuid_" + randomAlphanumeric(40))
+      .setIssueChangeCreationDate(nextLong())
+      .setCreatedAt(nextLong())
+      .setUpdatedAt(nextLong());
+  }
+
   /**
    * @deprecated use newIssue(...)
    */
index 8b315466eb75f815235d9bdcd1d7228aa0e518de..6733ce22e82bdc745f1dfc7f25929d0bfd93bec5 100644 (file)
@@ -8,7 +8,7 @@
     c.id,
     c.kee as kee,
     c.issue_key as issueKey,
-    c.user_login as userLogin,
+    c.user_login as userUuid,
     c.change_type as changeType,
     c.change_data as changeData,
     c.created_at as createdAt,
@@ -19,7 +19,7 @@
   <insert id="insert" parameterType="IssueChange" useGeneratedKeys="false" keyProperty="id">
     INSERT INTO issue_changes (kee, issue_key, user_login, change_type, change_data, created_at, updated_at,
     issue_change_creation_date)
-    VALUES (#{kee,jdbcType=VARCHAR}, #{issueKey,jdbcType=VARCHAR}, #{userLogin,jdbcType=VARCHAR},
+    VALUES (#{kee,jdbcType=VARCHAR}, #{issueKey,jdbcType=VARCHAR}, #{userUuid,jdbcType=VARCHAR},
     #{changeType,jdbcType=VARCHAR}, #{changeData,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT},
     #{updatedAt,jdbcType=BIGINT}, #{issueChangeCreationDate,jdbcType=BIGINT})
   </insert>
     order by created_at asc
   </select>
 
-  <select id="selectChangelogOfNonClosedIssuesByComponent" parameterType="map" resultType="IssueChange">
-    select
-    <include refid="issueChangeColumns"/>
-    from issue_changes c
-    inner join issues i on i.kee = c.issue_key
-    where i.component_uuid=#{componentUuid,jdbcType=VARCHAR}
-    and c.change_type=#{changeType,jdbcType=VARCHAR}
-    and i.status &lt;&gt; 'CLOSED'
-  </select>
 </mapper>
 
index caeeb7dee17c62e7ef936a97c3970c3e63863818..191e803eb7b23ee16f91e89dd4fc575f94c715dd 100644 (file)
@@ -346,7 +346,7 @@ public class ComponentDaoTest {
   public void get_by_id() {
     ComponentDto project = db.components().insertPrivateProject();
 
-    assertThat(underTest.selectOrFailById(dbSession, project.getId())).isNotNull();
+    assertThat(underTest.selectById(dbSession, project.getId())).isNotNull();
   }
 
   @Test
@@ -359,15 +359,6 @@ public class ComponentDaoTest {
     assertThat(result.get().isEnabled()).isFalse();
   }
 
-  @Test
-  public void fail_to_get_by_id_when_project_not_found() {
-    ComponentDto project = db.components().insertPrivateProject();
-
-    expectedException.expect(RowNotFoundException.class);
-
-    underTest.selectOrFailById(dbSession, 0L);
-  }
-
   @Test
   public void get_nullable_by_id() {
     ComponentDto project = db.components().insertPrivateProject();
index 5f9143541f93c1bcd77b12537d99e02e1a98c330..5eec49b95bc8878588622e3780a95a741c4187dd 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.db.issue;
 
-import java.util.Arrays;
 import java.util.List;
 import java.util.Optional;
 import org.junit.Rule;
@@ -29,7 +28,13 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.issue.FieldDiffs;
 import org.sonar.db.DbTester;
 
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.sonar.db.issue.IssueChangeDto.TYPE_COMMENT;
+import static org.sonar.db.issue.IssueChangeDto.TYPE_FIELD_CHANGE;
 
 public class IssueChangeDaoTest {
 
@@ -40,44 +45,53 @@ public class IssueChangeDaoTest {
 
   @Test
   public void select_issue_changelog_from_issue_key() {
-    db.prepareDbUnit(getClass(), "shared.xml");
+    IssueDto issue1 = db.issues().insertIssue();
+    db.issues().insertChange(issue1, c -> c.setChangeType(TYPE_FIELD_CHANGE).setChangeData("severity=MAJOR|BLOCKER"));
+    IssueDto issue2 = db.issues().insertIssue();
+    db.issues().insertChange(issue2);
+
+    List<FieldDiffs> changelog = underTest.selectChangelogByIssue(db.getSession(), issue1.getKey());
 
-    List<FieldDiffs> changelog = underTest.selectChangelogByIssue(db.getSession(), "1000");
     assertThat(changelog).hasSize(1);
     assertThat(changelog.get(0).diffs()).hasSize(1);
     assertThat(changelog.get(0).diffs().get("severity").newValue()).isEqualTo("BLOCKER");
     assertThat(changelog.get(0).diffs().get("severity").oldValue()).isEqualTo("MAJOR");
+
+    assertThat(underTest.selectChangelogByIssue(db.getSession(), "unknown")).isEmpty();
   }
 
   @Test
-  public void select_issue_changes_from_issues_key() {
-    db.prepareDbUnit(getClass(), "shared.xml");
+  public void select_issue_changes_from_issues_keys() {
+    IssueDto issue1 = db.issues().insertIssue();
+    db.issues().insertChange(issue1);
+    db.issues().insertChange(issue1);
+    db.issues().insertChange(issue1);
+    db.issues().insertChange(issue1);
+    IssueDto issue2 = db.issues().insertIssue();
+    db.issues().insertChange(issue2);
+    IssueDto issue3 = db.issues().insertIssue();
+
+    List<IssueChangeDto> changelog = underTest.selectByIssueKeys(db.getSession(), asList(issue1.getKey(), issue2.getKey(), issue3.getKey()));
 
-    List<IssueChangeDto> changelog = underTest.selectByIssueKeys(db.getSession(), Arrays.asList("1000", "1001"));
     assertThat(changelog).hasSize(5);
-  }
 
-  @Test
-  public void selectChangelogOfNonClosedIssuesByComponent() {
-    db.prepareDbUnit(getClass(), "selectChangelogOfNonClosedIssuesByComponent.xml");
-
-    List<IssueChangeDto> dtos = underTest.selectChangelogOfNonClosedIssuesByComponent(db.getSession(), "FILE_1");
-    // no need to have ordered results (see NewDebtCalculator)
-    assertThat(dtos).extracting("id").containsOnly(100L, 103L);
+    assertThat(underTest.selectByIssueKeys(db.getSession(), singletonList("unknown"))).isEmpty();
+    assertThat(underTest.selectByIssueKeys(db.getSession(), emptyList())).isEmpty();
   }
 
   @Test
   public void select_comment_by_key() {
-    IssueDto issueDto = db.issues().insertIssue();
-    IssueChangeDto comment = db.issues().insertComment(issueDto, "john", "some comment");
+    IssueDto issue = db.issues().insertIssue();
+    IssueChangeDto issueChange = db.issues().insertChange(issue, c -> c.setChangeType(TYPE_COMMENT));
+    db.issues().insertChange(issue, c -> c.setChangeType(TYPE_COMMENT));
 
-    Optional<IssueChangeDto> issueChangeDto = underTest.selectCommentByKey(db.getSession(), comment.getKey());
+    Optional<IssueChangeDto> issueChangeDto = underTest.selectCommentByKey(db.getSession(), issueChange.getKey());
 
     assertThat(issueChangeDto).isPresent();
-    assertThat(issueChangeDto.get().getKey()).isEqualTo(comment.getKey());
-    assertThat(issueChangeDto.get().getChangeType()).isEqualTo(IssueChangeDto.TYPE_COMMENT);
-    assertThat(issueChangeDto.get().getUserLogin()).isEqualTo("john");
-    assertThat(issueChangeDto.get().getChangeData()).isEqualTo("some comment");
+    assertThat(issueChangeDto.get().getKey()).isEqualTo(issueChange.getKey());
+    assertThat(issueChangeDto.get().getChangeType()).isEqualTo(TYPE_COMMENT);
+    assertThat(issueChangeDto.get().getUserUuid()).isEqualTo(issueChange.getUserUuid());
+    assertThat(issueChangeDto.get().getChangeData()).isEqualTo(issueChange.getChangeData());
     assertThat(issueChangeDto.get().getIssueChangeCreationDate()).isNotNull();
     assertThat(issueChangeDto.get().getCreatedAt()).isNotNull();
     assertThat(issueChangeDto.get().getUpdatedAt()).isNotNull();
@@ -85,29 +99,32 @@ public class IssueChangeDaoTest {
 
   @Test
   public void delete() {
-    db.prepareDbUnit(getClass(), "delete.xml");
+    IssueDto issue = db.issues().insertIssue();
+    IssueChangeDto issueChange1 = db.issues().insertChange(issue);
+    IssueChangeDto issueChange2 = db.issues().insertChange(issue);
 
-    assertThat(underTest.delete(db.getSession(), "COMMENT-2")).isTrue();
-    db.commit();
+    assertThat(underTest.delete(db.getSession(), issueChange1.getKey())).isTrue();
 
-    db.assertDbUnit(getClass(), "delete-result.xml", "issue_changes");
+    assertThat(db.countRowsOfTable(db.getSession(), "issue_changes")).isEqualTo(1);
   }
 
   @Test
   public void delete_unknown_key() {
-    db.prepareDbUnit(getClass(), "delete.xml");
+    IssueDto issue = db.issues().insertIssue();
+    db.issues().insertChange(issue);
 
     assertThat(underTest.delete(db.getSession(), "UNKNOWN")).isFalse();
   }
 
   @Test
   public void insert() {
+    IssueDto issue = db.issues().insertIssue();
     IssueChangeDto changeDto = new IssueChangeDto()
       .setKey("EFGH")
-      .setUserLogin("emmerik")
+      .setUserUuid("user_uuid")
       .setChangeData("Some text")
       .setChangeType("comment")
-      .setIssueKey("ABCDE")
+      .setIssueKey(issue.getKey())
       .setCreatedAt(1_500_000_000_000L)
       .setUpdatedAt(1_501_000_000_000L)
       .setIssueChangeCreationDate(1_502_000_000_000L);
@@ -115,36 +132,56 @@ public class IssueChangeDaoTest {
     underTest.insert(db.getSession(), changeDto);
     db.getSession().commit();
 
-    db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "issue_changes");
+    assertThat(underTest.selectByIssueKeys(db.getSession(), singletonList(issue.getKey())))
+      .extracting(IssueChangeDto::getKey, IssueChangeDto::getIssueKey, IssueChangeDto::getChangeData, IssueChangeDto::getChangeType,
+        IssueChangeDto::getIssueChangeCreationDate, IssueChangeDto::getCreatedAt, IssueChangeDto::getUpdatedAt)
+      .containsExactlyInAnyOrder(
+        tuple("EFGH", issue.getKey(), "Some text", TYPE_COMMENT, 1_502_000_000_000L, 1_500_000_000_000L, 1_501_000_000_000L));
   }
 
   @Test
   public void update() {
-    db.prepareDbUnit(getClass(), "update.xml");
-
-    IssueChangeDto change = new IssueChangeDto();
-    change.setKey("COMMENT-2");
-
-    // Only the following fields can be updated:
-    change.setChangeData("new comment");
-    change.setUpdatedAt(1_500_000_000_000L);
-
-    assertThat(underTest.update(db.getSession(), change)).isTrue();
+    IssueDto issue = db.issues().insertIssue();
+    IssueChangeDto issueChange = db.issues().insertChange(issue);
+
+    assertThat(underTest.update(db.getSession(), new IssueChangeDto()
+      .setKey(issueChange.getKey())
+      // Only the following fields can be updated:
+      .setChangeData("new comment")
+      .setUpdatedAt(1_500_000_000_000L)
+      // Should not be taking into account
+      .setIssueKey("other_issue_uuid")
+      .setUserUuid("other_user_uuid")
+      .setCreatedAt(10_000_000_000L)
+      .setIssueChangeCreationDate(30_000_000_000L))).isTrue();
     db.commit();
 
-    db.assertDbUnit(getClass(), "update-result.xml", "issue_changes");
+    assertThat(underTest.selectByIssueKeys(db.getSession(), singletonList(issue.getKey())))
+      .extracting(IssueChangeDto::getKey, IssueChangeDto::getIssueKey, IssueChangeDto::getChangeData, IssueChangeDto::getChangeType,
+        IssueChangeDto::getIssueChangeCreationDate, IssueChangeDto::getCreatedAt, IssueChangeDto::getUpdatedAt)
+      .containsExactlyInAnyOrder(
+        tuple(issueChange.getKey(), issue.getKey(), "new comment", issueChange.getChangeType(), issueChange.getIssueChangeCreationDate(), issueChange.getCreatedAt(),
+          1_500_000_000_000L));
   }
 
   @Test
   public void update_unknown_key() {
-    db.prepareDbUnit(getClass(), "update.xml");
-
-    IssueChangeDto change = new IssueChangeDto();
-    change.setKey("UNKNOWN");
-    change.setChangeData("new comment");
-    change.setUpdatedAt(DateUtils.parseDate("2013-06-30").getTime());
-
-    assertThat(underTest.update(db.getSession(), change)).isFalse();
+    IssueDto issue = db.issues().insertIssue();
+    IssueChangeDto issueChange = db.issues().insertChange(issue);
+
+    assertThat(underTest.update(db.getSession(), new IssueChangeDto()
+      .setKey("UNKNOWN")
+      .setIssueKey("other_issue_uuid")
+      .setChangeData("new comment")
+      .setUpdatedAt(DateUtils.parseDate("2013-06-30").getTime())))
+        .isFalse();
+
+    assertThat(underTest.selectByIssueKeys(db.getSession(), singletonList(issue.getKey())))
+      .extracting(IssueChangeDto::getKey, IssueChangeDto::getIssueKey, IssueChangeDto::getChangeData, IssueChangeDto::getChangeType,
+        IssueChangeDto::getIssueChangeCreationDate, IssueChangeDto::getCreatedAt, IssueChangeDto::getUpdatedAt)
+      .containsExactlyInAnyOrder(
+        tuple(issueChange.getKey(), issue.getKey(), issueChange.getChangeData(), issueChange.getChangeType(), issueChange.getIssueChangeCreationDate(), issueChange.getCreatedAt(),
+          issueChange.getUpdatedAt()));
   }
 
 }
index baeb22ac973ad5319fb9bcda7fba57b4c1c7b9c5..3f7059fbc3d1d3e87d630db5ab8c5443016dc2d8 100644 (file)
@@ -31,7 +31,7 @@ public class IssueChangeDtoTest {
 
   @Test
   public void create_from_comment() {
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
 
     IssueChangeDto dto = IssueChangeDto.of(comment);
 
@@ -41,12 +41,12 @@ public class IssueChangeDtoTest {
     assertThat(dto.getUpdatedAt()).isNotNull();
     assertThat(dto.getIssueChangeCreationDate()).isNotNull();
     assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
-    assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+    assertThat(dto.getUserUuid()).isEqualTo("user_uuid");
   }
 
   @Test
   public void create_from_comment_with_created_at() {
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     comment.setCreatedAt(parseDate("2015-01-13"));
 
     IssueChangeDto dto = IssueChangeDto.of(comment);
@@ -58,7 +58,7 @@ public class IssueChangeDtoTest {
   public void create_from_diff() {
     FieldDiffs diffs = new FieldDiffs();
     diffs.setDiff("severity", "INFO", "BLOCKER");
-    diffs.setUserLogin("emmerik");
+    diffs.setUserUuid("user_uuid");
     diffs.setCreationDate(parseDate("2015-01-13"));
 
     IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
@@ -68,7 +68,7 @@ public class IssueChangeDtoTest {
     assertThat(dto.getCreatedAt()).isNotNull();
     assertThat(dto.getUpdatedAt()).isNotNull();
     assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
-    assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+    assertThat(dto.getUserUuid()).isEqualTo("user_uuid");
     assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
   }
 
@@ -76,7 +76,7 @@ public class IssueChangeDtoTest {
   public void create_from_diff_with_created_at() {
     FieldDiffs diffs = new FieldDiffs();
     diffs.setDiff("severity", "INFO", "BLOCKER");
-    diffs.setUserLogin("emmerik");
+    diffs.setUserUuid("user_uuid");
     diffs.setCreationDate(parseDate("2015-01-13"));
 
     IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
@@ -88,7 +88,7 @@ public class IssueChangeDtoTest {
   public void to_comment() {
     IssueChangeDto changeDto = new IssueChangeDto()
       .setKey("EFGH")
-      .setUserLogin("emmerik")
+      .setUserUuid("user_uuid")
       .setChangeData("Some text")
       .setIssueKey("ABCDE")
       .setCreatedAt(System2.INSTANCE.now())
@@ -99,7 +99,7 @@ public class IssueChangeDtoTest {
     assertThat(comment.markdownText()).isEqualTo("Some text");
     assertThat(comment.createdAt()).isNotNull();
     assertThat(comment.updatedAt()).isNotNull();
-    assertThat(comment.userLogin()).isEqualTo("emmerik");
+    assertThat(comment.userUuid()).isEqualTo("user_uuid");
     assertThat(comment.issueKey()).isEqualTo("ABCDE");
   }
 
@@ -107,13 +107,13 @@ public class IssueChangeDtoTest {
   public void to_field_diffs_with_issue_creation_date() {
     IssueChangeDto changeDto = new IssueChangeDto()
       .setKey("EFGH")
-      .setUserLogin("emmerik")
+      .setUserUuid("user_uuid")
       .setChangeData("Some text")
       .setIssueKey("ABCDE")
       .setIssueChangeCreationDate(System2.INSTANCE.now());
 
     FieldDiffs diffs = changeDto.toFieldDiffs();
-    assertThat(diffs.userLogin()).isEqualTo("emmerik");
+    assertThat(diffs.userUuid()).isEqualTo("user_uuid");
     assertThat(diffs.issueKey()).isEqualTo("ABCDE");
     assertThat(diffs.creationDate()).isNotNull();
   }
@@ -122,13 +122,13 @@ public class IssueChangeDtoTest {
   public void to_field_diffs_with_create_at() {
     IssueChangeDto changeDto = new IssueChangeDto()
       .setKey("EFGH")
-      .setUserLogin("emmerik")
+      .setUserUuid("user_uuid")
       .setChangeData("Some text")
       .setIssueKey("ABCDE")
       .setCreatedAt(System2.INSTANCE.now());
 
     FieldDiffs diffs = changeDto.toFieldDiffs();
-    assertThat(diffs.userLogin()).isEqualTo("emmerik");
+    assertThat(diffs.userUuid()).isEqualTo("user_uuid");
     assertThat(diffs.issueKey()).isEqualTo("ABCDE");
     assertThat(diffs.creationDate()).isNotNull();
   }
@@ -137,7 +137,7 @@ public class IssueChangeDtoTest {
   public void getIssueChangeCreationDate_fallback_to_createAt_when_null() {
     IssueChangeDto changeDto = new IssueChangeDto()
       .setKey("EFGH")
-      .setUserLogin("emmerik")
+      .setUserUuid("user_uuid")
       .setChangeData("Some text")
       .setIssueKey("ABCDE")
       .setCreatedAt(10_000_000L)
@@ -148,7 +148,7 @@ public class IssueChangeDtoTest {
 
   @Test
   public void to_string() {
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     IssueChangeDto dto = IssueChangeDto.of(comment);
     assertThat(dto.toString()).contains("ABCDE");
   }
index a62605aca97bdc0cb7375f4fbb40b1a417fc0ee5..e446629b72809e6d36c6adba0066ecf0b9bb71d1 100644 (file)
@@ -34,7 +34,7 @@ public class IssueChangeMapperTest {
   public void insert_diff() {
     IssueChangeDto dto = new IssueChangeDto();
     dto.setKey(null /* no key on field changes */);
-    dto.setUserLogin("emmerik");
+    dto.setUserUuid("user_uuid");
     dto.setIssueKey("ABCDE");
     dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE);
     dto.setChangeData("severity=INFO|BLOCKER");
@@ -51,7 +51,7 @@ public class IssueChangeMapperTest {
   public void insert_comment() {
     IssueChangeDto dto = new IssueChangeDto();
     dto.setKey("COMMENT-1234");
-    dto.setUserLogin("emmerik");
+    dto.setUserUuid("user_uuid");
     dto.setIssueKey("ABCDE");
     dto.setChangeType(IssueChangeDto.TYPE_COMMENT);
     dto.setChangeData("the comment");
index 92f5b940af2e8693ec4495ab0b59cb6f48fe9f93..4d02ac3cac4b901dc0a73679089e9de9b6a682cd 100644 (file)
@@ -28,7 +28,9 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.user.UserDto;
 
+import static java.util.Arrays.stream;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.issue.IssueTesting.newIssue;
 
@@ -40,14 +42,10 @@ public class IssueDbTester {
     this.db = db;
   }
 
-  public IssueDto insert(RuleDefinitionDto rule, ComponentDto project, ComponentDto file) {
+  @SafeVarargs
+  public final IssueDto insert(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, Consumer<IssueDto>... populators) {
     IssueDto issue = newIssue(rule, project, file);
-    return insertIssue(issue);
-  }
-
-  public IssueDto insert(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, Consumer<IssueDto> populator) {
-    IssueDto issue = newIssue(rule, project, file);
-    populator.accept(issue);
+    stream(populators).forEach(p -> p.accept(issue));
     return insertIssue(issue);
   }
 
@@ -57,37 +55,36 @@ public class IssueDbTester {
     return issueDto;
   }
 
-  public IssueDto insertIssue() {
-    return insertIssue(issueDto -> {
-    });
-  }
-
-  public IssueDto insertIssue(Consumer<IssueDto> populateIssueDto) {
+  @SafeVarargs
+  public final IssueDto insertIssue(Consumer<IssueDto>... populateIssueDto) {
     return insertIssue(db.getDefaultOrganization(), populateIssueDto);
   }
 
-  public IssueDto insertIssue(OrganizationDto organizationDto) {
-    return insertIssue(organizationDto, issueDto -> {
-    });
-  }
-
-  public IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto> populateIssueDto) {
+  @SafeVarargs
+  public final IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto>... populators) {
     RuleDefinitionDto rule = db.rules().insert();
     ComponentDto project = db.components().insertPrivateProject(organizationDto);
     ComponentDto file = db.components().insertComponent(newFileDto(project));
     IssueDto issue = newIssue(rule, project, file);
-    populateIssueDto.accept(issue);
+    stream(populators).forEach(p -> p.accept(issue));
     return insertIssue(issue);
   }
 
+  @SafeVarargs
+  public final IssueChangeDto insertChange(IssueDto issueDto, Consumer<IssueChangeDto>... populators) {
+    IssueChangeDto dto = IssueTesting.newIssuechangeDto(issueDto);
+    stream(populators).forEach(p -> p.accept(dto));
+    return insertChange(dto);
+  }
+
   public IssueChangeDto insertChange(IssueChangeDto issueChangeDto) {
     db.getDbClient().issueChangeDao().insert(db.getSession(), issueChangeDto);
     db.commit();
     return issueChangeDto;
   }
 
-  public IssueChangeDto insertComment(IssueDto issueDto, @Nullable String login, String text) {
-    IssueChangeDto issueChangeDto = IssueChangeDto.of(DefaultIssueComment.create(issueDto.getKey(), login, text));
+  public IssueChangeDto insertComment(IssueDto issueDto, @Nullable UserDto user, String text) {
+    IssueChangeDto issueChangeDto = IssueChangeDto.of(DefaultIssueComment.create(issueDto.getKey(), user == null ? null : user.getUuid(), text));
     return insertChange(issueChangeDto);
   }
 
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete-result.xml
deleted file mode 100644 (file)
index be1549d..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-<dataset>
-
-  <issue_changes
-    id="100"
-    kee="COMMENT-1"
-    issue_key="ISSUE-1"
-    user_login="arthur"
-    change_type="comment"
-    change_data="old comment"
-    created_at="1356994800000"
-    updated_at="1356994800000"
-    issue_change_creation_date="[null]"
-    />
-
-  <issue_changes
-    id="101"
-    kee="[null]"
-    issue_key="1000"
-    user_login="arthur"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1359759600000"
-    updated_at="1359759600000"
-    issue_change_creation_date="1359759600000"
-    />
-
-  <!--
-   DELETED
-
-  <issue_changes
-    id="102"
-    kee="COMMENT-2"
-    issue_key="ISSUE-1"
-    user_login="arthur"
-    change_type="comment"
-    change_data="recent comment"
-    created_at="1367704800000"
-    updated_at="1367704800000"
-    issue_change_creation_date="1367704800000"
-    />
-    -->
-</dataset>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete.xml
deleted file mode 100644 (file)
index 3277acb..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<dataset>
-
-  <issue_changes
-    id="100"
-    kee="COMMENT-1"
-    issue_key="ISSUE-1"
-    user_login="arthur"
-    change_type="comment"
-    change_data="old comment"
-    created_at="1356994800000"
-    updated_at="1356994800000"
-    issue_change_creation_date="[null]"
-    />
-
-  <issue_changes
-    id="101"
-    kee="[null]"
-    issue_key="1000"
-    user_login="arthur"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1359759600000"
-    updated_at="1359759600000"
-    issue_change_creation_date="1359759600000"
-    />
-
-  <issue_changes
-    id="102"
-    kee="COMMENT-2"
-    issue_key="ISSUE-1"
-    user_login="arthur"
-    change_type="comment"
-    change_data="recent comment"
-    created_at="1367704800000"
-    updated_at="1367704800000"
-    issue_change_creation_date="1367704800000"
-    />
-</dataset>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/empty.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/empty.xml
deleted file mode 100644 (file)
index 871dedc..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-
-</dataset>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/insert-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/insert-result.xml
deleted file mode 100644 (file)
index 06468bf..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<dataset>
-
-  <issue_changes
-    id="1"
-    kee="EFGH"
-    issue_key="ABCDE"
-    user_login="emmerik"
-    change_type="comment"
-    change_data="Some text"
-    created_at="1500000000000"
-    updated_at="1501000000000"
-    issue_change_creation_date="1502000000000"
-    />
-
-</dataset>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/selectChangelogOfNonClosedIssuesByComponent.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/selectChangelogOfNonClosedIssuesByComponent.xml
deleted file mode 100644 (file)
index efb08c7..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-<dataset>
-
-  <!-- Unresolved. To be included -->
-  <issues
-    id="1"
-    kee="UNRESOLVED_ON_FILE_1"
-    component_uuid="FILE_1"
-    project_uuid="PROJECT_1"
-    resolution="[null]"
-    status="OPEN"
-    rule_id="500"
-    severity="BLOCKER"
-    manual_severity="[false]"
-    message="[null]"
-    line="200"
-    gap="[null]"
-    checksum="[null]"
-    reporter="[null]"
-    assignee="user"
-    author_login="[null]"
-    issue_attributes="[null]"
-    issue_creation_date="1366063200000"
-    issue_update_date="1366063200000"
-    issue_close_date="1366063200000"
-    created_at="1400000000000"
-    updated_at="[null]"
-    locations="[null]"
-    />
-
-  <!-- diff -->
-  <issue_changes
-    id="100"
-    kee="100"
-    issue_key="UNRESOLVED_ON_FILE_1"
-    user_login="arthur"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1410213600000"
-    updated_at="1410213600000"
-    issue_change_creation_date="1410213600000"
-    />
-
-  <!-- comment -->
-  <issue_changes
-    id="102"
-    kee="102"
-    issue_key="UNRESOLVED_ON_FILE_1"
-    user_login="arthur"
-    change_type="comment"
-    change_data="recent comment"
-    created_at="1410213600000"
-    updated_at="1410213600000"
-    issue_change_creation_date="[null]"
-    />
-
-  <!-- Resolved but not closed. To be included -->
-  <issues
-    id="2"
-    kee="RESOLVED_ON_FILE_1"
-    component_uuid="FILE_1"
-    project_uuid="PROJECT_1"
-    resolution="FIXED"
-    status="RESOLVED"
-    rule_id="501"
-    severity="MAJOR"
-    manual_severity="[false]"
-    message="[null]"
-    line="120"
-    gap="[null]"
-    checksum="[null]"
-    reporter="[null]"
-    assignee="user"
-    author_login="[null]"
-    issue_attributes="[null]"
-    issue_creation_date="1366063200000"
-    issue_update_date="1366063200000"
-    issue_close_date="1366063200000"
-    created_at="1400000000000"
-    updated_at="[null]"
-    locations="[null]"
-    />
-
-  <issue_changes
-    id="103"
-    kee="103"
-    issue_key="RESOLVED_ON_FILE_1"
-    user_login="arthur"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1410213600000"
-    updated_at="1410213600000"
-    issue_change_creation_date="1410213600000"
-    />
-
-  <!-- Closed. To be excluded -->
-  <issues
-    id="3"
-    kee="CLOSED_ON_FILE_1"
-    component_uuid="FILE_1"
-    project_uuid="PROJECT_1"
-    resolution="FIXED"
-    status="CLOSED"
-    rule_id="501"
-    severity="MAJOR"
-    manual_severity="[false]"
-    message="[null]"
-    line="120"
-    gap="[null]"
-    checksum="[null]"
-    reporter="[null]"
-    assignee="user"
-    author_login="[null]"
-    issue_attributes="[null]"
-    issue_creation_date="1366063200000"
-    issue_update_date="1366063200000"
-    issue_close_date="1366063200000"
-    created_at="1400000000000"
-    updated_at="[null]"
-    locations="[null]"
-    />
-
-  <issue_changes
-    id="104"
-    kee="104"
-    issue_key="CLOSED_ON_FILE_1"
-    user_login="arthur"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1410213600000"
-    updated_at="1410213600000"
-    issue_change_creation_date="1410213600000"
-    />
-
-  <!-- Unresolved on other file -->
-  <issues
-    id="4"
-    kee="UNRESOLVED_ON_FILE_2"
-    component_uuid="FILE_2"
-    project_uuid="PROJECT_1"
-    resolution="[null]"
-    status="OPEN"
-    rule_id="500"
-    severity="BLOCKER"
-    manual_severity="[false]"
-    message="[null]"
-    line="200"
-    gap="[null]"
-    checksum="[null]"
-    reporter="[null]"
-    assignee="user"
-    author_login="[null]"
-    issue_attributes="[null]"
-    issue_creation_date="1366063200000"
-    issue_update_date="1366063200000"
-    issue_close_date="1366063200000"
-    created_at="1400000000000"
-    updated_at="[null]"
-    locations="[null]"
-    />
-
-  <!-- diff -->
-  <issue_changes
-    id="105"
-    kee="105"
-    issue_key="UNRESOLVED_ON_FILE_2"
-    user_login="arthur"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1410213600000"
-    updated_at="1410213600000"
-    issue_change_creation_date="1410213600000"
-    />
-
-  <!-- comment -->
-  <issue_changes
-    id="106"
-    kee="106"
-    issue_key="UNRESOLVED_ON_FILE_2"
-    user_login="arthur"
-    change_type="comment"
-    change_data="recent comment"
-    created_at="1410213600000"
-    updated_at="1410213600000"
-    issue_change_creation_date="[null]"
-    />
-</dataset>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/shared.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/shared.xml
deleted file mode 100644 (file)
index 0b181de..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<dataset>
-
-  <issue_changes
-    id="100"
-    kee="ABCDE"
-    issue_key="1000"
-    user_login="arthur"
-    change_type="comment"
-    change_data="old comment"
-    created_at="1356994800000"
-    updated_at="1356994800000"
-    issue_change_creation_date="[null]"
-    />
-
-  <issue_changes
-    id="101"
-    kee="[null]"
-    issue_key="1000"
-    user_login="arthur"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1359759600000"
-    updated_at="1359759600000"
-    issue_change_creation_date="1359759600000"
-    />
-
-  <issue_changes
-    id="102"
-    kee="FGHIJ"
-    issue_key="1000"
-    user_login="arthur"
-    change_type="comment"
-    change_data="recent comment"
-    created_at="1367704800000"
-    updated_at="1367704800000"
-    issue_change_creation_date="[null]"
-    />
-
-  <issue_changes
-    id="103"
-    kee="KLMN"
-    issue_key="1001"
-    user_login="arthur"
-    change_type="diff"
-    change_data="actionPlan=1.0|1.1"
-    created_at="1359759600000"
-    updated_at="1359759600000"
-    issue_change_creation_date="1359759600000"
-    />
-
-  <issue_changes
-    id="104"
-    kee="OPQR"
-    issue_key="1001"
-    user_login="henry"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1356994800000"
-    updated_at="1356994800000"
-    issue_change_creation_date="1356994800000"
-    />
-
-</dataset>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update-result.xml
deleted file mode 100644 (file)
index a1c436a..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<dataset>
-
-  <issue_changes
-    id="100"
-    kee="COMMENT-1"
-    issue_key="ISSUE-1"
-    user_login="arthur"
-    change_type="comment"
-    change_data="old comment"
-    created_at="1356994800000"
-    updated_at="1356994800000"
-    issue_change_creation_date="[null]"
-    />
-
-  <issue_changes
-    id="101"
-    kee="[null]"
-    issue_key="1000"
-    user_login="arthur"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1359759600000"
-    updated_at="1359759600000"
-    issue_change_creation_date="1359759600000"
-    />
-
-  <issue_changes
-    id="102"
-    kee="COMMENT-2"
-    issue_key="ISSUE-1"
-    user_login="arthur"
-    change_type="comment"
-    change_data="new comment"
-    created_at="1367704800000"
-    updated_at="1500000000000"
-    issue_change_creation_date="[null]"
-    />
-</dataset>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update.xml
deleted file mode 100644 (file)
index 641f333..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<dataset>
-
-  <issue_changes
-    id="100"
-    kee="COMMENT-1"
-    issue_key="ISSUE-1"
-    user_login="arthur"
-    change_type="comment"
-    change_data="old comment"
-    created_at="1356994800000"
-    updated_at="1356994800000"
-    issue_change_creation_date="[null]"
-    />
-
-  <issue_changes
-    id="101"
-    kee="[null]"
-    issue_key="1000"
-    user_login="arthur"
-    change_type="diff"
-    change_data="severity=MAJOR|BLOCKER"
-    created_at="1359759600000"
-    updated_at="1359759600000"
-    issue_change_creation_date="1359759600000"
-    />
-
-  <issue_changes
-    id="102"
-    kee="COMMENT-2"
-    issue_key="ISSUE-1"
-    user_login="arthur"
-    change_type="comment"
-    change_data="old value"
-    created_at="1367704800000"
-    updated_at="1367704800000"
-    issue_change_creation_date="[null]"
-    />
-</dataset>
index f319c0348564410cbb89fd0023e2d9f39b9ca4cd..0dca8fdc4aabd6b8635456abb4c1c1a2252a7c6c 100644 (file)
@@ -3,7 +3,7 @@
     id="1"
     kee="COMMENT-1234"
     issue_key="ABCDE"
-    user_login="emmerik"
+    user_login="user_uuid"
     change_type="comment"
     change_data="the comment"
     created_at="1500000000000"
index bbc0741292f88b3a240734baa9d8aa97cd128c69..08dd09684b458c83c81f71508d90b35960fc94e4 100644 (file)
@@ -3,7 +3,7 @@
     id="1"
     kee="[null]"
     issue_key="ABCDE"
-    user_login="emmerik"
+    user_login="user_uuid"
     change_type="diff"
     change_data="severity=INFO|BLOCKER"
     created_at="1500000000000"
index ba8ac69dff9d373c3720e7ecb46156a41ee8d665..2b7cd7f71078e97b8fc5cffd0f5e5fbebecc098d 100644 (file)
                  issue_key="ABCDE"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="this is a comment"/>
 
index 703004ce3915d13ca0113793cdf9534911f6c8f1..deb3b1511d65232543195ee8e9477fd36f75977f 100644 (file)
                  issue_key="ABCDF"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"/>
 
index 2d594175e37a361917d33b0c62894df2c6bf5525..0722a36074433578d1b93ef2a3092d91a45ee161 100644 (file)
                  issue_key="ISSUE-3"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-4"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
index 75014b07a852f7dc9fab73c0cfeadd57791157a9..cdb04fe8e7df6f2a40e876fcc65228d1f37fc13f 100644 (file)
@@ -79,7 +79,7 @@
                  issue_key="ISSUE-1"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-2"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-3"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-4"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-5"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
index 694bfcc96887b66e259143f619973cf742294553..d7c45fc5c191a941edde2ff70eaa07318e3fa45c 100644 (file)
                  issue_key="ISSUE-3"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-4"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-5"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
index 4d97e9a281fa0cf3a5eab7569d6ec72f200af0ca..2d6ceed18650ef15aa6d0065b62195908fac0e07 100644 (file)
@@ -78,7 +78,7 @@
                  issue_key="ISSUE-1"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-2"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-3"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-4"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
                  issue_key="ISSUE-5"
                  created_at="[null]"
                  updated_at="[null]"
-                 user_login="admin"
+                 user_login="admin_uuid"
                  change_type="comment"
                  change_data="abc"
                  issue_change_creation_date="[null]"/>
index 64787b0cd7493a725f2f48127d552589420a64f1..3bd8525c14619b093e108a71f655ee43f113015f 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.annotations.VisibleForTesting;
 import java.util.Date;
 import java.util.Optional;
 import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.IssueComment;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.DefaultIssueComment;
 import org.sonar.core.issue.FieldDiffs;
@@ -94,18 +93,18 @@ public class IssueLifecycle {
   }
 
   private static void copyChanges(DefaultIssue raw, DefaultIssue base) {
-    base.comments().forEach(c -> raw.addComment(copy(raw.key(), c)));
+    base.defaultIssueComments().forEach(c -> raw.addComment(copy(raw.key(), c)));
     base.changes().forEach(c -> copy(raw.key(), c).ifPresent(raw::addChange));
   }
 
   /**
    * Copy a comment from another issue
    */
-  private static DefaultIssueComment copy(String issueKey, IssueComment c) {
+  private static DefaultIssueComment copy(String issueKey, DefaultIssueComment c) {
     DefaultIssueComment comment = new DefaultIssueComment();
     comment.setIssueKey(issueKey);
     comment.setKey(Uuids.create());
-    comment.setUserLogin(c.userLogin());
+    comment.setUserUuid(c.userUuid());
     comment.setMarkdownText(c.markdownText());
     comment.setCreatedAt(c.createdAt()).setUpdatedAt(c.updatedAt());
     comment.setNew(true);
@@ -118,7 +117,7 @@ public class IssueLifecycle {
   private static Optional<FieldDiffs> copy(String issueKey, FieldDiffs c) {
     FieldDiffs result = new FieldDiffs();
     result.setIssueKey(issueKey);
-    result.setUserLogin(c.userLogin());
+    result.setUserUuid(c.userUuid());
     result.setCreationDate(c.creationDate());
     // Don't copy "file" changelogs as they refer to file uuids that might later be purged
     c.diffs().entrySet().stream().filter(e -> !e.getKey().equals(IssueFieldsSetter.FILE))
index 8a59f8818135a31156a4a607af46b01b8c334e3c..3e5b82b277244989b78b8b11a05e7748be56c44b 100644 (file)
@@ -28,7 +28,6 @@ import java.util.Locale;
 import java.util.Objects;
 import java.util.Set;
 import javax.annotation.Nullable;
-
 import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.rules.RuleType;
 import org.sonar.api.server.ServerSide;
@@ -110,10 +109,12 @@ public class IssueFieldsSetter {
     }
     return false;
   }
+
   public boolean assign(DefaultIssue issue, @Nullable UserDto user, IssueChangeContext context) {
     String assigneeUuid = user != null ? user.getUuid() : null;
     if (!Objects.equals(assigneeUuid, issue.assignee())) {
-      issue.setFieldChange(context, ASSIGNEE, UNUSED, user != null ? user.getUuid() : null);
+      String newAssigneeName = user == null ? null : user.getName();
+      issue.setFieldChange(context, ASSIGNEE, UNUSED, newAssigneeName);
       issue.setAssigneeUuid(user != null ? user.getUuid() : null);
       issue.setUpdateDate(context.date());
       issue.setChanged(true);
@@ -239,7 +240,7 @@ public class IssueFieldsSetter {
   }
 
   public void addComment(DefaultIssue issue, String text, IssueChangeContext context) {
-    issue.addComment(DefaultIssueComment.create(issue.key(), context.login(), text));
+    issue.addComment(DefaultIssueComment.create(issue.key(), context.userUuid(), text));
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
   }
index 951042669f5b53420ff0f78784a429c62f591ad5..05fd5b6bbb30e5613c31dad6104bccd427a7f436 100644 (file)
@@ -27,7 +27,6 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.IssueComment;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.utils.System2;
@@ -153,10 +152,9 @@ public abstract class IssueStorage {
   protected abstract IssueDto doUpdate(DbSession batchSession, long now, DefaultIssue issue);
 
   public static void insertChanges(IssueChangeMapper mapper, DefaultIssue issue) {
-    for (IssueComment comment : issue.comments()) {
-      DefaultIssueComment c = (DefaultIssueComment) comment;
-      if (c.isNew()) {
-        IssueChangeDto changeDto = IssueChangeDto.of(c);
+    for (DefaultIssueComment comment : issue.defaultIssueComments()) {
+      if (comment.isNew()) {
+        IssueChangeDto changeDto = IssueChangeDto.of(comment);
         mapper.insert(changeDto);
       }
     }
index 86e24f47de38000f07d11adf394f0fa233781862..8b04bb0ade5274c901def6989c4a0c0726aa449d 100644 (file)
@@ -37,6 +37,7 @@ import org.sonar.server.issue.notification.IssueChangeNotification;
 import org.sonar.server.issue.ws.SearchResponseData;
 import org.sonar.server.notification.NotificationManager;
 
+import static com.google.common.base.Preconditions.checkState;
 import static java.util.Collections.singleton;
 import static java.util.Collections.singletonList;
 
@@ -64,7 +65,7 @@ public class IssueUpdater {
 
     Optional<RuleDefinitionDto> rule = getRuleByKey(dbSession, issue.getRuleKey());
     ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.projectUuid());
-    ComponentDto component = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.componentUuid());
+    ComponentDto component = getComponent(dbSession, issue, issue.componentUuid());
     IssueDto issueDto = doSaveIssue(dbSession, issue, context, comment, rule, project, component);
 
     SearchResponseData result = new SearchResponseData(issueDto);
@@ -82,8 +83,8 @@ public class IssueUpdater {
 
   public IssueDto saveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) {
     Optional<RuleDefinitionDto> rule = getRuleByKey(session, issue.getRuleKey());
-    ComponentDto project = dbClient.componentDao().selectOrFailByUuid(session, issue.projectUuid());
-    ComponentDto component = dbClient.componentDao().selectOrFailByUuid(session, issue.componentUuid());
+    ComponentDto project = getComponent(session, issue, issue.projectUuid());
+    ComponentDto component = getComponent(session, issue, issue.componentUuid());
     return doSaveIssue(session, issue, context, comment, rule, project, component);
   }
 
@@ -92,10 +93,12 @@ public class IssueUpdater {
     IssueDto issueDto = issueStorage.save(session, issue);
     String assigneeUuid = issue.assignee();
     UserDto assignee = assigneeUuid == null ? null : dbClient.userDao().selectByUuid(session, assigneeUuid);
+    String authorUuid = context.userUuid();
+    UserDto author = authorUuid == null ? null : dbClient.userDao().selectByUuid(session, authorUuid);
     notificationService.scheduleForSending(new IssueChangeNotification()
       .setIssue(issue)
       .setAssignee(assignee)
-      .setChangeAuthorLogin(context.login())
+      .setChangeAuthor(author)
       .setRuleName(rule.map(RuleDefinitionDto::getName).orElse(null))
       .setProject(project)
       .setComponent(component)
@@ -103,6 +106,14 @@ public class IssueUpdater {
     return issueDto;
   }
 
+  private ComponentDto getComponent(DbSession dbSession, DefaultIssue issue, @Nullable String componentUuid) {
+    String issueKey = issue.key();
+    checkState(componentUuid != null, "Issue '%s' has no component", issueKey);
+    ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orNull();
+    checkState(component != null, "Component uuid '%s' for issue key '%s' cannot be found", componentUuid, issueKey);
+    return component;
+  }
+
   private Optional<RuleDefinitionDto> getRuleByKey(DbSession session, RuleKey ruleKey) {
     Optional<RuleDefinitionDto> rule = dbClient.ruleDao().selectDefinitionByKey(session, ruleKey);
     return (rule.isPresent() && rule.get().getStatus() != RuleStatus.REMOVED) ? rule : Optional.empty();
index e0f3f5b0f04e3c31641ad9f2f78c88dcd1160ea1..2fe93c3f3eb12def43fa9bc6571e240c713dc740 100644 (file)
@@ -84,10 +84,11 @@ public class IssueChangeNotification extends Notification {
     return this;
   }
 
-  public IssueChangeNotification setChangeAuthorLogin(@Nullable String s) {
-    if (s != null) {
-      setFieldValue("changeAuthor", s);
+  public IssueChangeNotification setChangeAuthor(@Nullable UserDto author) {
+    if (author == null) {
+      return this;
     }
+    setFieldValue("changeAuthor", author.getLogin());
     return this;
   }
 
index d501ed054264c78fb14b128b58e281a89c1cde50..4ebee503e8747a3d3659431f01af63d28394e1af 100644 (file)
@@ -95,7 +95,7 @@ public class AddCommentAction implements IssuesWsAction {
     AddCommentRequest wsRequest = toWsRequest(request);
     try (DbSession dbSession = dbClient.openSession(false)) {
       IssueDto issueDto = issueFinder.getByKey(dbSession, wsRequest.getIssue());
-      IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+      IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
       DefaultIssue defaultIssue = issueDto.toDefaultIssue();
       issueFieldsSetter.addComment(defaultIssue, wsRequest.getText(), context);
       SearchResponseData preloadedSearchResponseData = issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, defaultIssue, context, wsRequest.getText(), false);
index 58cb67b2c7fd84e5c923bafbfae167bbb25f2d23..ce8714515b8569d80e89f45a576311371af85821 100644 (file)
@@ -119,7 +119,7 @@ public class AssignAction implements IssuesWsAction {
       if (user != null) {
         checkMembership(dbSession, issueDto, user);
       }
-      IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+      IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
       if (issueFieldsSetter.assign(issue, user, context)) {
         return issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, issue, context, null, false);
       }
index 72636d07b1c9371288107c29d2ecd5dd6d47d7e5..2be2da93a2200da305c98b01d0ccc20b1c71ad5b 100644 (file)
@@ -63,8 +63,10 @@ import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.Issues;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.ImmutableMap.of;
 import static java.lang.String.format;
+import static java.util.Objects.requireNonNull;
 import static java.util.function.Function.identity;
 import static java.util.stream.Collectors.toMap;
 import static java.util.stream.Collectors.toSet;
@@ -190,7 +192,7 @@ public class BulkChangeAction implements IssuesWsAction {
   private BulkChangeResult executeBulkChange(DbSession dbSession, Request request) {
     BulkChangeData bulkChangeData = new BulkChangeData(dbSession, request);
     BulkChangeResult result = new BulkChangeResult(bulkChangeData.issues.size());
-    IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+    IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
 
     List<DefaultIssue> items = bulkChangeData.issues.stream()
       .filter(bulkChange(issueChangeContext, bulkChangeData, result))
@@ -201,8 +203,10 @@ public class BulkChangeAction implements IssuesWsAction {
 
     Set<String> assigneeUuids = items.stream().map(DefaultIssue::assignee).filter(Objects::nonNull).collect(toSet());
     Map<String, UserDto> userDtoByUuid = dbClient.userDao().selectByUuids(dbSession, assigneeUuids).stream().collect(toMap(UserDto::getUuid, u -> u));
-
-    items.forEach(sendNotification(issueChangeContext, bulkChangeData, userDtoByUuid));
+    String authorUuid = requireNonNull(userSession.getUuid(), "User uuid cannot be null");
+    UserDto author = dbClient.userDao().selectByUuid(dbSession, authorUuid);
+    checkState(author != null, "User with uuid '%s' does not exist");
+    items.forEach(sendNotification(bulkChangeData, userDtoByUuid, author));
 
     return result;
   }
@@ -250,14 +254,13 @@ public class BulkChangeAction implements IssuesWsAction {
     bulkChangeData.getCommentAction().ifPresent(action -> action.execute(bulkChangeData.getProperties(action.key()), actionContext));
   }
 
-  private Consumer<DefaultIssue> sendNotification(IssueChangeContext issueChangeContext, BulkChangeData bulkChangeData,
-    Map<String, UserDto> userDtoByUuid) {
+  private Consumer<DefaultIssue> sendNotification(BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, UserDto author) {
     return issue -> {
       if (bulkChangeData.sendNotification) {
         notificationService.scheduleForSending(new IssueChangeNotification()
           .setIssue(issue)
           .setAssignee(userDtoByUuid.get(issue.assignee()))
-          .setChangeAuthorLogin(issueChangeContext.login())
+          .setChangeAuthor(author)
           .setRuleName(bulkChangeData.rulesByKey.get(issue.ruleKey()).getName())
           .setProject(bulkChangeData.projectsByUuid.get(issue.projectUuid()))
           .setComponent(bulkChangeData.componentsByUuid.get(issue.componentUuid())));
index 906be52db21708d2b61e59f0d769289ce511c87b..e44be5866d74a33f13eaf4aaf37bd84c4c4633b6 100644 (file)
@@ -113,10 +113,10 @@ public class ChangelogAction implements IssuesWsAction {
 
   private Function<FieldDiffs, Changelog> toWsChangelog(ChangeLogResults results) {
     return change -> {
-      String userLogin = change.userLogin();
+      String userUUuid = change.userUuid();
       Changelog.Builder changelogBuilder = Changelog.newBuilder();
       changelogBuilder.setCreationDate(formatDateTime(change.creationDate()));
-      UserDto user = userLogin == null ? null : results.users.get(userLogin);
+      UserDto user = userUUuid == null ? null : results.users.get(userUUuid);
       if (user != null) {
         changelogBuilder.setUser(user.getLogin());
         changelogBuilder.setUserName(user.getName());
@@ -155,8 +155,8 @@ public class ChangelogAction implements IssuesWsAction {
     ChangeLogResults(DbSession dbSession, String issueKey) {
       IssueDto dbIssue = issueFinder.getByKey(dbSession, issueKey);
       this.changes = dbClient.issueChangeDao().selectChangelogByIssue(dbSession, dbIssue.getKey());
-      List<String> logins = changes.stream().filter(change -> change.userLogin() != null).map(FieldDiffs::userLogin).collect(MoreCollectors.toList());
-      this.users = dbClient.userDao().selectByLogins(dbSession, logins).stream().collect(MoreCollectors.uniqueIndex(UserDto::getLogin));
+      List<String> userUuids = changes.stream().filter(change -> change.userUuid() != null).map(FieldDiffs::userUuid).collect(MoreCollectors.toList());
+      this.users = dbClient.userDao().selectByUuids(dbSession, userUuids).stream().collect(MoreCollectors.uniqueIndex(UserDto::getUuid));
       this.files = dbClient.componentDao().selectByUuids(dbSession, getFileUuids(changes)).stream().collect(MoreCollectors.uniqueIndex(ComponentDto::uuid, Function.identity()));
     }
 
index 595ea923d7348cd380360d7015b426812040cb8c..98286f173495efd3d03a9692ccd3d6250a47ea13 100644 (file)
@@ -113,7 +113,7 @@ public class DeleteCommentAction implements IssuesWsAction {
         .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", commentKey)));
       // Load issue now to quickly fail if user hasn't permission to see it
       this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey());
-      checkArgument(Objects.equals(issueChangeDto.getUserLogin(), userSession.getLogin()), "You can only delete your own comments");
+      checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only delete your own comments");
     }
 
     IssueChangeDto getIssueChangeDto() {
index 08b1b8ec7f6006ed00e67c686545997ad1e97d65..17c2e938dfb1fe2e53ee42c2f9bb885054510fd9 100644 (file)
@@ -37,6 +37,7 @@ import org.sonar.server.issue.IssueFinder;
 import org.sonar.server.issue.IssueUpdater;
 import org.sonar.server.issue.TransitionService;
 import org.sonar.server.user.UserSession;
+
 import static org.sonar.server.ws.WsUtils.checkRequest;
 import static org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_DO_TRANSITION;
 import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUE;
@@ -100,7 +101,7 @@ public class DoTransitionAction implements IssuesWsAction {
 
   private SearchResponseData doTransition(DbSession session, IssueDto issueDto, String transitionKey) {
     DefaultIssue defaultIssue = issueDto.toDefaultIssue();
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
     transitionService.checkTransitionPermission(transitionKey, defaultIssue);
     if (transitionService.doTransition(defaultIssue, context, transitionKey)) {
       return issueUpdater.saveIssueAndPreloadSearchResponseData(session, defaultIssue, context, null, true);
index 1d3d402ab87737d593e9438369a4339d6f37145b..e6b3cb630fa30623cee19979026879c327e63db1 100644 (file)
@@ -136,7 +136,7 @@ public class EditCommentAction implements IssuesWsAction {
         .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", request.getComment())));
       // Load issue now to quickly fail if user hasn't permission to see it
       this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey());
-      checkArgument(Objects.equals(issueChangeDto.getUserLogin(), userSession.getLogin()), "You can only edit your own comments");
+      checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only edit your own comments");
     }
 
     IssueChangeDto getIssueChangeDto() {
index b8d3f0857d5fef58938b9bd4ee539816da410bdc..6a8761059461ac7cfa11994bf9ed4231c699e7db 100644 (file)
@@ -65,7 +65,6 @@ import org.sonarqube.ws.Issues.SearchWsResponse;
 
 import static com.google.common.base.MoreObjects.firstNonNull;
 import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Strings.nullToEmpty;
 import static com.google.common.collect.Iterables.concat;
 import static com.google.common.collect.Sets.newHashSet;
 import static java.lang.String.format;
@@ -411,7 +410,7 @@ public class SearchAction implements IssuesWsAction {
         .filter(FACETS_REQUIRING_PROJECT_OR_ORGANIZATION::contains)
         .collect(toSet());
       checkArgument(facetsRequiringProjectOrOrganizationParameter.isEmpty() ||
-          (!query.projectUuids().isEmpty()) || query.organizationUuid() != null, "Facet(s) '%s' require to also filter by project or organization",
+        (!query.projectUuids().isEmpty()) || query.organizationUuid() != null, "Facet(s) '%s' require to also filter by project or organization",
         COMA_JOINER.join(facetsRequiringProjectOrOrganizationParameter));
     }
     SearchResponseData preloadedData = new SearchResponseData(emptyList());
@@ -444,7 +443,11 @@ public class SearchAction implements IssuesWsAction {
     }
 
     LinkedHashMap<String, Long> newAssigneeFacets = new LinkedHashMap<>();
-    assigneeFacets.forEach((k, v) -> newAssigneeFacets.put(nullToEmpty(data.getLoginByUserUuid(k)), v));
+    assigneeFacets
+      .forEach((userUuid, v) -> {
+        UserDto user = data.getUserByUuid(userUuid);
+        newAssigneeFacets.put(user == null ? "" : user.getLogin(), v);
+      });
     assigneeFacets.clear();
     assigneeFacets.putAll(newAssigneeFacets);
   }
index d8dcb27143d04a26ad88ebecb096870b12795264..b5acc861c56201e1fb4d1bc2ecf68e94de0402db 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.issue.ws;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ListMultimap;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -32,7 +31,6 @@ import java.util.Map;
 import java.util.Set;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueDto;
@@ -176,11 +174,11 @@ public class SearchResponseData {
   }
 
   @CheckForNull
-  public String getLoginByUserUuid(@Nullable String userUuid) {
+  public UserDto getUserByUuid(@Nullable String userUuid) {
     UserDto userDto = usersByUuid.get(userUuid);
-    if (userDto != null) {
-      return userDto.getLogin();
+    if (userDto == null) {
+      return null;
     }
-    return null;
+    return userDto;
   }
 }
index 1afa8e91e29935d9c927666d667c47a07f81de64..4bfbc23ff8dabd2a6ee6163d59657127791fcc3c 100644 (file)
@@ -180,7 +180,7 @@ public class SearchResponseFormat {
       issueBuilder.setExternalRuleEngine(engineNameFrom(dto.getRuleKey()));
     }
     issueBuilder.setSeverity(Common.Severity.valueOf(dto.getSeverity()));
-    setNullable(data.getLoginByUserUuid(dto.getAssigneeUuid()), issueBuilder::setAssignee);
+    setNullable(data.getUserByUuid(dto.getAssigneeUuid()), assignee -> issueBuilder.setAssignee(assignee.getLogin()));
     setNullable(emptyToNull(dto.getResolution()), issueBuilder::setResolution);
     issueBuilder.setStatus(dto.getStatus());
     issueBuilder.setMessage(nullToEmpty(dto.getMessage()));
@@ -288,9 +288,9 @@ public class SearchResponseFormat {
         wsComment
           .clear()
           .setKey(comment.getKey())
-          .setLogin(nullToEmpty(data.getLoginByUserUuid(comment.getUserLogin())))
           .setUpdatable(data.isUpdatableComment(comment.getKey()))
           .setCreatedAt(DateUtils.formatDateTime(new Date(comment.getIssueChangeCreationDate())));
+        setNullable(data.getUserByUuid(comment.getUserUuid()), user -> wsComment.setLogin(user.getLogin()));
         if (markdown != null) {
           wsComment
             .setHtmlText(Markdown.convertToHtml(markdown))
index 640081a5d68f498e60d679b98587270aff5b24c9..e66f427cebb7f8d9b845170965049f11dda4bd69 100644 (file)
@@ -56,6 +56,7 @@ import static com.google.common.collect.ImmutableSet.copyOf;
 import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Sets.difference;
 import static java.util.Collections.emptyList;
+import static java.util.Objects.requireNonNull;
 import static java.util.Optional.ofNullable;
 import static java.util.stream.Stream.concat;
 import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
@@ -225,8 +226,7 @@ public class SearchResponseLoader {
       List<IssueChangeDto> comments = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbSession, collector.getIssueKeys(), IssueChangeDto.TYPE_COMMENT);
       result.setComments(comments);
       for (IssueChangeDto comment : comments) {
-        // TODO GJT when addressing ticket on IssueChangesUuid
-        collector.add(USERS, comment.getUserLogin());
+        collector.add(USERS, comment.getUserUuid());
         if (canEditOrDelete(comment)) {
           result.addUpdatableComment(comment.getKey());
         }
@@ -235,7 +235,7 @@ public class SearchResponseLoader {
   }
 
   private boolean canEditOrDelete(IssueChangeDto dto) {
-    return userSession.isLoggedIn() && userSession.getLogin().equals(dto.getUserLogin());
+    return userSession.isLoggedIn() && requireNonNull(userSession.getUuid(), "User uuid should not be null").equals(dto.getUserUuid());
   }
 
   private void loadOrganizations(DbSession dbSession, SearchResponseData result) {
index c1cd538704b04608ae89fbdb88f773f1b0fc3a54..8d0e608c89eb5069ed721f479415310e21167160 100644 (file)
@@ -105,7 +105,7 @@ public class SetSeverityAction implements IssuesWsAction {
     DefaultIssue issue = issueDto.toDefaultIssue();
     userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
 
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid());
     if (issueFieldsSetter.setManualSeverity(issue, severity, context)) {
       return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, true);
     }
index 004e916a0129442ed37eb1f7de39e963c9227ff6..9df02691ca7d33466f0eadbac41edd4020fa4faa 100644 (file)
@@ -103,7 +103,7 @@ public class SetTagsAction implements IssuesWsAction {
     try (DbSession session = dbClient.openSession(false)) {
       IssueDto issueDto = issueFinder.getByKey(session, issueKey);
       DefaultIssue issue = issueDto.toDefaultIssue();
-      IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
+      IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid());
       if (issueFieldsSetter.setTags(issue, tags, context)) {
         return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, false);
       }
index d22d5fa26e03362ba20c0cb362fa8c4eb587ef45..241b6be963f98f7f5ad2989124c5c9a043fb4706 100644 (file)
@@ -108,7 +108,7 @@ public class SetTypeAction implements IssuesWsAction {
     DefaultIssue issue = issueDto.toDefaultIssue();
     userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
 
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
     if (issueFieldsSetter.setType(issue, ruleType, context)) {
       return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, true);
     }
index d23c8478ef486fcf16d79f4298c5b47285442a20..0b1780c9009b67073fbccce3d7e68dc2a7d61cc4 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap;
 import java.util.Date;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.issue.IssueComment;
 import org.sonar.api.utils.Duration;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.DefaultIssueComment;
@@ -52,22 +51,23 @@ import static org.sonar.api.utils.DateUtils.parseDate;
 
 public class IssueLifecycleTest {
 
-  static final Date DEFAULT_DATE = new Date();
+  private static final Date DEFAULT_DATE = new Date();
 
-  static final Duration DEFAULT_DURATION = Duration.create(10);
+  private static final Duration DEFAULT_DURATION = Duration.create(10);
 
-  IssueChangeContext issueChangeContext = IssueChangeContext.createUser(DEFAULT_DATE, "julien");
+  @Rule
+  public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
 
-  IssueWorkflow workflow = mock(IssueWorkflow.class);
+  private IssueChangeContext issueChangeContext = IssueChangeContext.createUser(DEFAULT_DATE, "default_user_uuid");
 
-  IssueFieldsSetter updater = mock(IssueFieldsSetter.class);
+  private IssueWorkflow workflow = mock(IssueWorkflow.class);
 
-  DebtCalculator debtCalculator = mock(DebtCalculator.class);
+  private IssueFieldsSetter updater = mock(IssueFieldsSetter.class);
+
+  private DebtCalculator debtCalculator = mock(DebtCalculator.class);
 
-  @Rule
-  public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
 
-  IssueLifecycle underTest = new IssueLifecycle(analysisMetadataHolder, issueChangeContext, workflow, updater, debtCalculator);
+  private IssueLifecycle underTest = new IssueLifecycle(analysisMetadataHolder, issueChangeContext, workflow, updater, debtCalculator);
 
   @Test
   public void initNewOpenIssue() {
@@ -98,7 +98,7 @@ public class IssueLifecycleTest {
     fromShort.addComment(new DefaultIssueComment()
       .setIssueKey("short")
       .setCreatedAt(commentDate)
-      .setUserLogin("user")
+      .setUserUuid("user_uuid")
       .setMarkdownText("A comment"));
 
     Date diffDate = new Date();
@@ -106,13 +106,13 @@ public class IssueLifecycleTest {
     fromShort.addChange(new FieldDiffs()
       .setCreationDate(diffDate)
       .setIssueKey("short")
-      .setUserLogin("user")
+      .setUserUuid("user_uuid")
       .setDiff("file", "uuidA1", "uuidB1"));
     // file diff with another field
     fromShort.addChange(new FieldDiffs()
       .setCreationDate(diffDate)
       .setIssueKey("short")
-      .setUserLogin("user")
+      .setUserUuid("user_uuid")
       .setDiff("severity", "MINOR", "MAJOR")
       .setDiff("file", "uuidA2", "uuidB2"));
 
@@ -124,14 +124,14 @@ public class IssueLifecycleTest {
 
     assertThat(raw.resolution()).isEqualTo("resolution");
     assertThat(raw.status()).isEqualTo("status");
-    assertThat(raw.comments()).extracting(IssueComment::issueKey, IssueComment::createdAt, IssueComment::userLogin, IssueComment::markdownText)
-      .containsOnly(tuple("raw", commentDate, "user", "A comment"));
+    assertThat(raw.defaultIssueComments()).extracting(DefaultIssueComment::issueKey, DefaultIssueComment::createdAt, DefaultIssueComment::userUuid, DefaultIssueComment::markdownText)
+      .containsOnly(tuple("raw", commentDate, "user_uuid", "A comment"));
     assertThat(raw.changes()).hasSize(2);
     assertThat(raw.changes().get(0).creationDate()).isEqualTo(diffDate);
-    assertThat(raw.changes().get(0).userLogin()).isEqualTo("user");
+    assertThat(raw.changes().get(0).userUuid()).isEqualTo("user_uuid");
     assertThat(raw.changes().get(0).issueKey()).isEqualTo("raw");
     assertThat(raw.changes().get(0).diffs()).containsOnlyKeys("severity");
-    assertThat(raw.changes().get(1).userLogin()).isEqualTo("julien");
+    assertThat(raw.changes().get(1).userUuid()).isEqualTo("default_user_uuid");
     assertThat(raw.changes().get(1).diffs()).containsOnlyKeys(IssueFieldsSetter.FROM_SHORT_BRANCH);
     assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_SHORT_BRANCH).oldValue()).isEqualTo("feature/foo");
     assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_SHORT_BRANCH).newValue()).isEqualTo("master");
@@ -160,7 +160,7 @@ public class IssueLifecycleTest {
       .setResolution(RESOLUTION_FIXED)
       .setStatus(STATUS_CLOSED)
       .setSeverity(BLOCKER)
-      .setAssigneeUuid("base assignee")
+      .setAssigneeUuid("base assignee uuid")
       .setAuthorLogin("base author")
       .setTags(newArrayList("base tag"))
       .setOnDisabledRule(true)
@@ -189,7 +189,7 @@ public class IssueLifecycleTest {
     assertThat(raw.closeDate()).isEqualTo(base.closeDate());
     assertThat(raw.resolution()).isEqualTo(RESOLUTION_FIXED);
     assertThat(raw.status()).isEqualTo(STATUS_CLOSED);
-    assertThat(raw.assignee()).isEqualTo("base assignee");
+    assertThat(raw.assignee()).isEqualTo("base assignee uuid");
     assertThat(raw.authorLogin()).isEqualTo("base author");
     assertThat(raw.tags()).containsOnly("base tag");
     assertThat(raw.debt()).isEqualTo(DEFAULT_DURATION);
@@ -233,7 +233,7 @@ public class IssueLifecycleTest {
       .setResolution(RESOLUTION_FIXED)
       .setStatus(STATUS_CLOSED)
       .setSeverity(BLOCKER)
-      .setAssigneeUuid("base assignee")
+      .setAssigneeUuid("base assignee uuid")
       .setAuthorLogin("base author")
       .setTags(newArrayList("base tag"))
       .setOnDisabledRule(true)
@@ -256,7 +256,7 @@ public class IssueLifecycleTest {
     assertThat(raw.closeDate()).isEqualTo(base.closeDate());
     assertThat(raw.resolution()).isEqualTo(RESOLUTION_FIXED);
     assertThat(raw.status()).isEqualTo(STATUS_CLOSED);
-    assertThat(raw.assignee()).isEqualTo("base assignee");
+    assertThat(raw.assignee()).isEqualTo("base assignee uuid");
     assertThat(raw.authorLogin()).isEqualTo("base author");
     assertThat(raw.tags()).containsOnly("base tag");
     assertThat(raw.debt()).isEqualTo(DEFAULT_DURATION);
index f36473f392eb14c307958d16c0867af79bfadc8a..b52486d250fdd38e5bdd127c5334e24e3775a9f6 100644 (file)
@@ -126,7 +126,7 @@ public class MovedIssueVisitorTest {
     ArgumentCaptor<IssueChangeContext> issueChangeContextCaptor = ArgumentCaptor.forClass(IssueChangeContext.class);
     verify(issue).setFieldChange(issueChangeContextCaptor.capture(), eq("file"), eq(originalFile.getUuid()), eq(FILE.getUuid()));
     assertThat(issueChangeContextCaptor.getValue().date()).isEqualTo(new Date(ANALYSIS_DATE));
-    assertThat(issueChangeContextCaptor.getValue().login()).isNull();
+    assertThat(issueChangeContextCaptor.getValue().userUuid()).isNull();
     assertThat(issueChangeContextCaptor.getValue().scan()).isFalse();
   }
 
index e65ee68cc018f190033f59647b9e0811406c0f31..a171b7a932bac3be776bb53093db73c055674d71 100644 (file)
@@ -41,6 +41,7 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.issue.IssueTesting;
 import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.user.UserDto;
 import org.sonar.server.computation.task.projectanalysis.component.ShortBranchComponentsWithIssues;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 
@@ -190,13 +191,15 @@ public class ShortBranchIssueMergerTest {
 
   @Test
   public void lazy_load_changes() {
+    UserDto user1 = db.users().insertUser();
     IssueDto issue1 = db.issues()
       .insertIssue(IssueTesting.newIssue(rule, branch1Dto, fileOnBranch1Dto).setKee("issue1").setStatus(Issue.STATUS_REOPENED).setLine(1).setChecksum("checksum"));
-    db.issues().insertComment(issue1, "user1", "A comment 1");
+    db.issues().insertComment(issue1, user1, "A comment 1");
     db.issues().insertFieldDiffs(issue1, FieldDiffs.parse("severity=BLOCKER|INFO,assignee=toto|titi").setCreationDate(new Date()));
+    UserDto user2 = db.users().insertUser();
     IssueDto issue2 = db.issues()
       .insertIssue(IssueTesting.newIssue(rule, branch2Dto, fileOnBranch2Dto).setKee("issue2").setStatus(Issue.STATUS_CONFIRMED).setLine(1).setChecksum("checksum"));
-    db.issues().insertComment(issue2, "user2", "A comment 2");
+    db.issues().insertComment(issue2, user2, "A comment 2");
     db.issues().insertFieldDiffs(issue2, FieldDiffs.parse("severity=BLOCKER|MINOR,assignee=foo|bar").setCreationDate(new Date()));
     DefaultIssue newIssue = createIssue("newIssue", rule.getKey(), Issue.STATUS_OPEN, null, new Date());
 
@@ -206,7 +209,7 @@ public class ShortBranchIssueMergerTest {
     verify(issueLifecycle).mergeConfirmedOrResolvedFromShortLivingBranch(eq(newIssue), issueToMerge.capture(), eq("myBranch2"));
 
     assertThat(issueToMerge.getValue().key()).isEqualTo("issue2");
-    assertThat(issueToMerge.getValue().comments()).isNotEmpty();
+    assertThat(issueToMerge.getValue().defaultIssueComments()).isNotEmpty();
     assertThat(issueToMerge.getValue().changes()).isNotEmpty();
   }
 
index d25c96d6b2066ed2b25cbb09d032d4db47787a37..c371f75e414b4cc7799f569443791836f2795767 100644 (file)
@@ -130,14 +130,14 @@ public class PersistIssuesStepTest extends BaseStepTest {
       .addComment(new DefaultIssueComment()
         .setKey("COMMENT")
         .setIssueKey("ISSUE")
-        .setUserLogin("john")
+        .setUserUuid("john_uuid")
         .setMarkdownText("Some text")
         .setCreatedAt(new Date(NOW))
         .setNew(true))
       .setCurrentChange(
         new FieldDiffs()
           .setIssueKey("ISSUE")
-          .setUserLogin("john")
+          .setUserUuid("john_uuid")
           .setDiff("technicalDebt", null, 1L)
           .setCreationDate(new Date(NOW))))
       .close();
@@ -182,13 +182,13 @@ public class PersistIssuesStepTest extends BaseStepTest {
       .addComment(new DefaultIssueComment()
         .setKey("COMMENT")
         .setIssueKey("ISSUE")
-        .setUserLogin("john")
+        .setUserUuid("john_uuid")
         .setMarkdownText("Some text")
         .setCreatedAt(new Date(NOW))
         .setNew(true))
       .setCurrentChange(new FieldDiffs()
         .setIssueKey("ISSUE")
-        .setUserLogin("john")
+        .setUserUuid("john_uuid")
         .setDiff("technicalDebt", null, 1L)
         .setCreationDate(new Date(NOW))))
       .close();
@@ -290,7 +290,7 @@ public class PersistIssuesStepTest extends BaseStepTest {
         .addComment(new DefaultIssueComment()
           .setKey("COMMENT")
           .setIssueKey(issue.getKey())
-          .setUserLogin("john")
+          .setUserUuid("john_uuid")
           .setMarkdownText("Some text")
           .setCreatedAt(new Date(NOW))
           .setNew(true)))
@@ -299,9 +299,9 @@ public class PersistIssuesStepTest extends BaseStepTest {
 
     IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0);
     assertThat(issueChangeDto)
-      .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserLogin, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
+      .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserUuid, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
         IssueChangeDto::getIssueChangeCreationDate)
-      .containsOnly(IssueChangeDto.TYPE_COMMENT, "john", "Some text", issue.getKey(), NOW);
+      .containsOnly(IssueChangeDto.TYPE_COMMENT, "john_uuid", "Some text", issue.getKey(), NOW);
   }
 
   @Test
@@ -325,7 +325,7 @@ public class PersistIssuesStepTest extends BaseStepTest {
         .setChanged(true)
         .setCurrentChange(new FieldDiffs()
           .setIssueKey("ISSUE")
-          .setUserLogin("john")
+          .setUserUuid("john_uuid")
           .setDiff("technicalDebt", null, 1L)
           .setCreationDate(new Date(NOW))))
       .close();
@@ -333,9 +333,9 @@ public class PersistIssuesStepTest extends BaseStepTest {
 
     IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0);
     assertThat(issueChangeDto)
-      .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserLogin, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
+      .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserUuid, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
         IssueChangeDto::getIssueChangeCreationDate)
-      .containsOnly(IssueChangeDto.TYPE_FIELD_CHANGE, "john", "technicalDebt=1", issue.getKey(), NOW);
+      .containsOnly(IssueChangeDto.TYPE_FIELD_CHANGE, "john_uuid", "technicalDebt=1", issue.getKey(), NOW);
   }
 
 }
index a67cc18e6efc98e35ffd8b9746ed7c5b19f39695..c487abf643142d2f0f20dd4d32671491aa0bdff5 100644 (file)
@@ -58,7 +58,7 @@ public class AssignActionTest {
   @Rule
   public DbTester db = DbTester.create();
 
-  private IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(), "emmerik");
+  private IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(), "user_uuid");
   private DefaultIssue issue = new DefaultIssue().setKey("ABC").setAssigneeUuid(ISSUE_CURRENT_ASSIGNEE_UUID);
   private ComponentDto project;
   private Action.Context context;
index 368fff1f6aedf7bd0c46b20d482ee8b1327184fe..1d9d4e86f1f686d5bd00ff843b999dc050ad9716 100644 (file)
@@ -48,7 +48,7 @@ public class IssueFieldsSetterTest {
   public ExpectedException thrown = none();
 
   private DefaultIssue issue = new DefaultIssue();
-  private IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik");
+  private IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
   private IssueFieldsSetter underTest = new IssueFieldsSetter();
 
   @Test
@@ -61,12 +61,12 @@ public class IssueFieldsSetterTest {
     assertThat(issue.mustSendNotifications()).isTrue();
     FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE);
     assertThat(diff.oldValue()).isEqualTo(UNUSED);
-    assertThat(diff.newValue()).isEqualTo(user.getUuid());
+    assertThat(diff.newValue()).isEqualTo(user.getName());
   }
 
   @Test
   public void unassign() {
-    issue.setAssigneeUuid("morgan");
+    issue.setAssigneeUuid("user_uuid");
     boolean updated = underTest.assign(issue, null, context);
     assertThat(updated).isTrue();
     assertThat(issue.assignee()).isNull();
@@ -80,14 +80,14 @@ public class IssueFieldsSetterTest {
   public void change_assignee() {
     UserDto user = newUserDto().setLogin("emmerik").setName("Emmerik");
 
-    issue.setAssigneeUuid("morgan");
+    issue.setAssigneeUuid("user_uuid");
     boolean updated = underTest.assign(issue, user, context);
     assertThat(updated).isTrue();
     assertThat(issue.assignee()).isEqualTo(user.getUuid());
     assertThat(issue.mustSendNotifications()).isTrue();
     FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE);
     assertThat(diff.oldValue()).isEqualTo(UNUSED);
-    assertThat(diff.newValue()).isEqualTo(user.getUuid());
+    assertThat(diff.newValue()).isEqualTo(user.getName());
   }
 
   @Test
@@ -103,13 +103,13 @@ public class IssueFieldsSetterTest {
 
   @Test
   public void set_new_assignee() {
-    boolean updated = underTest.setNewAssignee(issue, "simon", context);
+    boolean updated = underTest.setNewAssignee(issue, "user_uuid", context);
     assertThat(updated).isTrue();
-    assertThat(issue.assignee()).isEqualTo("simon");
+    assertThat(issue.assignee()).isEqualTo("user_uuid");
     assertThat(issue.mustSendNotifications()).isTrue();
     FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE);
     assertThat(diff.oldValue()).isEqualTo(UNUSED);
-    assertThat(diff.newValue()).isEqualTo("simon");
+    assertThat(diff.newValue()).isEqualTo("user_uuid");
   }
 
   @Test
@@ -122,11 +122,11 @@ public class IssueFieldsSetterTest {
 
   @Test
   public void fail_with_ISE_when_setting_new_assignee_on_already_assigned_issue() {
-    issue.setAssigneeUuid("simon");
+    issue.setAssigneeUuid("user_uuid");
 
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("It's not possible to update the assignee with this method, please use assign()");
-    underTest.setNewAssignee(issue, "julien", context);
+    underTest.setNewAssignee(issue, "another_user_uuid", context);
   }
 
   @Test
index 4c236bad09e243ac3945e4749d2e6ef9ef8e3e5f..07d488e07af95654db3dd4c0c23c2941e1c413b2 100644 (file)
@@ -45,17 +45,17 @@ public class IssueStorageTest {
   private static final System2 system2 = System2.INSTANCE;
 
   @org.junit.Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), "emmerik");
+  private IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), "user_uuid");
 
-  private DbClient dbClient = dbTester.getDbClient();
+  private DbClient dbClient = db.getDbClient();
 
   @Test
   public void batch_insert_new_issues() {
     FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
 
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     // override generated key
     comment.setKey("FGHIJ");
 
@@ -83,7 +83,7 @@ public class IssueStorageTest {
 
     saver.save(issue);
 
-    dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
+    db.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
       new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
   }
 
@@ -91,7 +91,7 @@ public class IssueStorageTest {
   public void batch_insert_new_issues_with_session() {
     FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
 
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     // override generated key
     comment.setKey("FGHIJ");
 
@@ -117,10 +117,10 @@ public class IssueStorageTest {
       .setProjectUuid("uuid-10")
       .setComponentKey("struts:Action");
 
-    saver.save(dbTester.getSession(), issue);
-    dbTester.getSession().commit();
+    saver.save(db.getSession(), issue);
+    db.getSession().commit();
 
-    dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
+    db.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
       new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
   }
 
@@ -130,7 +130,7 @@ public class IssueStorageTest {
     ComponentDto component = new ComponentDto().setId(100L).setUuid("uuid-100");
     FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project);
 
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     // override generated key
     comment.setKey("FGHIJ");
 
@@ -156,20 +156,20 @@ public class IssueStorageTest {
       .setComponentUuid("component-uuid")
       .setProjectUuid("project-uuid");
 
-    saver.save(dbTester.getSession(), issue);
-    dbTester.getSession().commit();
+    saver.save(db.getSession(), issue);
+    db.getSession().commit();
 
-    dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
-      new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
+    db.assertDbUnit(getClass(), "should_insert_new_issues-result.xml", new String[] {"id", "created_at", "updated_at",
+      "issue_change_creation_date"}, "issues", "issue_changes");
   }
 
   @Test
   public void batch_update_issues() {
-    dbTester.prepareDbUnit(getClass(), "should_update_issues.xml");
+    db.prepareDbUnit(getClass(), "should_update_issues.xml");
 
     FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
 
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     // override generated key
     comment.setKey("FGHIJ");
 
@@ -204,18 +204,18 @@ public class IssueStorageTest {
 
     saver.save(issue);
 
-    dbTester.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
+    db.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
   }
 
   @Test
   public void server_update_issues() {
-    dbTester.prepareDbUnit(getClass(), "should_update_issues.xml");
+    db.prepareDbUnit(getClass(), "should_update_issues.xml");
 
     ComponentDto project = new ComponentDto().setId(10L).setUuid("whatever-uuid");
     ComponentDto component = new ComponentDto().setId(100L).setUuid("whatever-uuid-2");
     FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project);
 
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     // override generated key
     comment.setKey("FGHIJ");
 
@@ -249,7 +249,7 @@ public class IssueStorageTest {
 
     saver.save(issue);
 
-    dbTester.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
+    db.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
   }
 
   static class FakeBatchSaver extends IssueStorage {
index 5b3183ff363baa8d5a5fe957af360159670bc804..60b45778519c4cccdab0d6c672e80ecb955bf3b4 100644 (file)
@@ -30,12 +30,9 @@ import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.IssueChangeContext;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.issue.IssueDbTester;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.issue.IssueTesting;
-import org.sonar.db.rule.RuleDbTester;
 import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.user.UserDto;
@@ -55,8 +52,6 @@ import static org.mockito.Mockito.verify;
 import static org.sonar.api.rule.Severity.BLOCKER;
 import static org.sonar.api.rule.Severity.MAJOR;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.issue.IssueTesting.newDto;
-import static org.sonar.db.rule.RuleTesting.newRuleDto;
 
 public class IssueUpdaterTest {
 
@@ -66,17 +61,14 @@ public class IssueUpdaterTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   @Rule
-  public DbTester dbTester = DbTester.create(system2);
+  public DbTester db = DbTester.create(system2);
 
   @Rule
   public EsTester es = EsTester.create();
 
-  private DbClient dbClient = dbTester.getDbClient();
-  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
+  private DbClient dbClient = db.getDbClient();
+  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
 
-  private RuleDbTester ruleDbTester = new RuleDbTester(dbTester);
-  private IssueDbTester issueDbTester = new IssueDbTester(dbTester);
-  private ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
   private IssueFieldsSetter issueFieldsSetter = new IssueFieldsSetter();
   private NotificationManager notificationManager = mock(NotificationManager.class);
   private ArgumentCaptor<IssueChangeNotification> notificationArgumentCaptor = ArgumentCaptor.forClass(IssueChangeNotification.class);
@@ -88,30 +80,31 @@ public class IssueUpdaterTest {
 
   @Test
   public void update_issue() {
-    DefaultIssue issue = issueDbTester.insertIssue(newIssue().setSeverity(MAJOR)).toDefaultIssue();
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+    DefaultIssue issue = db.issues().insertIssue(i -> i.setSeverity(MAJOR)).toDefaultIssue();
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
     issueFieldsSetter.setSeverity(issue, BLOCKER, context);
 
-    underTest.saveIssue(dbTester.getSession(), issue, context, null);
+    underTest.saveIssue(db.getSession(), issue, context, null);
 
-    IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issue.key()).get();
+    IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issue.key()).get();
     assertThat(issueReloaded.getSeverity()).isEqualTo(BLOCKER);
   }
 
   @Test
   public void verify_notification() {
-    UserDto user = dbTester.users().insertUser();
-    RuleDto rule = ruleDbTester.insertRule(newRuleDto());
-    ComponentDto project = componentDbTester.insertPrivateProject();
-    ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
-    DefaultIssue issue = issueDbTester.insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file))
+    UserDto assignee = db.users().insertUser();
+    RuleDto rule = db.rules().insertRule();
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file))
       .setSeverity(MAJOR)
-      .setAssigneeUuid(user.getUuid())
+      .setAssigneeUuid(assignee.getUuid())
       .toDefaultIssue();
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+    UserDto changeAuthor = db.users().insertUser();
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
     issueFieldsSetter.setSeverity(issue, BLOCKER, context);
 
-    underTest.saveIssue(dbTester.getSession(), issue, context, "increase severity");
+    underTest.saveIssue(db.getSession(), issue, context, "increase severity");
 
     verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
     IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue();
@@ -123,22 +116,22 @@ public class IssueUpdaterTest {
     assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.getDbKey());
     assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name());
     assertThat(issueChangeNotification.getFieldValue("ruleName")).isEqualTo(rule.getName());
-    assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo("john");
+    assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo(changeAuthor.getLogin());
     assertThat(issueChangeNotification.getFieldValue("comment")).isEqualTo("increase severity");
-    assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(user.getLogin());
+    assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(assignee.getLogin());
   }
 
   @Test
   public void verify_notification_on_branch() {
-    RuleDto rule = ruleDbTester.insertRule(newRuleDto());
-    ComponentDto project = componentDbTester.insertMainBranch();
-    ComponentDto branch = componentDbTester.insertProjectBranch(project);
-    ComponentDto file = componentDbTester.insertComponent(newFileDto(branch));
-    DefaultIssue issue = issueDbTester.insertIssue(IssueTesting.newIssue(rule.getDefinition(), branch, file)).setSeverity(MAJOR).toDefaultIssue();
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+    RuleDto rule = db.rules().insertRule();
+    ComponentDto project = db.components().insertMainBranch();
+    ComponentDto branch = db.components().insertProjectBranch(project);
+    ComponentDto file = db.components().insertComponent(newFileDto(branch));
+    DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), branch, file)).setSeverity(MAJOR).toDefaultIssue();
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
     issueFieldsSetter.setSeverity(issue, BLOCKER, context);
 
-    underTest.saveIssue(dbTester.getSession(), issue, context, "increase severity");
+    underTest.saveIssue(db.getSession(), issue, context, "increase severity");
 
     verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
     IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue();
@@ -150,37 +143,54 @@ public class IssueUpdaterTest {
 
   @Test
   public void verify_notification_when_issue_is_linked_on_removed_rule() {
-    RuleDto rule = ruleDbTester.insertRule(newRuleDto().setStatus(RuleStatus.REMOVED));
-    ComponentDto project = componentDbTester.insertPrivateProject();
-    ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
-    DefaultIssue issue = issueDbTester.insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file)).setSeverity(MAJOR).toDefaultIssue();
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+    RuleDto rule = db.rules().insertRule(r -> r.setStatus(RuleStatus.REMOVED));
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file)).setSeverity(MAJOR).toDefaultIssue();
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
     issueFieldsSetter.setSeverity(issue, BLOCKER, context);
 
-    underTest.saveIssue(dbTester.getSession(), issue, context, null);
+    underTest.saveIssue(db.getSession(), issue, context, null);
 
     verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
     assertThat(notificationArgumentCaptor.getValue().getFieldValue("ruleName")).isNull();
   }
 
-  private IssueDto newIssue() {
-    RuleDto rule = ruleDbTester.insertRule(newRuleDto());
-    ComponentDto project = componentDbTester.insertPrivateProject();
-    ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
-    return newDto(rule, file, project);
+  @Test
+  public void verify_notification_when_assignee_has_changed() {
+    UserDto oldAssignee = db.users().insertUser();
+    RuleDto rule = db.rules().insertRule();
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file))
+      .setAssigneeUuid(oldAssignee.getUuid())
+      .toDefaultIssue();
+    UserDto changeAuthor = db.users().insertUser();
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
+    UserDto newAssignee = db.users().insertUser();
+    issueFieldsSetter.assign(issue, newAssignee, context);
+
+    underTest.saveIssue(db.getSession(), issue, context, null);
+
+    verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
+    IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue();
+    assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key());
+    assertThat(issueChangeNotification.getFieldValue("new.assignee")).isEqualTo(newAssignee.getName());
+    assertThat(issueChangeNotification.getFieldValue("old.assignee")).isNull();
+    assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(newAssignee.getLogin());
   }
 
   @Test
   public void saveIssue_populates_specified_SearchResponseData_with_rule_project_and_component_retrieved_from_DB() {
-    RuleDto rule = ruleDbTester.insertRule(newRuleDto());
-    ComponentDto project = componentDbTester.insertPrivateProject();
-    ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
+    RuleDto rule = db.rules().insertRule();
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     IssueDto issueDto = IssueTesting.newIssue(rule.getDefinition(), project, file);
-    DefaultIssue issue = issueDbTester.insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue();
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+    DefaultIssue issue = db.issues().insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue();
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
     issueFieldsSetter.setSeverity(issue, BLOCKER, context);
 
-    SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(dbTester.getSession(), issue, context, null, true);
+    SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, null, true);
 
     assertThat(preloadedSearchResponseData.getIssues())
       .hasSize(1);
@@ -197,15 +207,15 @@ public class IssueUpdaterTest {
 
   @Test
   public void saveIssue_populates_specified_SearchResponseData_with_no_rule_but_with_project_and_component_if_rule_is_removed() {
-    RuleDto rule = ruleDbTester.insertRule(newRuleDto().setStatus(RuleStatus.REMOVED));
-    ComponentDto project = componentDbTester.insertPrivateProject();
-    ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
+    RuleDto rule = db.rules().insertRule(r -> r.setStatus(RuleStatus.REMOVED));
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
     IssueDto issueDto = IssueTesting.newIssue(rule.getDefinition(), project, file);
-    DefaultIssue issue = issueDbTester.insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue();
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+    DefaultIssue issue = db.issues().insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue();
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
     issueFieldsSetter.setSeverity(issue, BLOCKER, context);
 
-    SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(dbTester.getSession(), issue, context, null, false);
+    SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, null, false);
 
     assertThat(preloadedSearchResponseData.getIssues())
       .hasSize(1);
@@ -216,4 +226,5 @@ public class IssueUpdaterTest {
       .extracting(ComponentDto::uuid)
       .containsOnly(project.uuid(), file.uuid());
   }
+
 }
index c4103cd7d2d166296099213b5d433d77e7d96665..023420d92ad3d1ba54bfbac7fcb112656b0e122b 100644 (file)
@@ -80,7 +80,7 @@ public class ServerIssueStorageTest {
   public void should_insert_new_issues() {
     dbTester.prepareDbUnit(getClass(), "should_insert_new_issues.xml");
 
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     // override generated key
     comment.setKey("FGHIJ");
 
@@ -114,9 +114,9 @@ public class ServerIssueStorageTest {
   public void should_update_issues() {
     dbTester.prepareDbUnit(getClass(), "should_update_issues.xml");
 
-    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik");
+    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
 
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     // override generated key
     comment.setKey("FGHIJ");
 
index d2bb160c09ad83154bbb4bb7bdc10ef12ef70f39..bc5aedea1d19d3ffdd67c65ef9c7bb97987e74ed 100644 (file)
@@ -70,7 +70,7 @@ public class SetSeverityActionTest {
     IssueDto issueDto = newIssue().setSeverity(MAJOR);
     DefaultIssue issue = issueDto.toDefaultIssue();
     setUserWithBrowseAndAdministerIssuePermission(issueDto);
-    BulkChangeAction.ActionContext context = new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getLogin()), null);
+    BulkChangeAction.ActionContext context = new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getUuid()), null);
 
     action.execute(ImmutableMap.of("severity", MINOR), context);
 
index 3ef2c1287075bfaeeb661653f7f383dbc2d9177d..fb9a41a2e88335cef7141ac4f5a8225627f15d87 100644 (file)
@@ -71,7 +71,7 @@ public class SetTypeActionTest {
     setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     action.execute(ImmutableMap.of("type", VULNERABILITY.name()),
-      new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getLogin()), null));
+      new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getUuid()), null));
 
     assertThat(issue.type()).isEqualTo(VULNERABILITY);
     assertThat(issue.isChanged()).isTrue();
index be31ef5a637fbd0f6eaa7bfb7cc1f195fe112582..42a32d89672d8571437278cf3767f26569c8fee1 100644 (file)
@@ -21,9 +21,7 @@ package org.sonar.server.issue;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
-
 import java.util.Date;
-
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -71,7 +69,7 @@ public class TransitionActionTest {
   public void setUp() throws Exception {
     workflow.start();
     when(context.issue()).thenReturn(issue);
-    when(context.issueChangeContext()).thenReturn(IssueChangeContext.createUser(new Date(), "john"));
+    when(context.issueChangeContext()).thenReturn(IssueChangeContext.createUser(new Date(), "user_uuid"));
   }
 
   @Test
index 63b6c377bd745345b1fcba0236cf76b0f777d242..a049b8638e6dd30f0bf296e90a3a7b8e83bcb645 100644 (file)
@@ -92,7 +92,7 @@ public class TransitionServiceTest {
   public void do_transition() {
     DefaultIssue issue = newIssue().setStatus(STATUS_OPEN).setResolution(null).toDefaultIssue();
 
-    boolean result = underTest.doTransition(issue, IssueChangeContext.createUser(new Date(), "john"), "confirm");
+    boolean result = underTest.doTransition(issue, IssueChangeContext.createUser(new Date(), "user_uuid"), "confirm");
 
     assertThat(result).isTrue();
     assertThat(issue.status()).isEqualTo(STATUS_CONFIRMED);
index 47150591a90efc9332b57614c9e4e225fb702781..ba2a02cb2017f2a44a38a770357f4054b5a8bae1 100644 (file)
@@ -30,7 +30,7 @@ import static org.sonar.db.user.UserTesting.newUserDto;
 
 public class IssueChangeNotificationTest {
 
-  IssueChangeNotification notification = new IssueChangeNotification();
+  private IssueChangeNotification notification = new IssueChangeNotification();
 
   @Test
   public void set_issue() {
@@ -120,8 +120,9 @@ public class IssueChangeNotificationTest {
 
   @Test
   public void set_change_author_login() {
-    IssueChangeNotification result = notification.setChangeAuthorLogin("stephane");
-    assertThat(result.getFieldValue("changeAuthor")).isEqualTo("stephane");
+    UserDto user = newUserDto();
+    IssueChangeNotification result = notification.setChangeAuthor(user);
+    assertThat(result.getFieldValue("changeAuthor")).isEqualTo(user.getLogin());
   }
 
   @Test
index c608abfe57e71dfe50cda5c527f1c3ba3e2ac0ef..e877df34f4923755070bd8c7462e4d9a5be18f3a 100644 (file)
@@ -28,11 +28,11 @@ import org.sonar.api.config.EmailSettings;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.notifications.Notification;
 import org.sonar.db.DbTester;
+import org.sonar.db.user.UserDto;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.api.CoreProperties.SERVER_BASE_URL;
-import static org.sonar.db.user.UserTesting.newUserDto;
 
 public class IssueChangesEmailTemplateTest {
 
@@ -166,26 +166,26 @@ public class IssueChangesEmailTemplateTest {
 
   @Test
   public void notification_sender_should_be_the_author_of_change() {
-    db.users().insertUser(newUserDto().setLogin("simon").setName("Simon"));
+    UserDto user = db.users().insertUser();
 
     Notification notification = new IssueChangeNotification()
-      .setChangeAuthorLogin("simon")
+      .setChangeAuthor(user)
       .setProject("Struts", "org.apache:struts", null, null);
 
     EmailMessage message = underTest.format(notification);
-    assertThat(message.getFrom()).isEqualTo("Simon");
+    assertThat(message.getFrom()).isEqualTo(user.getName());
   }
 
   @Test
   public void notification_contains_user_login_when_user_is_removed() {
-    db.users().insertUser(newUserDto().setLogin("simon").setName("Simon").setActive(false));
+    UserDto user = db.users().insertDisabledUser();
 
     Notification notification = new IssueChangeNotification()
-      .setChangeAuthorLogin("simon")
+      .setChangeAuthor(user)
       .setProject("Struts", "org.apache:struts", null, null);
 
     EmailMessage message = underTest.format(notification);
-    assertThat(message.getFrom()).isEqualTo("simon");
+    assertThat(message.getFrom()).isEqualTo(user.getLogin());
   }
 
   private static Notification generateNotification() {
index 6f2a36b1a6c1c4c995a94f1acbf0fb871e191cd3..d3a7499eafb05b947f6fcb7db4b7fe3ae281394c 100644 (file)
@@ -118,7 +118,7 @@ public class AddCommentActionTest {
 
     IssueChangeDto issueComment = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbTester.getSession(), singletonList(issueDto.getKey()), TYPE_COMMENT).get(0);
     assertThat(issueComment.getKey()).isNotNull();
-    assertThat(issueComment.getUserLogin()).isEqualTo("john");
+    assertThat(issueComment.getUserUuid()).isEqualTo(userSession.getUuid());
     assertThat(issueComment.getChangeType()).isEqualTo(TYPE_COMMENT);
     assertThat(issueComment.getChangeData()).isEqualTo("please fix it");
     assertThat(issueComment.getCreatedAt()).isNotNull();
index 2c8a9e1bc7e1aa427e11c3db098c35e939813b17..82026b788c689a285fbdc4a03adcaeefc79f0761 100644 (file)
@@ -228,7 +228,7 @@ public class BulkChangeActionTest {
 
     checkResponse(response, 1, 1, 0, 0);
     IssueChangeDto issueComment = dbClient.issueChangeDao().selectByTypeAndIssueKeys(db.getSession(), singletonList(issueDto.getKey()), TYPE_COMMENT).get(0);
-    assertThat(issueComment.getUserLogin()).isEqualTo("john");
+    assertThat(issueComment.getUserUuid()).isEqualTo(user.getUuid());
     assertThat(issueComment.getChangeData()).isEqualTo("type was badly defined");
 
     verifyPostProcessorCalled(file);
@@ -237,7 +237,7 @@ public class BulkChangeActionTest {
   @Test
   public void bulk_change_many_issues() {
     setUserProjectPermissions(USER, ISSUE_ADMIN);
-    UserDto userToAssign = db.users().insertUser("arthur");
+    UserDto userToAssign = db.users().insertUser();
     db.organizations().addMember(organization, user);
     db.organizations().addMember(organization, userToAssign);
     IssueDto issue1 = db.issues().insertIssue(newUnresolvedIssue().setAssigneeUuid(user.getUuid())).setType(BUG).setSeverity(MINOR);
index fba14ca2723bdc19c10285a1731c6fa62a1d1eb7..f4463790ac3b4c25f9bcc423e4f45916aeb1628b 100644 (file)
@@ -80,7 +80,7 @@ public class ChangelogActionTest {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -129,7 +129,7 @@ public class ChangelogActionTest {
     UserDto user = db.users().insertUser(UserTesting.newUserDto("john", "John", null));
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -143,7 +143,7 @@ public class ChangelogActionTest {
   public void return_changelog_not_having_user() {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(null).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(null).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -158,7 +158,7 @@ public class ChangelogActionTest {
   public void return_changelog_on_none_existing_user() {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin("UNKNOWN").setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid("UNKNOWN").setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -174,7 +174,7 @@ public class ChangelogActionTest {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin())
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid())
       .setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date())
       .setDiff("status", "RESOLVED", "CLOSED").setCreationDate(new Date()));
 
@@ -190,7 +190,7 @@ public class ChangelogActionTest {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", null, "BLOCKER").setCreationDate(new Date()));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", null, "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -203,7 +203,7 @@ public class ChangelogActionTest {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", null).setCreationDate(new Date()));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", "MAJOR", null).setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -217,7 +217,7 @@ public class ChangelogActionTest {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto,
-      new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()),
+      new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()),
       new FieldDiffs().setDiff("status", "RESOLVED", "CLOSED").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -230,7 +230,7 @@ public class ChangelogActionTest {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("technicalDebt", "10", "20").setCreationDate(new Date()));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("technicalDebt", "10", "20").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -263,7 +263,7 @@ public class ChangelogActionTest {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs()
-      .setUserLogin(user.getLogin())
+      .setUserUuid(user.getUuid())
       .setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date())
       .setCreationDate(DateUtils.parseDateTime("2014-03-04T23:03:44+0100")));
 
index d997549dea952434979b98bcd66499570a992650..db0ad0afa1603a9f00c8d9438f701bf50ac2eb72 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueDbTester;
 import org.sonar.db.issue.IssueDto;
+import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.exceptions.UnauthorizedException;
@@ -70,8 +71,9 @@ public class DeleteCommentActionTest {
   @Test
   public void delete_comment() {
     IssueDto issueDto = issueDbTester.insertIssue();
-    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    loginAndAddProjectPermission("john", issueDto, USER);
+    UserDto user = dbTester.users().insertUser();
+    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+    loginAndAddProjectPermission(user, issueDto, USER);
 
     call(commentDto.getKey());
 
@@ -83,8 +85,9 @@ public class DeleteCommentActionTest {
   @Test
   public void delete_comment_using_deprecated_key_parameter() {
     IssueDto issueDto = issueDbTester.insertIssue();
-    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    loginAndAddProjectPermission("john", issueDto, USER);
+    UserDto user = dbTester.users().insertUser();
+    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+    loginAndAddProjectPermission(user, issueDto, USER);
 
     tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute();
 
@@ -96,8 +99,10 @@ public class DeleteCommentActionTest {
   @Test
   public void fail_when_comment_does_not_belong_to_current_user() {
     IssueDto issueDto = issueDbTester.insertIssue();
-    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    loginAndAddProjectPermission("another", issueDto, USER);
+    UserDto user = dbTester.users().insertUser();
+    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+    UserDto another = dbTester.users().insertUser();
+    loginAndAddProjectPermission(another, issueDto, USER);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("You can only delete your own comments");
@@ -107,8 +112,9 @@ public class DeleteCommentActionTest {
   @Test
   public void fail_when_comment_has_not_user() {
     IssueDto issueDto = issueDbTester.insertIssue();
+    UserDto user = dbTester.users().insertUser();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, null, "please fix it");
-    loginAndAddProjectPermission("john", issueDto, USER);
+    loginAndAddProjectPermission(user, issueDto, USER);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("You can only delete your own comments");
@@ -140,8 +146,9 @@ public class DeleteCommentActionTest {
   @Test
   public void fail_when_not_enough_permission() {
     IssueDto issueDto = issueDbTester.insertIssue();
-    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    loginAndAddProjectPermission("john", issueDto, CODEVIEWER);
+    UserDto user = dbTester.users().insertUser();
+    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+    loginAndAddProjectPermission(user, issueDto, CODEVIEWER);
 
     expectedException.expect(ForbiddenException.class);
     call(commentDto.getKey());
@@ -172,8 +179,8 @@ public class DeleteCommentActionTest {
     return request.execute();
   }
 
-  private void loginAndAddProjectPermission(String login, IssueDto issueDto, String permission) {
-    userSession.logIn(login).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
+  private void loginAndAddProjectPermission(UserDto user, IssueDto issueDto, String permission) {
+    userSession.logIn(user).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
   }
 
 }
index 11e7993e933096678b6135b0c5dd11da76909320..b18df676e52b52dd709d6fd93ed7a94dcde5b325 100644 (file)
@@ -34,6 +34,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueDbTester;
 import org.sonar.db.issue.IssueDto;
+import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.exceptions.UnauthorizedException;
@@ -81,8 +82,9 @@ public class EditCommentActionTest {
   @Test
   public void edit_comment() {
     IssueDto issueDto = issueDbTester.insertIssue();
-    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    loginWithBrowsePermission("john", USER, issueDto);
+    UserDto user = dbTester.users().insertUser();
+    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+    loginWithBrowsePermission(user, USER, issueDto);
 
     call(commentDto.getKey(), "please have a look");
 
@@ -97,8 +99,9 @@ public class EditCommentActionTest {
   @Test
   public void edit_comment_using_deprecated_key_parameter() {
     IssueDto issueDto = issueDbTester.insertIssue();
-    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    loginWithBrowsePermission("john", USER, issueDto);
+    UserDto user = dbTester.users().insertUser();
+    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+    loginWithBrowsePermission(user, USER, issueDto);
 
     tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute();
 
@@ -113,8 +116,10 @@ public class EditCommentActionTest {
   @Test
   public void fail_when_comment_does_not_belong_to_current_user() {
     IssueDto issueDto = issueDbTester.insertIssue();
-    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    loginWithBrowsePermission("another", USER, issueDto);
+    UserDto user = dbTester.users().insertUser();
+    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+    UserDto another = dbTester.users().insertUser();
+    loginWithBrowsePermission(another, USER, issueDto);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("You can only edit your own comments");
@@ -124,8 +129,9 @@ public class EditCommentActionTest {
   @Test
   public void fail_when_comment_has_not_user() {
     IssueDto issueDto = issueDbTester.insertIssue();
+    UserDto user = dbTester.users().insertUser();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, null, "please fix it");
-    loginWithBrowsePermission("john", USER, issueDto);
+    loginWithBrowsePermission(user, USER, issueDto);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("You can only edit your own comments");
@@ -159,8 +165,9 @@ public class EditCommentActionTest {
   @Test
   public void fail_when_empty_comment_text() {
     IssueDto issueDto = issueDbTester.insertIssue();
-    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    loginWithBrowsePermission("john", USER, issueDto);
+    UserDto user = dbTester.users().insertUser();
+    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+    loginWithBrowsePermission(user, USER, issueDto);
 
     expectedException.expect(IllegalArgumentException.class);
     call(commentDto.getKey(), "");
@@ -175,8 +182,9 @@ public class EditCommentActionTest {
   @Test
   public void fail_when_not_enough_permission() {
     IssueDto issueDto = issueDbTester.insertIssue();
-    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    loginWithBrowsePermission("john", CODEVIEWER, issueDto);
+    UserDto user = dbTester.users().insertUser();
+    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+    loginWithBrowsePermission(user, CODEVIEWER, issueDto);
 
     expectedException.expect(ForbiddenException.class);
     call(commentDto.getKey(), "please have a look");
@@ -199,8 +207,8 @@ public class EditCommentActionTest {
     return request.execute();
   }
 
-  private void loginWithBrowsePermission(String login, String permission, IssueDto issueDto) {
-    userSession.logIn(login).addProjectPermission(permission,
+  private void loginWithBrowsePermission(UserDto user, String permission, IssueDto issueDto) {
+    userSession.logIn(user).addProjectPermission(permission,
       dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get(),
       dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getComponentUuid()).get());
   }
index 4cce3afeee3d28db25dda71346f5dc868865dcd3..f5bd488fbc487f21da23daab9632b8dcff70819b 100644 (file)
@@ -24,11 +24,9 @@ import com.google.gson.JsonParser;
 import java.time.Clock;
 import java.util.Arrays;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.issue.Issue;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.server.ws.WebService;
@@ -287,7 +285,6 @@ public class SearchActionTest {
   }
 
   @Test
-  @Ignore // TODO GJT when adressing ticket on IssueChangesUuid
   public void issue_with_comments() {
     UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John"));
     UserDto fabrice = db.users().insertUser(u -> u.setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
@@ -304,14 +301,14 @@ public class SearchActionTest {
         .setKey("COMMENT-ABCD")
         .setChangeData("*My comment*")
         .setChangeType(IssueChangeDto.TYPE_COMMENT)
-        .setUserLogin(john.getUuid())
+        .setUserUuid(john.getUuid())
         .setIssueChangeCreationDate(DateUtils.parseDateTime("2014-09-09T12:00:00+0000").getTime()));
     dbClient.issueChangeDao().insert(session,
       new IssueChangeDto().setIssueKey(issue.getKey())
         .setKey("COMMENT-ABCE")
         .setChangeData("Another comment")
         .setChangeType(IssueChangeDto.TYPE_COMMENT)
-        .setUserLogin(fabrice.getUuid())
+        .setUserUuid(fabrice.getUuid())
         .setIssueChangeCreationDate(DateUtils.parseDateTime("2014-09-10T12:00:00+0000").getTime()));
     session.commit();
     indexIssues();
@@ -325,8 +322,8 @@ public class SearchActionTest {
 
   @Test
   public void issue_with_comment_hidden() {
-    db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com"));
-    db.users().insertUser(u -> u.setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
+    UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com"));
+    UserDto fabrice = db.users().insertUser(u -> u.setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
 
     ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization1, "PROJECT_ID").setDbKey("PROJECT_KEY"));
     indexPermissions();
@@ -340,22 +337,22 @@ public class SearchActionTest {
         .setKey("COMMENT-ABCD")
         .setChangeData("*My comment*")
         .setChangeType(IssueChangeDto.TYPE_COMMENT)
-        .setUserLogin("john")
+        .setUserUuid(john.getUuid())
         .setCreatedAt(DateUtils.parseDateTime("2014-09-09T12:00:00+0000").getTime()));
     dbClient.issueChangeDao().insert(session,
       new IssueChangeDto().setIssueKey(issue.getKey())
         .setKey("COMMENT-ABCE")
         .setChangeData("Another comment")
         .setChangeType(IssueChangeDto.TYPE_COMMENT)
-        .setUserLogin("fabrice")
+        .setUserUuid(fabrice.getUuid())
         .setCreatedAt(DateUtils.parseDateTime("2014-09-10T19:10:03+0000").getTime()));
     session.commit();
     indexIssues();
 
-    userSessionRule.logIn("john");
+    userSessionRule.logIn(john);
     TestResponse result = ws.newRequest().setParam(PARAM_HIDE_COMMENTS, "true").execute();
     result.assertJson(this.getClass(), "issue_with_comment_hidden.json");
-    assertThat(result.getInput()).doesNotContain("fabrice");
+    assertThat(result.getInput()).doesNotContain(fabrice.getLogin());
   }
 
   @Test
index 8c8a93cbd13a57641eb9d7e4f70e9a16dcad3231..5bf22423c314ec6fef2ec395c4b34f81a07abe2f 100644 (file)
@@ -23,7 +23,7 @@
           issue_type="2"
     />
 
-  <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik"
+  <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="user_uuid"
                  change_data="the comment"
                  created_at="[null]" updated_at="[null]" issue_change_creation_date="[null]"/>
 
index 1a8a5607b7f32c94692a26d76a1be6d484aef477..0a39d215e77254a0df40c248ef18fed82dfc774d 100644 (file)
@@ -28,9 +28,9 @@
           issue_type="2"
     />
 
-  <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik"
+  <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="user_uuid"
                  change_data="the comment" created_at="[null]" updated_at="[null]" issue_change_creation_date="[null]"/>
-  <issue_changes id="2" kee="[null]" issue_key="ABCDE" change_type="diff" user_login="emmerik"
+  <issue_changes id="2" kee="[null]" issue_key="ABCDE" change_type="diff" user_login="user_uuid"
                  change_data="severity=INFO|BLOCKER" created_at="[null]" updated_at="[null]"
                  issue_change_creation_date="[null]"/>
 </dataset>
index 71d96ca788d9ff5ff51010e0783431ccc17810f8..cb2f3324eed83563a4a4a7d2eee71f551b9315f4 100644 (file)
@@ -23,7 +23,7 @@
           issue_type="2"
       />
 
-  <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik"
+  <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="user_uuid"
                  change_data="the comment"
                  created_at="[null]" updated_at="[null]" issue_change_creation_date="[null]"/>
 
index 964df64e069edeeab611b0c8f8331a84bcc78296..3c0d6b1ed417fc9c63ecb7c7fb35daaf7b9d5f53 100644 (file)
@@ -32,7 +32,7 @@
                  kee="FGHIJ"
                  issue_key="ABCDE"
                  change_type="comment"
-                 user_login="emmerik"
+                 user_login="user_uuid"
                  change_data="the comment"
                  created_at="[null]"
                  updated_at="[null]"
@@ -41,7 +41,7 @@
                  kee="[null]"
                  issue_key="ABCDE"
                  change_type="diff"
-                 user_login="emmerik"
+                 user_login="user_uuid"
                  change_data="severity=INFO|BLOCKER"
                  created_at="[null]"
                  updated_at="[null]"
index 205ac39dff857fcd5b5f936a963ceda55732419b..f74bcb71e1ec7221a974ebe18c05013498e696e4 100644 (file)
@@ -77,7 +77,7 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure.
   private String checksum;
   private Map<String, String> attributes = null;
   private String authorLogin = null;
-  private List<IssueComment> comments = null;
+  private List<DefaultIssueComment> comments = null;
   private Set<String> tags = null;
   // temporarily an Object as long as DefaultIssue is used by sonar-batch
   private Object locations = null;
@@ -528,7 +528,7 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure.
     if (!Objects.equals(oldValue, newValue)) {
       if (currentChange == null) {
         currentChange = new FieldDiffs();
-        currentChange.setUserLogin(context.login());
+        currentChange.setUserUuid(context.userUuid());
         currentChange.setCreationDate(context.date());
       }
       currentChange.setDiff(field, oldValue, newValue);
@@ -576,8 +576,16 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure.
     return this;
   }
 
+  /**
+   * @deprecated since 7.2, comments are not more available
+   */
   @Override
+  @Deprecated
   public List<IssueComment> comments() {
+    return Collections.emptyList();
+  }
+
+  public List<DefaultIssueComment> defaultIssueComments() {
     if (comments == null) {
       return Collections.emptyList();
     }
index 421ceb2abda3b23eac3267dbfb30194209f21454..5cc9859852492a4b2752425e42c3ade3345ee1f2 100644 (file)
@@ -23,37 +23,35 @@ import java.io.Serializable;
 import java.util.Date;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import org.sonar.api.issue.IssueComment;
 import org.sonar.core.util.Uuids;
 
 /**
- * PLUGINS MUST NOT BE USED THIS CLASS, EXCEPT FOR UNIT TESTING.
+ * PLUGINS MUST NOT BE USED THIS CLASS
  *
  * @since 3.6
  */
-public class DefaultIssueComment implements Serializable, IssueComment {
+public class DefaultIssueComment implements Serializable {
 
   private String issueKey;
-  private String userLogin;
+  private String userUuid;
   private Date createdAt;
   private Date updatedAt;
   private String key;
   private String markdownText;
   private boolean isNew;
 
-  public static DefaultIssueComment create(String issueKey, @Nullable String login, String markdownText) {
+  public static DefaultIssueComment create(String issueKey, @Nullable String userUuid, String markdownText) {
     DefaultIssueComment comment = new DefaultIssueComment();
     comment.setIssueKey(issueKey);
     comment.setKey(Uuids.create());
     Date now = new Date();
-    comment.setUserLogin(login);
+    comment.setUserUuid(userUuid);
     comment.setMarkdownText(markdownText);
     comment.setCreatedAt(now).setUpdatedAt(now);
     comment.setNew(true);
     return comment;
   }
 
-  @Override
   public String markdownText() {
     return markdownText;
   }
@@ -63,7 +61,6 @@ public class DefaultIssueComment implements Serializable, IssueComment {
     return this;
   }
 
-  @Override
   public String issueKey() {
     return issueKey;
   }
@@ -73,7 +70,6 @@ public class DefaultIssueComment implements Serializable, IssueComment {
     return this;
   }
 
-  @Override
   public String key() {
     return key;
   }
@@ -84,20 +80,18 @@ public class DefaultIssueComment implements Serializable, IssueComment {
   }
 
   /**
-   * The user who created the comment. Null if it was automatically generated during project scan.
+   * The user uuid who created the comment. Null if it was automatically generated during project scan.
    */
-  @Override
   @CheckForNull
-  public String userLogin() {
-    return userLogin;
+  public String userUuid() {
+    return userUuid;
   }
 
-  public DefaultIssueComment setUserLogin(@Nullable String userLogin) {
-    this.userLogin = userLogin;
+  public DefaultIssueComment setUserUuid(@Nullable String userUuid) {
+    this.userUuid = userUuid;
     return this;
   }
 
-  @Override
   public Date createdAt() {
     return createdAt;
   }
@@ -107,7 +101,6 @@ public class DefaultIssueComment implements Serializable, IssueComment {
     return this;
   }
 
-  @Override
   public Date updatedAt() {
     return updatedAt;
   }
index be509ecc2f4bf2556b38197d249ec09875378919..a5e23f42689fa7eb94c3e5ce75a0b8a2aa8888cd 100644 (file)
@@ -40,7 +40,7 @@ public class FieldDiffs implements Serializable {
   public static final Splitter FIELDS_SPLITTER = Splitter.on(',').omitEmptyStrings();
 
   private String issueKey;
-  private String userLogin;
+  private String userUuid;
   private Date creationDate;
 
   private final Map<String, Diff> diffs = Maps.newLinkedHashMap();
@@ -54,12 +54,12 @@ public class FieldDiffs implements Serializable {
   }
 
   @CheckForNull
-  public String userLogin() {
-    return userLogin;
+  public String userUuid() {
+    return userUuid;
   }
 
-  public FieldDiffs setUserLogin(@Nullable String s) {
-    this.userLogin = s;
+  public FieldDiffs setUserUuid(@Nullable String s) {
+    this.userUuid = s;
     return this;
   }
 
index 702462c9f8e939f77f15c0da2fd0e52e3f8f3add..9760bc7f7fa852ada21dd02ceb746db27a9f1581 100644 (file)
@@ -27,19 +27,19 @@ import javax.annotation.Nullable;
 
 public class IssueChangeContext implements Serializable {
 
-  private final String login;
+  private final String userUuid;
   private final Date date;
   private final boolean scan;
 
-  private IssueChangeContext(@Nullable String login, Date date, boolean scan) {
-    this.login = login;
+  private IssueChangeContext(@Nullable String userUuid, Date date, boolean scan) {
+    this.userUuid = userUuid;
     this.date = date;
     this.scan = scan;
   }
 
   @CheckForNull
-  public String login() {
-    return login;
+  public String userUuid() {
+    return userUuid;
   }
 
   public Date date() {
@@ -54,8 +54,8 @@ public class IssueChangeContext implements Serializable {
     return new IssueChangeContext(null, date, true);
   }
 
-  public static IssueChangeContext createUser(Date date, @Nullable String login) {
-    return new IssueChangeContext(login, date, false);
+  public static IssueChangeContext createUser(Date date, @Nullable String userUuid) {
+    return new IssueChangeContext(userUuid, date, false);
   }
 
   @Override
@@ -68,19 +68,19 @@ public class IssueChangeContext implements Serializable {
     }
     IssueChangeContext that = (IssueChangeContext) o;
     return scan == that.scan &&
-      Objects.equals(login, that.login) &&
+      Objects.equals(userUuid, that.userUuid) &&
       Objects.equals(date, that.date);
   }
 
   @Override
   public int hashCode() {
-    return Objects.hash(login, date, scan);
+    return Objects.hash(userUuid, date, scan);
   }
 
   @Override
   public String toString() {
     return "IssueChangeContext{" +
-      "login='" + login + '\'' +
+      "userUuid='" + userUuid + '\'' +
       ", date=" + date +
       ", scan=" + scan +
       '}';
index 08df314980e94a8d51b5bd7637f9cf561a68dca9..01d8ad8b04c0bc1f36e8e5b7d14df863e908cfe3 100644 (file)
@@ -25,7 +25,6 @@ import java.util.List;
 import org.apache.commons.lang.StringUtils;
 import org.junit.Test;
 import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.IssueComment;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.utils.Duration;
 
@@ -110,7 +109,7 @@ public class DefaultIssueTest {
   }
 
   @Test
-  public void test_attributes() throws Exception {
+  public void test_attributes() {
     assertThat(issue.attribute("foo")).isNull();
     issue.setAttribute("foo", "bar");
     assertThat(issue.attribute("foo")).isEqualTo("bar");
@@ -171,7 +170,7 @@ public class DefaultIssueTest {
   }
 
   @Test
-  public void test_nullable_fields() throws Exception {
+  public void test_nullable_fields() {
     issue.setGap(null).setSeverity(null).setLine(null);
     assertThat(issue.gap()).isNull();
     assertThat(issue.severity()).isNull();
@@ -179,7 +178,7 @@ public class DefaultIssueTest {
   }
 
   @Test
-  public void test_equals_and_hashCode() throws Exception {
+  public void test_equals_and_hashCode() {
     DefaultIssue a1 = new DefaultIssue().setKey("AAA");
     DefaultIssue a2 = new DefaultIssue().setKey("AAA");
     DefaultIssue b = new DefaultIssue().setKey("BBB");
@@ -193,7 +192,7 @@ public class DefaultIssueTest {
   public void comments_should_not_be_modifiable() {
     DefaultIssue issue = new DefaultIssue().setKey("AAA");
 
-    List<IssueComment> comments = issue.comments();
+    List<DefaultIssueComment> comments = issue.defaultIssueComments();
     assertThat(comments).isEmpty();
 
     try {
index a4888fa93ef79fa77e91f94c0988ff8d31a10690..a3cb528ad498dcdd2fa56c2fbb37757e77af26c9 100644 (file)
@@ -26,22 +26,22 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class IssueChangeContextTest {
   @Test
-  public void test_scan_context() throws Exception {
+  public void test_scan_context() {
     Date now = new Date();
     IssueChangeContext context = IssueChangeContext.createScan(now);
 
     assertThat(context.scan()).isTrue();
-    assertThat(context.login()).isNull();
+    assertThat(context.userUuid()).isNull();
     assertThat(context.date()).isEqualTo(now);
   }
 
   @Test
-  public void test_end_user_context() throws Exception {
+  public void test_end_user_context() {
     Date now = new Date();
-    IssueChangeContext context = IssueChangeContext.createUser(now, "emmerik");
+    IssueChangeContext context = IssueChangeContext.createUser(now, "user_uuid");
 
     assertThat(context.scan()).isFalse();
-    assertThat(context.login()).isEqualTo("emmerik");
+    assertThat(context.userUuid()).isEqualTo("user_uuid");
     assertThat(context.date()).isEqualTo(now);
   }
 }
index e9ac390fb393c68a87b883f71d08196e495fe40f..c7326428d4d5a90b271d08c108839431771f0156 100644 (file)
@@ -196,7 +196,10 @@ public interface Issue extends Serializable {
    * <br>
    * IMPORTANT: existing comments are not loaded when this method is called when analyzing project
    * (from {@link ScannerSide}).
+   *
+   * @deprecated since 7.2, comments are not more available
    */
+  @Deprecated
   List<IssueComment> comments();
 
   /**
index 7126a5e417085260bfbba90d19868d289911c192..3e2e17722d9cdfd71fb2a7ebb3c47e2b390e4b06 100644 (file)
  */
 package org.sonar.api.issue;
 
-import javax.annotation.CheckForNull;
 import java.util.Date;
+import javax.annotation.CheckForNull;
 
+/**
+ * @deprecated since 7.2, comments are no more available
+ */
+@Deprecated
 public interface IssueComment {
   String markdownText();
 
index a562571526542da99954d9364bd6bff2b956e971..42321b9eeb1ff337050a5fc5e64d4fbdd3287ef0 100644 (file)
@@ -21,7 +21,6 @@ package org.sonarqube.tests.issue;
 
 import java.util.List;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.sonar.wsclient.issue.Issue;
 import org.sonarqube.ws.Issues;
@@ -49,7 +48,6 @@ public class IssueChangelogTest extends AbstractIssueTest {
   }
 
   @Test
-  @Ignore // TODO GJT when adressing ticket on IssueChangesUuid
   public void update_changelog_when_assigning_issue_by_user() {
     runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");
     Issue issue = searchRandomIssue();
index 2b61896692b210e0795c28a2c456551b1a6d6bff..fd4cd4841b2783da8c62d52f393c8963dc382046 100644 (file)
@@ -31,7 +31,6 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.ClassRule;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonarqube.qa.util.Tester;
@@ -118,7 +117,6 @@ public class IssueNotificationsTest {
   }
 
   @Test
-  @Ignore // TODO GJT when adressing ticket on IssueChangesUuid
   public void notification_for_ChangesOnMyIssue() throws Exception {
     String version = RandomStringUtils.randomAlphanumeric(10);
     Project project = tester.projects().provision();
index 9240e14e0a5e66ce7085065a3b01d29ba941bfdf..0ac38f659aabb36c92961cc7da299faac60a2451 100644 (file)
@@ -32,7 +32,6 @@ import org.junit.Test;
 import org.sonarqube.qa.util.Tester;
 import org.sonarqube.qa.util.TesterSession;
 import org.sonarqube.ws.Ce;
-import org.sonarqube.ws.Issues;
 import org.sonarqube.ws.Issues.Issue;
 import org.sonarqube.ws.Organizations.Organization;
 import org.sonarqube.ws.Projects;
@@ -47,6 +46,7 @@ import org.sonarqube.ws.client.WsClient;
 import org.sonarqube.ws.client.ce.ActivityRequest;
 import org.sonarqube.ws.client.ce.TaskRequest;
 import org.sonarqube.ws.client.custommeasures.CreateRequest;
+import org.sonarqube.ws.client.issues.AddCommentRequest;
 import org.sonarqube.ws.client.issues.AssignRequest;
 import org.sonarqube.ws.client.organizations.AddMemberRequest;
 import org.sonarqube.ws.client.organizations.SearchRequest;
@@ -136,30 +136,68 @@ public class SonarCloudUpdateLoginDuringAuthenticationTest {
     String oldLogin = tester.users().generateLogin();
     String providerId = tester.users().generateProviderId();
 
-    // Create user using authentication
+    // Create user using authentication, and set user as member of the organization
     authenticate(oldLogin, providerId);
-
-    // Set user as member of the organization
     Organization organization = tester.organizations().generate();
     tester.organizations().service().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(oldLogin));
+
+    // Execute analysis and assign an issue to the user
     Projects.CreateWsResponse.Project project = tester.projects().provision(organization);
     Qualityprofiles.CreateWsResponse.QualityProfile profile = tester.qProfiles().createXooProfile(organization);
     tester.qProfiles().assignQProfileToProject(profile, project);
     tester.qProfiles().activateRule(profile.getKey(), "xoo:OneIssuePerLine");
-
-    // Execute project and assignee an issue to the user
     orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"),
       "sonar.organization", organization.getKey(),
       "sonar.projectKey", project.getKey(),
       "sonar.login", "admin",
       "sonar.password", "admin"));
-    Issues.Issue issue = tester.wsClient().issues().search(new org.sonarqube.ws.client.issues.SearchRequest().setOrganization(organization.getKey())).getIssuesList().get(0);
+    Issue issue = tester.wsClient().issues().search(new org.sonarqube.ws.client.issues.SearchRequest().setOrganization(organization.getKey())).getIssuesList().get(0);
     tester.wsClient().issues().assign(new AssignRequest().setIssue(issue.getKey()).setAssignee(oldLogin));
+    assertThat(getIssue(organization, issue.getKey()).getAssignee()).isEqualTo(oldLogin);
 
     // Update login during authentication, check issue is assigned to new login
     String newLogin = tester.users().generateLogin();
     authenticate(newLogin, providerId);
-    tester.wsClient().issues().assign(new AssignRequest().setIssue(issue.getKey()).setAssignee(newLogin));
+    assertThat(getIssue(organization, issue.getKey()).getAssignee()).isEqualTo(newLogin);
+  }
+
+  @Test
+  public void issue_changes_after_login_update() {
+    String oldLogin = tester.users().generateLogin();
+    String providerId = tester.users().generateProviderId();
+
+    // Create user using authentication
+    authenticate(oldLogin, providerId);
+    Organization organization = tester.organizations().generate();
+    tester.organizations().service().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(oldLogin));
+    String userToken = tester.wsClient().userTokens().generate(new GenerateRequest().setLogin(oldLogin).setName("token")).getToken();
+    WsClient userWsClient = tester.as(userToken, null).wsClient();
+
+    // Execute analysis, then the user assign an issue to himself and add a comment
+    Projects.CreateWsResponse.Project project = tester.projects().provision(organization);
+    Qualityprofiles.CreateWsResponse.QualityProfile profile = tester.qProfiles().createXooProfile(organization);
+    tester.qProfiles().assignQProfileToProject(profile, project);
+    tester.qProfiles().activateRule(profile.getKey(), "xoo:OneIssuePerLine");
+    orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"),
+      "sonar.organization", organization.getKey(),
+      "sonar.projectKey", project.getKey(),
+      "sonar.login", "admin",
+      "sonar.password", "admin"));
+    Issue issue = tester.wsClient().issues().search(new org.sonarqube.ws.client.issues.SearchRequest().setOrganization(organization.getKey())).getIssuesList().get(0);
+    userWsClient.issues().assign(new AssignRequest().setIssue(issue.getKey()).setAssignee(oldLogin));
+    userWsClient.issues().addComment(new AddCommentRequest().setIssue(issue.getKey()).setText("some comment"));
+
+    // Comment and changelog contain old login
+    assertThat(getIssue(organization, issue.getKey()).getComments().getComments(0).getLogin()).isEqualTo(oldLogin);
+    assertThat(tester.wsClient().issues().changelog(new org.sonarqube.ws.client.issues.ChangelogRequest().setIssue(issue.getKey()))
+      .getChangelog(0).getUser()).isEqualTo(oldLogin);
+
+    // Update login during authentication, check comment and issue changelog contain new login
+    String newLogin = tester.users().generateLogin();
+    authenticate(newLogin, providerId);
+    assertThat(getIssue(organization, issue.getKey()).getComments().getComments(0).getLogin()).isEqualTo(newLogin);
+    assertThat(tester.wsClient().issues().changelog(new org.sonarqube.ws.client.issues.ChangelogRequest().setIssue(issue.getKey()))
+      .getChangelog(0).getUser()).isEqualTo(newLogin);
   }
 
   @Test