aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2018-05-11 11:06:31 +0200
committerSonarTech <sonartech@sonarsource.com>2018-05-23 20:20:48 +0200
commit4ff1b9f90fe7b7a695b8059357e97e69419fc36c (patch)
tree1f2b56499e3883d0c31b82b42f8d01da8bb8d939
parent67012b8a06c3d2c929eb7c4391f5fa25368ee75b (diff)
downloadsonarqube-4ff1b9f90fe7b7a695b8059357e97e69419fc36c.tar.gz
sonarqube-4ff1b9f90fe7b7a695b8059357e97e69419fc36c.zip
SONAR-10597 Update ISSUE_CHANGE#USER_LOGIN to USER_UUID
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java5
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java21
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java13
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml13
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java11
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java133
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java28
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDbTester.java41
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete-result.xml42
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete.xml38
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/empty.xml3
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/insert-result.xml15
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/selectChangelogOfNonClosedIssuesByComponent.xml186
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/shared.xml63
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update-result.xml38
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update.xml38
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_comment-result.xml2
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_diff-result.xml2
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml2
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml2
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues-result.xml4
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues.xml10
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml6
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues.xml10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java7
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/IssueStorage.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java19
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java7
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java15
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java42
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ShortBranchIssueMergerTest.java9
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest.java20
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java20
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java40
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java121
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/TransitionServiceTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java14
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java20
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/DeleteCommentActionTest.java29
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/EditCommentActionTest.java34
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java19
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_insert_new_issues-result.xml2
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_update_issues-result.xml4
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml2
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java12
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java27
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java10
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/IssueChangeContext.java20
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java9
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/IssueChangeContextTest.java10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueComment.java6
-rw-r--r--tests/src/test/java/org/sonarqube/tests/issue/IssueChangelogTest.java2
-rw-r--r--tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java2
-rw-r--r--tests/src/test/java/org/sonarqube/tests/user/SonarCloudUpdateLoginDuringAuthenticationTest.java54
82 files changed, 551 insertions, 875 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
index e5dfb2a5dfa..c77a5f650f9 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -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));
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java
index fa97adf11cd..8787c9ca930 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java
@@ -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));
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java
index b3af27e7373..5c8dd1aa94f 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java
@@ -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);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java
index b6216a313f1..b176704c672 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java
@@ -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);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
index 6f03a04bdaf..7eaebeb4eb5 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
@@ -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(...)
*/
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
index 8b315466eb7..6733ce22e82 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
@@ -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>
@@ -68,14 +68,5 @@
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>
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index caeeb7dee17..191e803eb7b 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -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
@@ -360,15 +360,6 @@ public class ComponentDaoTest {
}
@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();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
index 5f9143541f9..5eec49b95bc 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
@@ -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()));
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java
index baeb22ac973..3f7059fbc3d 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java
@@ -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");
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
index a62605aca97..e446629b728 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
@@ -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");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDbTester.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDbTester.java
index 92f5b940af2..4d02ac3cac4 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDbTester.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDbTester.java
@@ -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
index be1549d36f1..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete-result.xml
+++ /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
index 3277acb54ca..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/delete.xml
+++ /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
index 871dedcb5e9..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/empty.xml
+++ /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
index 06468bff8a8..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/insert-result.xml
+++ /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
index efb08c7ae4f..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/selectChangelogOfNonClosedIssuesByComponent.xml
+++ /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
index 0b181deb146..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/shared.xml
+++ /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
index a1c436a6622..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update-result.xml
+++ /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
index 641f333faa3..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeDaoTest/update.xml
+++ /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>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_comment-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_comment-result.xml
index f319c034856..0dca8fdc4aa 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_comment-result.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_comment-result.xml
@@ -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"
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_diff-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_diff-result.xml
index bbc0741292f..08dd09684b4 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_diff-result.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_diff-result.xml
@@ -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"
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml
index ba8ac69dff9..2b7cd7f7107 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml
@@ -110,7 +110,7 @@
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"/>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml
index 703004ce391..deb3b1511d6 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml
@@ -111,7 +111,7 @@
issue_key="ABCDF"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"/>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues-result.xml
index 2d594175e37..0722a360744 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues-result.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues-result.xml
@@ -107,7 +107,7 @@
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]"/>
@@ -145,7 +145,7 @@
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]"/>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues.xml
index 75014b07a85..cdb04fe8e7d 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_all_closed_issues.xml
@@ -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]"/>
@@ -115,7 +115,7 @@
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]"/>
@@ -153,7 +153,7 @@
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]"/>
@@ -190,7 +190,7 @@
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]"/>
@@ -226,7 +226,7 @@
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]"/>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml
index 694bfcc9688..d7c45fc5c19 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml
@@ -101,7 +101,7 @@
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]"/>
@@ -139,7 +139,7 @@
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]"/>
@@ -176,7 +176,7 @@
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]"/>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues.xml
index 4d97e9a281f..2d6ceed1865 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues.xml
@@ -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]"/>
@@ -113,7 +113,7 @@
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]"/>
@@ -151,7 +151,7 @@
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]"/>
@@ -188,7 +188,7 @@
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]"/>
@@ -224,7 +224,7 @@
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]"/>
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java
index 64787b0cd74..3bd8525c146 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java
@@ -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))
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java
index 8a59f881813..3e5b82b2772 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java
@@ -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);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueStorage.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueStorage.java
index 951042669f5..05fd5b6bbb3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueStorage.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueStorage.java
@@ -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);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java
index 86e24f47de3..8b04bb0ade5 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java
@@ -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();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java
index e0f3f5b0f04..2fe93c3f3eb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java
@@ -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;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java
index d501ed05426..4ebee503e87 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java
@@ -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);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java
index 58cb67b2c7f..ce8714515b8 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java
@@ -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);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
index 72636d07b1c..2be2da93a22 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
@@ -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())));
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java
index 906be52db21..e44be5866d7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java
@@ -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()));
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java
index 595ea923d73..98286f17349 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java
@@ -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() {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
index 08b1b8ec7f6..17c2e938dfb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
@@ -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);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java
index 1d3d402ab87..e6b3cb630fa 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java
@@ -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() {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
index b8d3f0857d5..6a876105946 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
@@ -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);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java
index d8dcb27143d..b5acc861c56 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java
@@ -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;
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
index 1afa8e91e29..4bfbc23ff8d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
@@ -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))
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
index 640081a5d68..e66f427cebb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
@@ -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) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java
index c1cd538704b..8d0e608c89e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java
@@ -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);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java
index 004e916a012..9df02691ca7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java
@@ -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);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
index d22d5fa26e0..241b6be963f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
@@ -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);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java
index d23c8478ef4..0b1780c9009 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java
index f36473f392e..b52486d250f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java
@@ -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();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ShortBranchIssueMergerTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ShortBranchIssueMergerTest.java
index e65ee68cc01..a171b7a932b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ShortBranchIssueMergerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ShortBranchIssueMergerTest.java
@@ -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();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest.java
index d25c96d6b20..c371f75e414 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest.java
@@ -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);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java
index a67cc18e6ef..c487abf6431 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java
@@ -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;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java
index 368fff1f6ae..1d9d4e86f1f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java
index 4c236bad09e..07d488e07af 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java
@@ -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 {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java
index 5b3183ff363..60b45778519 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java
@@ -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());
}
+
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java
index c4103cd7d2d..023420d92ad 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java
@@ -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");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java
index d2bb160c09a..bc5aedea1d1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java
index 3ef2c128707..fb9a41a2e88 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java
@@ -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();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java
index be31ef5a637..42a32d89672 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/TransitionServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/TransitionServiceTest.java
index 63b6c377bd7..a049b8638e6 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/TransitionServiceTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/TransitionServiceTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java
index 47150591a90..ba2a02cb201 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java
index c608abfe57e..e877df34f49 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java
@@ -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() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java
index 6f2a36b1a6c..d3a7499eafb 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java
@@ -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();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java
index 2c8a9e1bc7e..82026b788c6 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java
index fba14ca2723..f4463790ac3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java
@@ -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")));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DeleteCommentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DeleteCommentActionTest.java
index d997549dea9..db0ad0afa16 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DeleteCommentActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DeleteCommentActionTest.java
@@ -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());
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/EditCommentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/EditCommentActionTest.java
index 11e7993e933..b18df676e52 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/EditCommentActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/EditCommentActionTest.java
@@ -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());
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
index 4cce3afeee3..f5bd488fbc4 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
@@ -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
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_insert_new_issues-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_insert_new_issues-result.xml
index 8c8a93cbd13..5bf22423c31 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_insert_new_issues-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_insert_new_issues-result.xml
@@ -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]"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_update_issues-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_update_issues-result.xml
index 1a8a5607b7f..0a39d215e77 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_update_issues-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/IssueStorageTest/should_update_issues-result.xml
@@ -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>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml
index 71d96ca788d..cb2f3324eed 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml
@@ -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]"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml
index 964df64e069..3c0d6b1ed41 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml
@@ -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]"
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
index 205ac39dff8..f74bcb71e1e 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
@@ -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();
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java
index 421ceb2abda..5cc98598524 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java
@@ -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;
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java b/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java
index be509ecc2f4..a5e23f42689 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java
@@ -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;
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueChangeContext.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueChangeContext.java
index 702462c9f8e..9760bc7f7fa 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/IssueChangeContext.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueChangeContext.java
@@ -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 +
'}';
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
index 08df314980e..01d8ad8b04c 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
@@ -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 {
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueChangeContextTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueChangeContextTest.java
index a4888fa93ef..a3cb528ad49 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/IssueChangeContextTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueChangeContextTest.java
@@ -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);
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java
index e9ac390fb39..c7326428d4d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java
@@ -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();
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueComment.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueComment.java
index 7126a5e4170..3e2e17722d9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueComment.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueComment.java
@@ -19,9 +19,13 @@
*/
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();
diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueChangelogTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueChangelogTest.java
index a5625715265..42321b9eeb1 100644
--- a/tests/src/test/java/org/sonarqube/tests/issue/IssueChangelogTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueChangelogTest.java
@@ -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();
diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java
index 2b61896692b..fd4cd4841b2 100644
--- a/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java
@@ -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();
diff --git a/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUpdateLoginDuringAuthenticationTest.java b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUpdateLoginDuringAuthenticationTest.java
index 9240e14e0a5..0ac38f659aa 100644
--- a/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUpdateLoginDuringAuthenticationTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUpdateLoginDuringAuthenticationTest.java
@@ -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