diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-25 23:31:28 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-26 16:27:24 +0100 |
commit | 8dd5740bdeb71b8fcabbfb7d428f2e73b2e0d727 (patch) | |
tree | 2d50de1b3b52af8cb9371fa62f0c76e8a670edae /sonar-db/src/test | |
parent | 41c79688c9760806fb15cf2a6b97cf98d852f18c (diff) | |
download | sonarqube-8dd5740bdeb71b8fcabbfb7d428f2e73b2e0d727.tar.gz sonarqube-8dd5740bdeb71b8fcabbfb7d428f2e73b2e0d727.zip |
SONAR-7333 DB migration to set ISSUES.ISSUE_TYPE
Diffstat (limited to 'sonar-db/src/test')
6 files changed, 114 insertions, 3 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/sonar-db/src/test/java/org/sonar/db/issue/IssueDaoTest.java index ddd3920af68..cbda4d662bc 100644 --- a/sonar-db/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -106,6 +106,7 @@ public class IssueDaoTest { assertThat(issue.getRuleId()).isEqualTo(500); assertThat(issue.getLanguage()).isEqualTo("java"); assertThat(issue.getSeverity()).isEqualTo("BLOCKER"); + assertThat(issue.getType()).isEqualTo(2); assertThat(issue.isManualSeverity()).isFalse(); assertThat(issue.getMessage()).isNull(); assertThat(issue.getLine()).isEqualTo(200); diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index 033448a921e..e81f6085362 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(55); + assertThat(container.size()).isEqualTo(56); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v55/FeedIssueTypesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v55/FeedIssueTypesTest.java new file mode 100644 index 00000000000..0299c30b39a --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v55/FeedIssueTypesTest.java @@ -0,0 +1,79 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.db.version.v55; + +import java.util.Arrays; +import java.util.Collections; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.core.issue.IssueType; +import org.sonar.db.DbSession; +import org.sonar.db.DbTester; +import org.sonar.db.issue.IssueDto; +import org.sonar.db.version.MigrationStep; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.sonar.db.version.v55.FeedIssueTypes.tagsToType; + +public class FeedIssueTypesTest { + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedIssueTypesTest.class, "schema.sql"); + + @Test + public void test_tagsToType() { + assertThat(tagsToType(asList("misra", "bug"))).isEqualTo(IssueType.BUG); + assertThat(tagsToType(asList("misra", "security"))).isEqualTo(IssueType.VULNERABILITY); + + // "bug" has priority on "security" + assertThat(tagsToType(asList("security", "bug"))).isEqualTo(IssueType.BUG); + + // default is "code smell" + assertThat(tagsToType(asList("clumsy", "spring"))).isEqualTo(IssueType.CODE_SMELL); + assertThat(tagsToType(Collections.<String>emptyList())).isEqualTo(IssueType.CODE_SMELL); + } + + @Test + public void test_migration() throws Exception { + try (DbSession dbSession = db.getSession()) { + IssueDto codeSmell = new IssueDto().setKee("code_smell").setTags(Arrays.asList("clumsy", "spring")); + IssueDto withoutTags = new IssueDto().setKee("without_tags"); + IssueDto bug = new IssueDto().setKee("bug").setTags(Arrays.asList("clumsy", "bug")); + db.getDbClient().issueDao().insert(dbSession, codeSmell, withoutTags, bug); + dbSession.commit(); + + MigrationStep underTest = new FeedIssueTypes(db.database(), mock(System2.class)); + underTest.execute(); + + assertType("code_smell", IssueType.CODE_SMELL); + assertType("without_tags", IssueType.CODE_SMELL); + assertType("bug", IssueType.BUG); + } + } + + private void assertType(String issueKey, IssueType expectedType) { + Number type = (Number)db.selectFirst("select * from issues where kee='" + issueKey + "'").get("ISSUE_TYPE"); + assertThat(type.intValue()).isEqualTo(expectedType.getDbConstant()); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java index 84da34783be..240c0e79345 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java @@ -39,7 +39,7 @@ public class FeedRulesLongDateColumnsTest { System2 system = mock(System2.class); - MigrationStep migration = new FeedRulesLongDateColumns(db.database(), system); + MigrationStep underTest = new FeedRulesLongDateColumns(db.database(), system); @Before public void setUp() throws Exception { @@ -50,7 +50,7 @@ public class FeedRulesLongDateColumnsTest { public void execute() throws Exception { db.prepareDbUnit(getClass(), "execute.xml"); - migration.execute(); + underTest.execute(); assertThat(db.countSql("select count(*) from rules where created_at_ms is not null and updated_at_ms is not null")).isEqualTo(3); // Only 1 rules not updated diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/get_by_key.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/get_by_key.xml index 0b261a3252d..07ddc4b1729 100644 --- a/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/get_by_key.xml +++ b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/get_by_key.xml @@ -24,6 +24,7 @@ created_at="1400000000000" updated_at="1450000000000" locations="[null]" + issue_type="2" /> <issues @@ -50,6 +51,7 @@ created_at="1400000000000" updated_at="1450000000000" locations="[null]" + issue_type="2" /> </dataset> diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v55/FeedIssueTypesTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v55/FeedIssueTypesTest/schema.sql new file mode 100644 index 00000000000..b7526a5d2bb --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v55/FeedIssueTypesTest/schema.sql @@ -0,0 +1,29 @@ +CREATE TABLE "ISSUES" ( + "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "KEE" VARCHAR(50) UNIQUE NOT NULL, + "COMPONENT_UUID" VARCHAR(50), + "PROJECT_UUID" VARCHAR(50), + "RULE_ID" INTEGER, + "SEVERITY" VARCHAR(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" VARCHAR(4000), + "LINE" INTEGER, + "EFFORT_TO_FIX" DOUBLE, + "TECHNICAL_DEBT" INTEGER, + "STATUS" VARCHAR(20), + "RESOLUTION" VARCHAR(20), + "CHECKSUM" VARCHAR(1000), + "REPORTER" VARCHAR(255), + "ASSIGNEE" VARCHAR(255), + "AUTHOR_LOGIN" VARCHAR(255), + "ACTION_PLAN_KEY" VARCHAR(50) NULL, + "ISSUE_ATTRIBUTES" VARCHAR(4000), + "TAGS" VARCHAR(4000), + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "LOCATIONS" BLOB(167772150), + "ISSUE_TYPE" TINYINT +); |