aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-12-14 18:08:17 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-12-15 14:45:04 +0100
commitf708dfbad7bacac33b18bb5c7c1221565b803fa5 (patch)
tree497f9c3db0541b57b42faf10363f46f1fed5c96c /sonar-db/src/test
parenta2387e7c4baeec2522b6017b7447fcda77716c5d (diff)
downloadsonarqube-f708dfbad7bacac33b18bb5c7c1221565b803fa5.tar.gz
sonarqube-f708dfbad7bacac33b18bb5c7c1221565b803fa5.zip
SONAR-7292 IssueChangeDao#selectCommentByKey now returns a dto
Diffstat (limited to 'sonar-db/src/test')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java28
-rw-r--r--sonar-db/src/test/java/org/sonar/db/issue/IssueDbTester.java29
2 files changed, 51 insertions, 6 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
index 09544234f7e..a1c2397efc6 100644
--- a/sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
@@ -22,6 +22,7 @@ package org.sonar.db.issue;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.DateUtils;
@@ -35,7 +36,6 @@ import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-
public class IssueChangeDaoTest {
@Rule
@@ -75,16 +75,16 @@ public class IssueChangeDaoTest {
}
@Test
- public void select_comment_by_key() {
+ public void select_default_comment_by_key() {
db.prepareDbUnit(getClass(), "shared.xml");
- DefaultIssueComment comment = underTest.selectCommentByKey("FGHIJ");
+ DefaultIssueComment comment = underTest.selectDefaultCommentByKey("FGHIJ");
assertThat(comment).isNotNull();
assertThat(comment.key()).isEqualTo("FGHIJ");
assertThat(comment.key()).isEqualTo("FGHIJ");
assertThat(comment.userLogin()).isEqualTo("arthur");
- assertThat(underTest.selectCommentByKey("UNKNOWN")).isNull();
+ assertThat(underTest.selectDefaultCommentByKey("UNKNOWN")).isNull();
}
@Test
@@ -117,6 +117,23 @@ public class IssueChangeDaoTest {
}
@Test
+ public void select_comment_by_key() {
+ IssueDto issueDto = db.issues().insertIssue();
+ IssueChangeDto comment = db.issues().insertComment(issueDto, "john", "some comment");
+
+ Optional<IssueChangeDto> issueChangeDto = underTest.selectCommentByKey(db.getSession(), comment.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().getIssueChangeCreationDate()).isNotNull();
+ assertThat(issueChangeDto.get().getCreatedAt()).isNotNull();
+ assertThat(issueChangeDto.get().getUpdatedAt()).isNotNull();
+ }
+
+ @Test
public void delete() {
db.prepareDbUnit(getClass(), "delete.xml");
@@ -147,7 +164,7 @@ public class IssueChangeDaoTest {
underTest.insert(db.getSession(), changeDto);
db.getSession().commit();
- db.assertDbUnit(getClass(), "insert-result.xml", new String[]{"id"}, "issue_changes");
+ db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "issue_changes");
}
@Test
@@ -179,4 +196,5 @@ public class IssueChangeDaoTest {
assertThat(underTest.update(change)).isFalse();
}
+
}
diff --git a/sonar-db/src/test/java/org/sonar/db/issue/IssueDbTester.java b/sonar-db/src/test/java/org/sonar/db/issue/IssueDbTester.java
index 62d034a013f..e9ef4e5e6e3 100644
--- a/sonar-db/src/test/java/org/sonar/db/issue/IssueDbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/issue/IssueDbTester.java
@@ -21,8 +21,16 @@
package org.sonar.db.issue;
import java.util.Arrays;
+import javax.annotation.Nullable;
+import org.sonar.core.issue.DefaultIssueComment;
import org.sonar.core.issue.FieldDiffs;
import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.rule.RuleDto;
+
+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 IssueDbTester {
@@ -38,8 +46,27 @@ public class IssueDbTester {
return issueDto;
}
- public void insertIssueChanges(IssueDto issueDto, FieldDiffs... diffs) {
+ public IssueDto insertIssue() {
+ RuleDto rule = db.rules().insertRule(newRuleDto());
+ ComponentDto project = db.components().insertProject();
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
+ return insertIssue(newDto(rule, file, project));
+ }
+
+ 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));
+ return insertChange(issueChangeDto);
+ }
+
+ public void insertFieldDiffs(IssueDto issueDto, FieldDiffs... diffs) {
Arrays.stream(diffs).forEach(diff -> db.getDbClient().issueChangeDao().insert(db.getSession(), IssueChangeDto.of(issueDto.getKey(), diff)));
db.commit();
}
+
}