aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-10-31 11:08:55 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-11-01 08:28:17 +0100
commit784829702ff22927a87b51091b82724609e6efbe (patch)
tree1ccdf5052d4994d3f584c80f2ace414ea45c1196 /server/sonar-db-dao
parent7dd92e607ad74e0beafbd0798e45b9545caaca45 (diff)
downloadsonarqube-784829702ff22927a87b51091b82724609e6efbe.tar.gz
sonarqube-784829702ff22927a87b51091b82724609e6efbe.zip
SONAR-9993 Functional creation date of comment is no more nullable
Old comments do not have functional creation date as this column has been added later
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java18
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java16
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java1
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueChangeMapperTest/insert_comment-result.xml2
4 files changed, 28 insertions, 9 deletions
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 53f2ebda604..0d9a822647b 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
@@ -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);
}
}
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 bda52ad0132..4465a3b1dc7 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
@@ -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
@@ -133,6 +134,19 @@ public class IssueChangeDtoTest {
}
@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");
IssueChangeDto dto = IssueChangeDto.of(comment);
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 cb2d6b907dd..b250929940c 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
@@ -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();
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 ed763c2952a..f319c034856 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
@@ -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>