aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-02 14:39:34 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-02 14:50:19 +0200
commit1fd5d8abd320428e1e8e4cd1b3ebf793678b10f2 (patch)
tree73668ba184e89bcadf405ae15e1ba3bbd22054d6 /sonar-core/src/test
parent5f2b527e01b997a551a1a57779a57a80c1ba3411 (diff)
downloadsonarqube-1fd5d8abd320428e1e8e4cd1b3ebf793678b10f2.tar.gz
sonarqube-1fd5d8abd320428e1e8e4cd1b3ebf793678b10f2.zip
SONAR-3755 implement changelog
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java16
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/FieldDiffsTest.java115
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/IssueChangeContextTest.java48
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java196
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java78
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java45
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java48
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java121
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert-result.xml11
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert.xml3
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml22
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/insert-result.xml22
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/insert.xml3
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/update-result.xml26
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/update.xml26
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml10
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml2
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml2
18 files changed, 608 insertions, 186 deletions
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 64e5970e8fb..1ac246e0db3 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
@@ -19,11 +19,13 @@
*/
package org.sonar.core.issue;
+import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
+import static org.fest.assertions.MapAssert.entry;
public class DefaultIssueTest {
@@ -41,6 +43,20 @@ public class DefaultIssueTest {
}
@Test
+ public void setAttributes_should_not_clear_existing_values() throws Exception {
+ issue.setAttributes(ImmutableMap.of("1", "one"));
+ assertThat(issue.attribute("1")).isEqualTo("one");
+
+ issue.setAttributes(ImmutableMap.of("2", "two"));
+ assertThat(issue.attributes()).hasSize(2);
+ assertThat(issue.attributes()).includes(entry("1", "one"), entry("2", "two"));
+
+ issue.setAttributes(null);
+ assertThat(issue.attributes()).hasSize(2);
+ assertThat(issue.attributes()).includes(entry("1", "one"), entry("2", "two"));
+ }
+
+ @Test
public void should_fail_on_empty_status() {
try {
issue.setStatus("");
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/FieldDiffsTest.java b/sonar-core/src/test/java/org/sonar/core/issue/FieldDiffsTest.java
new file mode 100644
index 00000000000..08d436c7f36
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/issue/FieldDiffsTest.java
@@ -0,0 +1,115 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.issue;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class FieldDiffsTest {
+
+ FieldDiffs diffs = new FieldDiffs();
+
+ @Test
+ public void diffs_should_be_empty_by_default() throws Exception {
+ assertThat(diffs.diffs()).isEmpty();
+ }
+
+ @Test
+ public void test_diff() throws Exception {
+ diffs.setDiff("severity", "BLOCKER", "INFO");
+ diffs.setDiff("resolution", "OPEN", "FIXED");
+
+ assertThat(diffs.diffs()).hasSize(2);
+
+ FieldDiffs.Diff diff = diffs.diffs().get("severity");
+ assertThat(diff.oldValue()).isEqualTo("BLOCKER");
+ assertThat(diff.newValue()).isEqualTo("INFO");
+
+ diff = diffs.diffs().get("resolution");
+ assertThat(diff.oldValue()).isEqualTo("OPEN");
+ assertThat(diff.newValue()).isEqualTo("FIXED");
+ }
+
+ @Test
+ public void should_keep_old_value() throws Exception {
+ diffs.setDiff("severity", "BLOCKER", "INFO");
+ diffs.setDiff("severity", null, "MAJOR");
+ FieldDiffs.Diff diff = diffs.diffs().get("severity");
+ assertThat(diff.oldValue()).isEqualTo("BLOCKER");
+ assertThat(diff.newValue()).isEqualTo("MAJOR");
+ }
+
+ @Test
+ public void test_toString() throws Exception {
+ diffs.setDiff("severity", "BLOCKER", "INFO");
+ diffs.setDiff("resolution", "OPEN", "FIXED");
+
+ assertThat(diffs.toString()).isEqualTo("severity=BLOCKER|INFO,resolution=OPEN|FIXED");
+ }
+
+ @Test
+ public void test_toString_with_null_values() throws Exception {
+ diffs.setDiff("severity", null, "INFO");
+ diffs.setDiff("resolution", "OPEN", null);
+
+ assertThat(diffs.toString()).isEqualTo("severity=|INFO,resolution=OPEN|");
+ }
+
+ @Test
+ public void test_parse() throws Exception {
+ diffs = FieldDiffs.parse("severity=BLOCKER|INFO,resolution=OPEN|FIXED");
+ assertThat(diffs.diffs()).hasSize(2);
+
+ FieldDiffs.Diff diff = diffs.diffs().get("severity");
+ assertThat(diff.oldValue()).isEqualTo("BLOCKER");
+ assertThat(diff.newValue()).isEqualTo("INFO");
+
+ diff = diffs.diffs().get("resolution");
+ assertThat(diff.oldValue()).isEqualTo("OPEN");
+ assertThat(diff.newValue()).isEqualTo("FIXED");
+ }
+
+ @Test
+ public void test_parse_empty_values() throws Exception {
+ diffs = FieldDiffs.parse("severity=|INFO,resolution=OPEN|");
+ assertThat(diffs.diffs()).hasSize(2);
+
+ FieldDiffs.Diff diff = diffs.diffs().get("severity");
+ assertThat(diff.oldValue()).isEqualTo("");
+ assertThat(diff.newValue()).isEqualTo("INFO");
+
+ diff = diffs.diffs().get("resolution");
+ assertThat(diff.oldValue()).isEqualTo("OPEN");
+ assertThat(diff.newValue()).isEqualTo("");
+ }
+
+ @Test
+ public void test_parse_null() throws Exception {
+ diffs = FieldDiffs.parse(null);
+ assertThat(diffs.diffs()).isEmpty();
+ }
+
+ @Test
+ public void test_parse_empty() throws Exception {
+ diffs = FieldDiffs.parse("");
+ assertThat(diffs.diffs()).isEmpty();
+ }
+}
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
new file mode 100644
index 00000000000..101b5fd1472
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueChangeContextTest.java
@@ -0,0 +1,48 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.issue;
+
+import org.junit.Test;
+
+import java.util.Date;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueChangeContextTest {
+ @Test
+ public void test_scan_context() throws Exception {
+ Date now = new Date();
+ IssueChangeContext context = IssueChangeContext.createScan(now);
+
+ assertThat(context.scan()).isTrue();
+ assertThat(context.login()).isNull();
+ assertThat(context.date()).isEqualTo(now);
+ }
+
+ @Test
+ public void test_end_user_context() throws Exception {
+ Date now = new Date();
+ IssueChangeContext context = IssueChangeContext.createUser(now, "emmerik");
+
+ assertThat(context.scan()).isFalse();
+ assertThat(context.login()).isEqualTo("emmerik");
+ assertThat(context.date()).isEqualTo(now);
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java
new file mode 100644
index 00000000000..478121c2e45
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java
@@ -0,0 +1,196 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.issue;
+
+import org.junit.Test;
+
+import java.util.Date;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueUpdaterTest {
+
+ IssueUpdater updater = new IssueUpdater();
+ DefaultIssue issue = new DefaultIssue();
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik");
+
+ @Test
+ public void should_assign() throws Exception {
+ boolean updated = updater.assign(issue, "emmerik", context);
+ assertThat(updated).isTrue();
+ assertThat(issue.assignee()).isEqualTo("emmerik");
+ FieldDiffs.Diff diff = issue.diffs().get("assignee");
+ assertThat(diff.oldValue()).isNull();
+ assertThat(diff.newValue()).isEqualTo("emmerik");
+ }
+
+ @Test
+ public void should_unassign() throws Exception {
+ issue.setAssignee("morgan");
+ boolean updated = updater.assign(issue, null, context);
+ assertThat(updated).isTrue();
+ assertThat(issue.assignee()).isNull();
+ FieldDiffs.Diff diff = issue.diffs().get("assignee");
+ assertThat(diff.oldValue()).isEqualTo("morgan");
+ assertThat(diff.newValue()).isNull();
+ }
+
+ @Test
+ public void should_change_assignee() throws Exception {
+ issue.setAssignee("morgan");
+ boolean updated = updater.assign(issue, "emmerik", context);
+ assertThat(updated).isTrue();
+ assertThat(issue.assignee()).isEqualTo("emmerik");
+ FieldDiffs.Diff diff = issue.diffs().get("assignee");
+ assertThat(diff.oldValue()).isEqualTo("morgan");
+ assertThat(diff.newValue()).isEqualTo("emmerik");
+ }
+
+ @Test
+ public void should_not_change_assignee() throws Exception {
+ issue.setAssignee("morgan");
+ boolean updated = updater.assign(issue, "morgan", context);
+ assertThat(updated).isFalse();
+ assertThat(issue.diffs()).isNull();
+ }
+
+
+ @Test
+ public void should_set_severity() throws Exception {
+ boolean updated = updater.setSeverity(issue, "BLOCKER", context);
+ assertThat(updated).isTrue();
+ assertThat(issue.severity()).isEqualTo("BLOCKER");
+ assertThat(issue.manualSeverity()).isFalse();
+
+ FieldDiffs.Diff diff = issue.diffs().get("severity");
+ assertThat(diff.oldValue()).isNull();
+ assertThat(diff.newValue()).isEqualTo("BLOCKER");
+ }
+
+ @Test
+ public void should_update_severity() throws Exception {
+ issue.setSeverity("BLOCKER");
+ boolean updated = updater.setSeverity(issue, "MINOR", context);
+
+ assertThat(updated).isTrue();
+ assertThat(issue.severity()).isEqualTo("MINOR");
+ FieldDiffs.Diff diff = issue.diffs().get("severity");
+ assertThat(diff.oldValue()).isEqualTo("BLOCKER");
+ assertThat(diff.newValue()).isEqualTo("MINOR");
+ }
+
+ @Test
+ public void should_not_change_severity() throws Exception {
+ issue.setSeverity("MINOR");
+ boolean updated = updater.setSeverity(issue, "MINOR", context);
+ assertThat(updated).isFalse();
+ assertThat(issue.diffs()).isNull();
+ }
+
+ @Test
+ public void should_not_revert_manual_severity() throws Exception {
+ issue.setSeverity("MINOR").setManualSeverity(true);
+ try {
+ updater.setSeverity(issue, "MAJOR", context);
+ } catch (IllegalStateException e) {
+ assertThat(e).hasMessage("Severity can't be changed");
+ }
+ }
+
+ @Test
+ public void should_set_manual_severity() throws Exception {
+ issue.setSeverity("BLOCKER");
+ boolean updated = updater.setManualSeverity(issue, "MINOR", context);
+
+ assertThat(updated).isTrue();
+ assertThat(issue.severity()).isEqualTo("MINOR");
+ assertThat(issue.manualSeverity()).isTrue();
+ FieldDiffs.Diff diff = issue.diffs().get("severity");
+ assertThat(diff.oldValue()).isEqualTo("BLOCKER");
+ assertThat(diff.newValue()).isEqualTo("MINOR");
+ }
+
+ @Test
+ public void should_not_change_manual_severity() throws Exception {
+ issue.setSeverity("MINOR").setManualSeverity(true);
+ boolean updated = updater.setManualSeverity(issue, "MINOR", context);
+ assertThat(updated).isFalse();
+ assertThat(issue.diffs()).isNull();
+ }
+
+ @Test
+ public void should_set_line() throws Exception {
+ boolean updated = updater.setLine(issue, 123);
+ assertThat(updated).isTrue();
+ assertThat(issue.line()).isEqualTo(123);
+
+ // do not save change
+ assertThat(issue.diffs()).isNull();
+ }
+
+ @Test
+ public void should_not_change_line() throws Exception {
+ issue.setLine(123);
+ boolean updated = updater.setLine(issue, 123);
+ assertThat(updated).isFalse();
+ assertThat(issue.line()).isEqualTo(123);
+ assertThat(issue.diffs()).isNull();
+ }
+
+ @Test
+ public void should_set_resolution() throws Exception {
+ boolean updated = updater.setResolution(issue, "OPEN", context);
+ assertThat(updated).isTrue();
+ assertThat(issue.resolution()).isEqualTo("OPEN");
+
+ FieldDiffs.Diff diff = issue.diffs().get("resolution");
+ assertThat(diff.oldValue()).isNull();
+ assertThat(diff.newValue()).isEqualTo("OPEN");
+ }
+
+ @Test
+ public void should_not_change_resolution() throws Exception {
+ issue.setResolution("FIXED");
+ boolean updated = updater.setResolution(issue, "FIXED", context);
+ assertThat(updated).isFalse();
+ assertThat(issue.resolution()).isEqualTo("FIXED");
+ assertThat(issue.diffs()).isNull();
+ }
+
+ @Test
+ public void should_set_status() throws Exception {
+ boolean updated = updater.setStatus(issue, "OPEN", context);
+ assertThat(updated).isTrue();
+ assertThat(issue.status()).isEqualTo("OPEN");
+
+ FieldDiffs.Diff diff = issue.diffs().get("status");
+ assertThat(diff.oldValue()).isNull();
+ assertThat(diff.newValue()).isEqualTo("OPEN");
+ }
+
+ @Test
+ public void should_not_change_status() throws Exception {
+ issue.setStatus("CLOSED");
+ boolean updated = updater.setStatus(issue, "CLOSED", context);
+ assertThat(updated).isFalse();
+ assertThat(issue.status()).isEqualTo("CLOSED");
+ assertThat(issue.diffs()).isNull();
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java
new file mode 100644
index 00000000000..dec00ee6cf9
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java
@@ -0,0 +1,78 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.issue.db;
+
+import org.junit.Test;
+import org.sonar.core.issue.DefaultIssue;
+import org.sonar.core.issue.FieldDiffs;
+import org.sonar.core.issue.IssueChangeContext;
+import org.sonar.core.issue.IssueComment;
+
+import java.util.Date;
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ChangeDtoConverterTest {
+ @Test
+ public void testToChangeDtos() throws Exception {
+ IssueComment comment = IssueComment.create("emmerik", "the comment");
+
+ IssueChangeDto dto = ChangeDtoConverter.commentToDto("ABCDE", comment);
+
+ assertThat(dto.getChangeData()).isEqualTo("the comment");
+ assertThat(dto.getChangeType()).isEqualTo("comment");
+ assertThat(dto.getCreatedAt()).isNotNull();
+ assertThat(dto.getUpdatedAt()).isNotNull();
+ assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
+ assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+ }
+
+ @Test
+ public void testToDiffsDtos() throws Exception {
+ FieldDiffs diffs = new FieldDiffs();
+ diffs.setDiff("severity", "INFO", "BLOCKER");
+ diffs.setUserLogin("emmerik");
+
+ IssueChangeDto dto = ChangeDtoConverter.diffsToDto("ABCDE", diffs);
+
+ assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER");
+ assertThat(dto.getChangeType()).isEqualTo("diff");
+ assertThat(dto.getCreatedAt()).isNotNull();
+ assertThat(dto.getUpdatedAt()).isNotNull();
+ assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
+ assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+ }
+
+ @Test
+ public void test_toChangeDtos() throws Exception {
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik");
+ IssueComment comment = IssueComment.create("emmerik", "the comment");
+ DefaultIssue issue = new DefaultIssue();
+ issue.setFieldDiff(context, "severity", "INFO", "BLOCKER");
+ issue.addComment(comment);
+
+ List<IssueChangeDto> changeDtos = ChangeDtoConverter.toChangeDtos(issue);
+ assertThat(changeDtos).hasSize(2);
+ assertThat(changeDtos.get(0).getChangeType()).isEqualTo("comment");
+ assertThat(changeDtos.get(1).getChangeType()).isEqualTo("diff");
+
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java
index 437ec98973a..c3c23a7c4a1 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java
@@ -21,12 +21,10 @@ package org.sonar.core.issue.db;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.issue.db.IssueChangeDao;
-import org.sonar.core.issue.db.IssueChangeDto;
import org.sonar.core.persistence.AbstractDaoTestCase;
-import java.util.Collection;
import java.util.Date;
+import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
@@ -40,46 +38,27 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase {
}
@Test
- public void should_insert() {
- setupData("insert");
-
- IssueChangeDto dto = new IssueChangeDto();
- dto.setIssueKey("100");
- dto.setUserLogin("arthur");
- dto.setChangeType("type");
- dto.setChangeData("data");
- dto.setMessage("some message");
-
- Date today = new Date();
- dto.setCreatedAt(today);
- dto.setUpdatedAt(today);
-
- dao.insert(dto);
-
- checkTables("insert", new String[]{"id", "created_at", "updated_at"}, "issue_changes");
- }
-
- @Test
- public void should_find_by_id() {
+ public void should_select_by_id() {
setupData("shared");
- IssueChangeDto dto = dao.findById(100L);
+ IssueChangeDto dto = dao.selectById(100L);
assertThat(dto.getId()).isEqualTo(100L);
- assertThat(dto.getIssueKey()).isEqualTo("100");
+ assertThat(dto.getIssueKey()).isEqualTo("1000");
assertThat(dto.getUserLogin()).isEqualTo("arthur");
- assertThat(dto.getChangeType()).isEqualTo("type");
- assertThat(dto.getChangeData()).isEqualTo("data");
- assertThat(dto.getMessage()).isEqualTo("some message");
- assertThat(dto.getCreatedAt()).isNull();
- assertThat(dto.getUpdatedAt()).isNull();
+ assertThat(dto.getChangeType()).isEqualTo("comment");
+ assertThat(dto.getChangeData()).isEqualTo("this is a comment");
+ assertThat(dto.getCreatedAt()).isNotNull();
+ assertThat(dto.getUpdatedAt()).isNotNull();
}
@Test
public void should_select_by_issue() {
setupData("shared");
- Collection<IssueChangeDto> dtoList = dao.selectByIssue("100");
- assertThat(dtoList).hasSize(2);
+ List<IssueChangeDto> ordered = dao.selectByIssue("1000");
+ assertThat(ordered).hasSize(2);
+ assertThat(ordered.get(0).getId()).isEqualTo(101);
+ assertThat(ordered.get(1).getId()).isEqualTo(100);
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java
index e988b9c2bd9..26975e3251e 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java
@@ -45,54 +45,6 @@ public class IssueDaoTest extends AbstractDaoTestCase {
}
@Test
- public void should_insert() {
- setupData("insert");
-
- IssueDto issueDto = new IssueDto();
- issueDto.setKey("100");
- issueDto.setResourceId(400);
- issueDto.setRuleId(12);
- issueDto.setSeverity("BLOCKER");
- issueDto.setLine(200);
- issueDto.setStatus("OPEN");
- issueDto.setAssignee("user");
- issueDto.setDescription("the description");
- issueDto.setCost(10.0);
- issueDto.setChecksum("checksum");
- issueDto.setAuthorLogin("arthur");
-
- Date today = new Date();
- issueDto.setCreatedAt(today);
- issueDto.setUpdatedAt(today);
- issueDto.setClosedAt(today);
-
- dao.insert(issueDto);
-
- checkTables("insert", new String[]{"id", "created_at", "updated_at", "closed_at"}, "issues");
- }
-
- @Test
- public void update() {
- setupData("shared", "update");
- Collection<IssueDto> issues = newArrayList(dao.selectById(100L));
- IssueDto issue = issues.iterator().next();
- issue.setLine(1000);
- issue.setResolution("NEW_RESOLUTION");
- issue.setStatus("NEW_STATUS");
- issue.setSeverity("NEW_SEV");
- issue.setAssignee("new_user");
- issue.setManualSeverity(true);
- issue.setManualIssue(false);
- issue.setCreatedAt(DateUtils.parseDate("2012-05-18"));
- issue.setUpdatedAt(DateUtils.parseDate("2012-07-01"));
- issue.setAttributes("big=bang");
-
- dao.update(issues);
-
- checkTables("update", "issues");
- }
-
- @Test
public void should_select_by_id() {
setupData("shared", "should_select_by_id");
IssueDto issue = dao.selectById(100L);
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java
new file mode 100644
index 00000000000..c49b404fbbf
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java
@@ -0,0 +1,121 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.issue.db;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.RuleQuery;
+import org.sonar.core.issue.DefaultIssue;
+import org.sonar.core.issue.IssueChangeContext;
+import org.sonar.core.issue.IssueComment;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+import org.sonar.core.persistence.MyBatis;
+
+import java.util.Collection;
+import java.util.Date;
+
+public class IssueStorageTest extends AbstractDaoTestCase {
+ @Test
+ public void should_insert_new_issues() throws Exception {
+ FakeSaver saver = new FakeSaver(getMyBatis(), new FakeRuleFinder());
+
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik");
+ IssueComment comment = IssueComment.create("emmerik", "the comment");
+ // override generated key
+ comment.setKey("FGHIJ");
+
+ DefaultIssue issue = new DefaultIssue();
+ issue.setKey("ABCDE");
+ issue.setRuleKey(RuleKey.of("squid", "AvoidCycle"));
+ issue.setLine(5000);
+ issue.setNew(true);
+ issue.setFieldDiff(context, "severity", "INFO", "BLOCKER");
+ issue.setUserLogin("emmerik");
+ issue.setResolution("OPEN").setStatus("OPEN").setSeverity("BLOCKER");
+ issue.setAttribute("foo", "bar");
+ issue.addComment(comment);
+
+ saver.save(issue);
+
+ checkTables("should_insert_new_issues", new String[]{"id", "created_at", "updated_at", "closed_at"}, "issues", "issue_changes");
+ }
+
+ @Ignore("TODO")
+ @Test
+ public void should_update_issues() throws Exception {
+
+ }
+
+ @Ignore("TODO")
+ @Test
+ public void should_fail_if_unknown_rule() throws Exception {
+
+ }
+
+ @Ignore("TODO")
+ @Test
+ public void should_fail_if_unknown_component() throws Exception {
+
+ }
+
+ static class FakeSaver extends IssueStorage {
+ protected FakeSaver(MyBatis mybatis, RuleFinder ruleFinder) {
+ super(mybatis, ruleFinder);
+ }
+
+ @Override
+ protected int componentId(DefaultIssue issue) {
+ return 100;
+ }
+ }
+
+ static class FakeRuleFinder implements RuleFinder {
+
+ @Override
+ public Rule findById(int ruleId) {
+ return null;
+ }
+
+ @Override
+ public Rule findByKey(String repositoryKey, String key) {
+ return null;
+ }
+
+ @Override
+ public Rule findByKey(RuleKey key) {
+ Rule rule = new Rule().setRepositoryKey(key.repository()).setKey(key.rule());
+ rule.setId(200);
+ return rule;
+ }
+
+ @Override
+ public Rule find(RuleQuery query) {
+ return null;
+ }
+
+ @Override
+ public Collection<Rule> findAll(RuleQuery query) {
+ return null;
+ }
+ }
+}
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert-result.xml
deleted file mode 100644
index cf0a89b4610..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert-result.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
- <issue_changes
- issue_key="100"
- user_login="arthur"
- change_type="type"
- change_data="data"
- message="some message"
- />
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert.xml
deleted file mode 100644
index 871dedcb5e9..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml
index e3e9559f8ca..739f6c802df 100644
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml
@@ -2,24 +2,22 @@
<issue_changes
id="100"
- issue_key="100"
+ issue_key="1000"
user_login="arthur"
- change_type="type"
- change_data="data"
- message="some message"
- created_at="[null]"
- updated_at="[null]"
+ change_type="comment"
+ change_data="this is a comment"
+ created_at="2013-01-01"
+ updated_at="2013-01-01"
/>
<issue_changes
id="101"
- issue_key="100"
+ issue_key="1000"
user_login="arthur"
- change_type="type"
- change_data="data"
- message="some message"
- created_at="[null]"
- updated_at="[null]"
+ change_type="fields"
+ change_data="severity:MAJOR,BLOCKER"
+ created_at="2013-02-02"
+ updated_at="2013-02-02"
/>
</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/insert-result.xml
deleted file mode 100644
index 5868688a27b..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/insert-result.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<dataset>
-
- <issues
- kee="100"
- resource_id="400"
- rule_id="12"
- severity="BLOCKER"
- manual_severity="[false]"
- manual_issue="[false]"
- description="the description"
- line="200"
- cost="10.0"
- status="OPEN"
- resolution="[null]"
- checksum="checksum"
- user_login="[null]"
- assignee_login="user"
- author_login="arthur"
- attributes="[null]"
- />
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/insert.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/insert.xml
deleted file mode 100644
index 871dedcb5e9..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/insert.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/update-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/update-result.xml
deleted file mode 100644
index 0574a4c9d88..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/update-result.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<dataset>
-
- <issues
- id="100"
- kee="100"
- resource_id="400"
- rule_id="500"
- severity="NEW_SEV"
- manual_severity="[true]"
- manual_issue="[false]"
- description="[null]"
- line="1000"
- cost="[null]"
- status="NEW_STATUS"
- resolution="NEW_RESOLUTION"
- checksum="[null]"
- user_login="user"
- assignee_login="new_user"
- author_login="[null]"
- attributes="big=bang"
- created_at="2012-05-18"
- updated_at="2012-07-01"
- closed_at="[null]"
- />
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/update.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/update.xml
deleted file mode 100644
index d701d8d68c3..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/update.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<dataset>
-
- <issues
- id="100"
- kee="100"
- resource_id="400"
- rule_id="500"
- severity="BLOCKER"
- manual_severity="[false]"
- manual_issue="[false]"
- description="[null]"
- line="200"
- cost="[null]"
- status="OPEN"
- resolution="RESOLVE"
- checksum="[null]"
- user_login="user"
- assignee_login="user"
- author_login="[null]"
- attributes="prop1=foo;prop2=bar"
- created_at="[null]"
- updated_at="[null]"
- closed_at="[null]"
- />
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml
new file mode 100644
index 00000000000..24140048336
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml
@@ -0,0 +1,10 @@
+<dataset>
+ <issues id="1" kee="ABCDE" resolution="OPEN" status="OPEN" severity="BLOCKER" manual_severity="[false]"
+ assignee_login="[null]" author_login="[null]" checksum="[null]" closed_at="[null]"
+ cost="[null]" created_at="[null]" description="[null]" line="5000"
+ manual_issue="[false]" resource_id="100" rule_id="200" updated_at="[null]" user_login="emmerik"
+ attributes="foo=bar" />
+
+ <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik" change_data="the comment" created_at="[null]" updated_at="[null]" />
+ <issue_changes id="2" kee="[null]" issue_key="ABCDE" change_type="diff" user_login="emmerik" change_data="severity=INFO|BLOCKER" created_at="[null]" updated_at="[null]" />
+</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml
index f603e893826..1c4b7929732 100644
--- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml
@@ -27,7 +27,7 @@
<issues id="1" kee="ABCDE" resource_id="1" status="CLOSED" resolution="[null]" created_at="[null]" line="200" severity="BLOCKER"
user_login="perceval" assignee_login="arthur" rule_id="500" manual_issue="[true]" manual_severity="[false]" description="[null]"/>
- <issue_changes id="1" issue_key="ABCDE" created_at="[null]" updated_at="[null]" user_login="admin" message="abc"/>
+ <issue_changes id="1" kee="ABDA" issue_key="ABCDE" created_at="[null]" updated_at="[null]" user_login="admin" change_type="comment" change_data="this is a comment"/>
<authors id="1" person_id="1" login="tartanpion" created_at="[null]" updated_at="[null]" />
<authors id="2" person_id="1" login="fanfoue" created_at="[null]" updated_at="[null]" />
diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml
index 3df0470a044..611e020fda0 100644
--- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml
@@ -39,7 +39,7 @@
<issues id="2" kee="ABCDF" resource_id="1" status="CLOSED" resolution="[null]" created_at="[null]" line="200" severity="BLOCKER"
user_login="perceval" assignee_login="arthur" rule_id="500" manual_issue="[true]" manual_severity="[false]" description="[null]"/>
- <issue_changes id="1" issue_key="ABCDF" created_at="[null]" updated_at="[null]" user_login="admin" message="abc"/>
+ <issue_changes id="1" kee="[null]" issue_key="ABCDF" created_at="[null]" updated_at="[null]" user_login="admin" change_type="comment" change_data="abc"/>
<!-- modules -->
<projects id="2" enabled="[true]" root_id="1"