]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9993 Functional creation date of comment is no more nullable
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 31 Oct 2017 10:08:55 +0000 (11:08 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 1 Nov 2017 07:28:17 +0000 (08:28 +0100)
 Old comments do not have functional creation date as this column has been added later

12 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_comment-result.xml
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/ShortBranchIssueMergerTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/add_change-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/add_comment-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/close_issue-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/insert_new_issue.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/shared.xml [deleted file]

index 53f2ebda604108c3d6072e0e90f8091041f8a5f9..0d9a822647bf9f30c342f32e4f77da18db32d929 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.core.issue.DefaultIssueComment;
 import org.sonar.core.issue.FieldDiffs;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.Objects.requireNonNull;
 
 /**
  * @since 3.6
@@ -51,6 +52,7 @@ public final class IssueChangeDto implements Serializable {
   private Long updatedAt;
 
   // functional date
+  @Nullable
   private Long issueChangeCreationDate;
 
   public static IssueChangeDto of(DefaultIssueComment comment) {
@@ -59,7 +61,8 @@ public final class IssueChangeDto implements Serializable {
     dto.setChangeType(IssueChangeDto.TYPE_COMMENT);
     dto.setChangeData(comment.markdownText());
     dto.setUserLogin(comment.userLogin());
-    dto.setIssueChangeCreationDate(comment.createdAt() == null ? null : comment.createdAt().getTime());
+    Date createdAt = requireNonNull(comment.createdAt(), "Comment created at must not be null");
+    dto.setIssueChangeCreationDate(createdAt.getTime());
     return dto;
   }
 
@@ -68,7 +71,8 @@ public final class IssueChangeDto implements Serializable {
     dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE);
     dto.setChangeData(diffs.toString());
     dto.setUserLogin(diffs.userLogin());
-    dto.setIssueChangeCreationDate(diffs.creationDate() == null ? null : diffs.creationDate().getTime());
+    Date createdAt = requireNonNull(diffs.creationDate(), "Diffs created at must not be null");
+    dto.setIssueChangeCreationDate(createdAt.getTime());
     return dto;
   }
 
@@ -157,10 +161,11 @@ public final class IssueChangeDto implements Serializable {
   }
 
   public Long getIssueChangeCreationDate() {
-    return issueChangeCreationDate;
+    // Old comments do not have functional creation date as this column has been added later
+    return issueChangeCreationDate == null ? createdAt : issueChangeCreationDate;
   }
 
-  public IssueChangeDto setIssueChangeCreationDate(@Nullable Long issueChangeCreationDate) {
+  public IssueChangeDto setIssueChangeCreationDate(long issueChangeCreationDate) {
     this.issueChangeCreationDate = issueChangeCreationDate;
     return this;
   }
@@ -174,7 +179,7 @@ public final class IssueChangeDto implements Serializable {
     return new DefaultIssueComment()
       .setMarkdownText(changeData)
       .setKey(kee)
-      .setCreatedAt(new Date(createdAt))
+      .setCreatedAt(new Date(getIssueChangeCreationDate()))
       .setUpdatedAt(updatedAt == null ? null : new Date(updatedAt))
       .setUserLogin(userLogin)
       .setIssueKey(issueKey)
@@ -184,8 +189,7 @@ public final class IssueChangeDto implements Serializable {
   public FieldDiffs toFieldDiffs() {
     return FieldDiffs.parse(changeData)
       .setUserLogin(userLogin)
-      // issueChangeCreationDate can be null as it has been introduced after createdAt
-      .setCreationDate(issueChangeCreationDate != null ? new Date(issueChangeCreationDate) : new Date(createdAt))
+      .setCreationDate(new Date(getIssueChangeCreationDate()))
       .setIssueKey(issueKey);
   }
 }
index bda52ad013268fa6198fa198b0978db579edee21..4465a3b1dc7b2dc3da59b0a21facde7a31d98c1f 100644 (file)
@@ -59,6 +59,7 @@ public class IssueChangeDtoTest {
     FieldDiffs diffs = new FieldDiffs();
     diffs.setDiff("severity", "INFO", "BLOCKER");
     diffs.setUserLogin("emmerik");
+    diffs.setCreationDate(parseDate("2015-01-13"));
 
     IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
 
@@ -66,9 +67,9 @@ public class IssueChangeDtoTest {
     assertThat(dto.getChangeType()).isEqualTo("diff");
     assertThat(dto.getCreatedAt()).isNotNull();
     assertThat(dto.getUpdatedAt()).isNotNull();
-    assertThat(dto.getIssueChangeCreationDate()).isNull();
     assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
     assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+    assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
   }
 
   @Test
@@ -132,6 +133,19 @@ public class IssueChangeDtoTest {
     assertThat(diffs.creationDate()).isNotNull();
   }
 
+  @Test
+  public void getIssueChangeCreationDate_fallback_to_createAt_when_null() {
+    IssueChangeDto changeDto = new IssueChangeDto()
+      .setKey("EFGH")
+      .setUserLogin("emmerik")
+      .setChangeData("Some text")
+      .setIssueKey("ABCDE")
+      .setCreatedAt(10_000_000L)
+      .setUpdatedAt(20_000_000L);
+
+    assertThat(changeDto.getIssueChangeCreationDate()).isEqualTo(10_000_000L);
+  }
+
   @Test
   public void to_string() {
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
index cb2d6b907dd4bf53c35f2226b1aadab33b615166..b250929940c105a95520292dfb2998a87ece5e67 100644 (file)
@@ -57,6 +57,7 @@ public class IssueChangeMapperTest {
     dto.setChangeData("the comment");
     dto.setCreatedAt(1_500_000_000_000L);
     dto.setUpdatedAt(1_500_000_000_000L);
+    dto.setIssueChangeCreationDate(1_500_000_000_000L);
     dbTester.getSession().getMapper(IssueChangeMapper.class).insert(dto);
     dbTester.getSession().commit();
 
index ed763c2952a94e507edb63853354565df8508c9b..f319c0348564410cbb89fd0023e2d9f39b9ca4cd 100644 (file)
@@ -8,6 +8,6 @@
     change_data="the comment"
     created_at="1500000000000"
     updated_at="1500000000000"
-    issue_change_creation_date="[null]"
+    issue_change_creation_date="1500000000000"
     />
 </dataset>
index 2cbb7a20af6443b831647d30adadad6568b01c67..55153e11418e7d288d327f2d7905bd741541e864 100644 (file)
@@ -193,11 +193,11 @@ public class ShortBranchIssueMergerTest {
     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().insertFieldDiffs(issue1, FieldDiffs.parse("severity=BLOCKER|INFO,assignee=toto|titi"));
+    db.issues().insertFieldDiffs(issue1, FieldDiffs.parse("severity=BLOCKER|INFO,assignee=toto|titi").setCreationDate(new Date()));
     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().insertFieldDiffs(issue2, FieldDiffs.parse("severity=BLOCKER|MINOR,assignee=foo|bar"));
+    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());
 
     copier.tryMerge(FILE_1, Collections.singleton(newIssue));
index 1fbc1c9d1a2d7970584e164e3c664a5474166f9e..c970bb0409d1ff7f9a7d214a167d5f0a9e36cdc5 100644 (file)
 package org.sonar.server.computation.task.projectanalysis.step;
 
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.issue.Issue;
 import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rule.Severity;
 import org.sonar.api.rules.RuleType;
 import org.sonar.api.utils.System2;
 import org.sonar.core.issue.DefaultIssue;
@@ -51,10 +50,17 @@ import org.sonar.server.computation.task.projectanalysis.issue.IssueCache;
 import org.sonar.server.computation.task.projectanalysis.issue.RuleRepositoryImpl;
 import org.sonar.server.computation.task.projectanalysis.issue.UpdateConflictResolver;
 import org.sonar.server.computation.task.step.ComputationStep;
+import org.sonar.server.util.cache.DiskCache;
 
+import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
+import static org.sonar.api.issue.Issue.STATUS_CLOSED;
+import static org.sonar.api.issue.Issue.STATUS_OPEN;
+import static org.sonar.api.rule.Severity.BLOCKER;
+import static org.sonar.db.component.ComponentTesting.newFileDto;
 
 public class PersistIssuesStepTest extends BaseStepTest {
 
@@ -63,15 +69,15 @@ public class PersistIssuesStepTest extends BaseStepTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE);
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
     .setOrganizationUuid("org-1");
 
-  private DbSession session = dbTester.getSession();
-  private DbClient dbClient = dbTester.getDbClient();
+  private DbSession session = db.getSession();
+  private DbClient dbClient = db.getDbClient();
   private System2 system2;
   private IssueCache issueCache;
   private ComputationStep step;
@@ -99,11 +105,11 @@ public class PersistIssuesStepTest extends BaseStepTest {
   @Test
   public void insert_copied_issue() {
     RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
-    dbTester.rules().insert(rule);
-    OrganizationDto organizationDto = dbTester.organizations().insert();
+    db.rules().insert(rule);
+    OrganizationDto organizationDto = db.organizations().insert();
     ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
     dbClient.componentDao().insert(session, project);
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = newFileDto(project, null);
     dbClient.componentDao().insert(session, file);
     session.commit();
 
@@ -113,8 +119,8 @@ public class PersistIssuesStepTest extends BaseStepTest {
       .setRuleKey(rule.getKey())
       .setComponentUuid(file.uuid())
       .setProjectUuid(project.uuid())
-      .setSeverity(Severity.BLOCKER)
-      .setStatus(Issue.STATUS_OPEN)
+      .setSeverity(BLOCKER)
+      .setStatus(STATUS_OPEN)
       .setNew(false)
       .setCopied(true)
       .setType(RuleType.BUG)
@@ -123,11 +129,14 @@ public class PersistIssuesStepTest extends BaseStepTest {
         .setIssueKey("ISSUE")
         .setUserLogin("john")
         .setMarkdownText("Some text")
+        .setCreatedAt(new Date(NOW))
         .setNew(true))
-      .setCurrentChange(new FieldDiffs()
-        .setIssueKey("ISSUE")
-        .setUserLogin("john")
-        .setDiff("technicalDebt", null, 1L)))
+      .setCurrentChange(
+        new FieldDiffs()
+          .setIssueKey("ISSUE")
+          .setUserLogin("john")
+          .setDiff("technicalDebt", null, 1L)
+          .setCreationDate(new Date(NOW))))
       .close();
 
     step.execute();
@@ -137,8 +146,8 @@ public class PersistIssuesStepTest extends BaseStepTest {
     assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
     assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
     assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
-    assertThat(result.getSeverity()).isEqualTo(Severity.BLOCKER);
-    assertThat(result.getStatus()).isEqualTo(Issue.STATUS_OPEN);
+    assertThat(result.getSeverity()).isEqualTo(BLOCKER);
+    assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
     assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
 
     List<IssueChangeDto> changes = dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList("ISSUE"));
@@ -148,11 +157,11 @@ public class PersistIssuesStepTest extends BaseStepTest {
   @Test
   public void insert_merged_issue() {
     RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
-    dbTester.rules().insert(rule);
-    OrganizationDto organizationDto = dbTester.organizations().insert();
+    db.rules().insert(rule);
+    OrganizationDto organizationDto = db.organizations().insert();
     ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
     dbClient.componentDao().insert(session, project);
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = newFileDto(project, null);
     dbClient.componentDao().insert(session, file);
     session.commit();
 
@@ -162,8 +171,8 @@ public class PersistIssuesStepTest extends BaseStepTest {
       .setRuleKey(rule.getKey())
       .setComponentUuid(file.uuid())
       .setProjectUuid(project.uuid())
-      .setSeverity(Severity.BLOCKER)
-      .setStatus(Issue.STATUS_OPEN)
+      .setSeverity(BLOCKER)
+      .setStatus(STATUS_OPEN)
       .setNew(true)
       .setCopied(true)
       .setType(RuleType.BUG)
@@ -172,13 +181,14 @@ public class PersistIssuesStepTest extends BaseStepTest {
         .setIssueKey("ISSUE")
         .setUserLogin("john")
         .setMarkdownText("Some text")
+        .setCreatedAt(new Date(NOW))
         .setNew(true))
       .setCurrentChange(new FieldDiffs()
         .setIssueKey("ISSUE")
         .setUserLogin("john")
-        .setDiff("technicalDebt", null, 1L)))
+        .setDiff("technicalDebt", null, 1L)
+        .setCreationDate(new Date(NOW))))
       .close();
-
     step.execute();
 
     IssueDto result = dbClient.issueDao().selectOrFailByKey(session, "ISSUE");
@@ -186,8 +196,8 @@ public class PersistIssuesStepTest extends BaseStepTest {
     assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
     assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
     assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
-    assertThat(result.getSeverity()).isEqualTo(Severity.BLOCKER);
-    assertThat(result.getStatus()).isEqualTo(Issue.STATUS_OPEN);
+    assertThat(result.getSeverity()).isEqualTo(BLOCKER);
+    assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
     assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
 
     List<IssueChangeDto> changes = dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList("ISSUE"));
@@ -197,11 +207,11 @@ public class PersistIssuesStepTest extends BaseStepTest {
   @Test
   public void insert_new_issue() {
     RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
-    dbTester.rules().insert(rule);
-    OrganizationDto organizationDto = dbTester.organizations().insert();
+    db.rules().insert(rule);
+    OrganizationDto organizationDto = db.organizations().insert();
     ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
     dbClient.componentDao().insert(session, project);
-    ComponentDto file = ComponentTesting.newFileDto(project, null);
+    ComponentDto file = newFileDto(project, null);
     dbClient.componentDao().insert(session, file);
     session.commit();
 
@@ -211,8 +221,8 @@ public class PersistIssuesStepTest extends BaseStepTest {
       .setRuleKey(rule.getKey())
       .setComponentUuid(file.uuid())
       .setProjectUuid(project.uuid())
-      .setSeverity(Severity.BLOCKER)
-      .setStatus(Issue.STATUS_OPEN)
+      .setSeverity(BLOCKER)
+      .setStatus(STATUS_OPEN)
       .setNew(true)
       .setType(RuleType.BUG)).close();
 
@@ -223,85 +233,106 @@ public class PersistIssuesStepTest extends BaseStepTest {
     assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
     assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
     assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
-    assertThat(result.getSeverity()).isEqualTo(Severity.BLOCKER);
-    assertThat(result.getStatus()).isEqualTo(Issue.STATUS_OPEN);
+    assertThat(result.getSeverity()).isEqualTo(BLOCKER);
+    assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
     assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
   }
 
   @Test
   public void close_issue() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    issueCache.newAppender().append(new DefaultIssue()
-      .setKey("ISSUE")
-      .setType(RuleType.CODE_SMELL)
-      .setRuleKey(RuleKey.of("xoo", "S01"))
-      .setComponentUuid("COMPONENT")
-      .setProjectUuid("PROJECT")
-      .setSeverity(Severity.BLOCKER)
-      .setStatus(Issue.STATUS_CLOSED)
-      .setResolution(Issue.RESOLUTION_FIXED)
-      .setSelectedAt(NOW)
-      .setNew(false)
-      .setChanged(true)).close();
-
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    RuleDefinitionDto rule = db.rules().insert();
+    IssueDto issue = db.issues().insert(rule, project, file,
+      i -> i.setStatus(STATUS_OPEN)
+        .setResolution(null)
+        .setCreatedAt(NOW - 1_000_000_000L)
+        .setUpdatedAt(NOW - 1_000_000_000L));
+    DiskCache<DefaultIssue>.DiskAppender issueCacheAppender = issueCache.newAppender();
+
+    issueCacheAppender.append(
+      issue.toDefaultIssue()
+        .setStatus(STATUS_CLOSED)
+        .setResolution(RESOLUTION_FIXED)
+        .setSelectedAt(NOW)
+        .setNew(false)
+        .setChanged(true))
+      .close();
     step.execute();
 
-    dbTester.assertDbUnit(getClass(), "close_issue-result.xml", "issues");
+    IssueDto issueReloaded = db.getDbClient().issueDao().selectByKey(db.getSession(), issue.getKey()).get();
+    assertThat(issueReloaded.getStatus()).isEqualTo(STATUS_CLOSED);
+    assertThat(issueReloaded.getResolution()).isEqualTo(RESOLUTION_FIXED);
   }
 
   @Test
   public void add_comment() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    issueCache.newAppender().append(new DefaultIssue()
-      .setKey("ISSUE")
-      .setType(RuleType.CODE_SMELL)
-      .setRuleKey(RuleKey.of("xoo", "S01"))
-      .setComponentUuid("COMPONENT")
-      .setProjectUuid("PROJECT")
-      .setSeverity(Severity.BLOCKER)
-      .setStatus(Issue.STATUS_CLOSED)
-      .setResolution(Issue.RESOLUTION_FIXED)
-      .setNew(false)
-      .setChanged(true)
-      .addComment(new DefaultIssueComment()
-        .setKey("COMMENT")
-        .setIssueKey("ISSUE")
-        .setUserLogin("john")
-        .setMarkdownText("Some text")
-        .setNew(true)))
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    RuleDefinitionDto rule = db.rules().insert();
+    IssueDto issue = db.issues().insert(rule, project, file,
+      i -> i.setStatus(STATUS_OPEN)
+        .setResolution(null)
+        .setCreatedAt(NOW - 1_000_000_000L)
+        .setUpdatedAt(NOW - 1_000_000_000L));
+    DiskCache<DefaultIssue>.DiskAppender issueCacheAppender = issueCache.newAppender();
+
+    issueCacheAppender.append(
+      issue.toDefaultIssue()
+        .setStatus(STATUS_CLOSED)
+        .setResolution(RESOLUTION_FIXED)
+        .setSelectedAt(NOW)
+        .setNew(false)
+        .setChanged(true)
+        .addComment(new DefaultIssueComment()
+          .setKey("COMMENT")
+          .setIssueKey(issue.getKey())
+          .setUserLogin("john")
+          .setMarkdownText("Some text")
+          .setCreatedAt(new Date(NOW))
+          .setNew(true)))
       .close();
-
     step.execute();
 
-    dbTester.assertDbUnit(getClass(), "add_comment-result.xml", new String[] {"id", "created_at", "updated_at"}, "issue_changes");
+    IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0);
+    assertThat(issueChangeDto)
+      .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserLogin, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
+        IssueChangeDto::getIssueChangeCreationDate)
+      .containsOnly(IssueChangeDto.TYPE_COMMENT, "john", "Some text", issue.getKey(), NOW);
   }
 
   @Test
   public void add_change() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    issueCache.newAppender().append(new DefaultIssue()
-      .setKey("ISSUE")
-      .setType(RuleType.CODE_SMELL)
-      .setRuleKey(RuleKey.of("xoo", "S01"))
-      .setComponentUuid("COMPONENT")
-      .setProjectUuid("PROJECT")
-      .setSeverity(Severity.BLOCKER)
-      .setStatus(Issue.STATUS_CLOSED)
-      .setResolution(Issue.RESOLUTION_FIXED)
-      .setNew(false)
-      .setChanged(true)
-      .setCurrentChange(new FieldDiffs()
-        .setIssueKey("ISSUE")
-        .setUserLogin("john")
-        .setDiff("technicalDebt", null, 1L)))
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    RuleDefinitionDto rule = db.rules().insert();
+    IssueDto issue = db.issues().insert(rule, project, file,
+      i -> i.setStatus(STATUS_OPEN)
+        .setResolution(null)
+        .setCreatedAt(NOW - 1_000_000_000L)
+        .setUpdatedAt(NOW - 1_000_000_000L));
+    DiskCache<DefaultIssue>.DiskAppender issueCacheAppender = issueCache.newAppender();
+
+    issueCacheAppender.append(
+      issue.toDefaultIssue()
+        .setStatus(STATUS_CLOSED)
+        .setResolution(RESOLUTION_FIXED)
+        .setSelectedAt(NOW)
+        .setNew(false)
+        .setChanged(true)
+        .setCurrentChange(new FieldDiffs()
+          .setIssueKey("ISSUE")
+          .setUserLogin("john")
+          .setDiff("technicalDebt", null, 1L)
+          .setCreationDate(new Date(NOW))))
       .close();
-
     step.execute();
 
-    dbTester.assertDbUnit(getClass(), "add_change-result.xml", new String[] {"id", "created_at", "updated_at"}, "issue_changes");
+    IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0);
+    assertThat(issueChangeDto)
+      .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserLogin, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
+        IssueChangeDto::getIssueChangeCreationDate)
+      .containsOnly(IssueChangeDto.TYPE_FIELD_CHANGE, "john", "technicalDebt=1", issue.getKey(), NOW);
   }
 
 }
index 8a6fc9784e060b4b748466a39038cd717645724c..8c311b114acf5786d827a246d0fa89e1e58fc6f4 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.issue.ws;
 
+import java.util.Date;
 import javax.annotation.Nullable;
 import org.junit.Before;
 import org.junit.Rule;
@@ -79,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"));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -99,7 +100,7 @@ public class ChangelogActionTest {
     ComponentDto file2 = db.components().insertComponent(newFileDto(project));
     IssueDto issueDto = db.issues().insertIssue(newDto(rule, file2, project));
     userSession.logIn("john").addProjectPermission(USER, project, file1, file2);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setDiff("file", file1.uuid(), file2.uuid()));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setDiff("file", file1.uuid(), file2.uuid()).setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -114,7 +115,7 @@ public class ChangelogActionTest {
   public void changelog_of_file_move_is_empty_when_files_does_not_exists() throws Exception {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
     userSession.logIn("john").addProjectPermission(USER, project, file);
-    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setDiff("file", "UNKNOWN_1", "UNKNOWN_2"));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setDiff("file", "UNKNOWN_1", "UNKNOWN_2").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -128,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"));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -142,7 +143,7 @@ public class ChangelogActionTest {
   public void return_changelog_not_having_user() throws Exception {
     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"));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(null).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -157,7 +158,7 @@ public class ChangelogActionTest {
   public void return_changelog_on_none_existing_user() throws Exception {
     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"));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin("UNKNOWN").setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -173,7 +174,9 @@ 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").setDiff("status", "RESOLVED", "CLOSED"));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin())
+      .setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date())
+      .setDiff("status", "RESOLVED", "CLOSED").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -187,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"));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", null, "BLOCKER").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -200,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));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", null).setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -214,8 +217,8 @@ 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"),
-      new FieldDiffs().setDiff("status", "RESOLVED", "CLOSED"));
+      new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()),
+      new FieldDiffs().setDiff("status", "RESOLVED", "CLOSED").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -227,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"));
+    db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("technicalDebt", "10", "20").setCreationDate(new Date()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -261,7 +264,7 @@ public class ChangelogActionTest {
     userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs()
       .setUserLogin(user.getLogin())
-      .setDiff("severity", "MAJOR", "BLOCKER")
+      .setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date())
       .setCreationDate(DateUtils.parseDateTime("2014-03-04T23:03:44+0100")));
 
     String result = tester.newRequest().setParam("issue", issueDto.getKey()).execute().getInput();
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/add_change-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/add_change-result.xml
deleted file mode 100644 (file)
index 78e771f..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<dataset>
-
-  <issue_changes
-      id="1"
-      kee="[null]"
-      issue_key="ISSUE"
-      user_login="john"
-      change_type="diff"
-      change_data="technicalDebt=1"
-      created_at="1400000000000"
-      updated_at="1400000000000"
-      issue_change_creation_date="[null]"
-      />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/add_comment-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/add_comment-result.xml
deleted file mode 100644 (file)
index c95cb87..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<dataset>
-
-  <issue_changes
-      id="1"
-      kee="COMMENT"
-      issue_key="ISSUE"
-      user_login="john"
-      change_type="comment"
-      change_data="Some text"
-      created_at="1400000000000"
-      updated_at="1400000000000"
-      issue_change_creation_date="[null]"
-      />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/close_issue-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/close_issue-result.xml
deleted file mode 100644 (file)
index c9fcff4..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<dataset>
-
-  <issues
-      id="1"
-      kee="ISSUE"
-      component_uuid="COMPONENT"
-      project_uuid="PROJECT"
-      rule_id="1"
-      severity="BLOCKER"
-      manual_severity="[false]"
-      message="[null]"
-      line="[null]"
-      gap="[null]"
-      effort="[null]"
-      status="CLOSED"
-      resolution="FIXED"
-      checksum="[null]"
-      reporter="[null]"
-      author_login="[null]"
-      assignee="[null]"
-      action_plan_key="[null]"
-      tags="[null]"
-      issue_attributes=""
-      issue_creation_date="[null]"
-      issue_update_date="[null]"
-      issue_close_date="[null]"
-      created_at="1300000000000"
-      updated_at="1400000000000"
-      locations="[null]"
-      issue_type="1"
-      />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/insert_new_issue.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/insert_new_issue.xml
deleted file mode 100644 (file)
index fb44281..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<dataset>
-
-  <rules id="1"
-         plugin_rule_key="S01"
-         plugin_name="xoo"
-         name="name"
-         description="description"
-         status="READY"
-         plugin_config_key="[null]"
-         priority="0"
-         is_template="[true]"
-         language="xoo"
-         template_id="[null]"
-         def_remediation_function="LINEAR_OFFSET"
-         def_remediation_coeff="5d"
-         def_remediation_offset="10h"
-         effort_to_fix_description="[null]"
-         description_format="MARKDOWN"
-         system_tags="[null]"
-         created_at="1500000000000"
-         updated_at="1500000000000"
-  />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/PersistIssuesStepTest/shared.xml
deleted file mode 100644 (file)
index 5398346..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<dataset>
-
-  <rules id="1"
-         plugin_rule_key="S01"
-         plugin_name="xoo"
-         name="name"
-         description="description"
-         status="READY"
-         plugin_config_key="[null]"
-         priority="0"
-         is_template="[true]"
-         language="xoo"
-         template_id="[null]"
-         def_remediation_function="LINEAR_OFFSET"
-         def_remediation_gap_mult="5d"
-         def_remediation_base_effort="10h"
-         gap_description="[null]"
-         description_format="MARKDOWN"
-         system_tags="[null]"
-         created_at="1500000000000"
-         updated_at="1500000000000"
-  />
-
-  <issues
-      id="1"
-      kee="ISSUE"
-      component_uuid="COMPONENT"
-      project_uuid="PROJECT"
-      rule_id="1"
-      severity="BLOCKER"
-      manual_severity="[false]"
-      message="[null]"
-      line="[null]"
-      gap="[null]"
-      effort="[null]"
-      status="OPEN"
-      resolution="[null]"
-      checksum="[null]"
-      reporter="[null]"
-      author_login="[null]"
-      assignee="[null]"
-      action_plan_key="[null]"
-      tags="[null]"
-      issue_attributes=""
-      issue_creation_date="[null]"
-      issue_update_date="[null]"
-      issue_close_date="[null]"
-      created_at="1300000000000"
-      updated_at="1300000000000"
-      locations="[null]"
-      issue_type="[null]"
-  />
-
-</dataset>