From d16562b8ee9ff9f73c73fa83147be8632a6c1e70 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 16 Feb 2016 18:55:30 +0100 Subject: SONAR-7330 Add rules long date columns --- .../sonar/db/version/MigrationStepModuleTest.java | 2 +- .../version/v55/AddRulesLongDateColumnsTest.java | 50 ++++++++++++++++++ .../version/v55/FeedRulesLongDateColumnsTest.java | 60 ++++++++++++++++++++++ .../rule/RuleDaoTest/selectEnabledAndNonManual.xml | 15 ++++-- .../org/sonar/db/rule/RuleDaoTest/shared.xml | 10 +++- .../v55/AddRulesLongDateColumnsTest/schema.sql | 31 +++++++++++ .../v55/FeedRulesLongDateColumnsTest/execute.xml | 29 +++++++++++ .../v55/FeedRulesLongDateColumnsTest/schema.sql | 33 ++++++++++++ 8 files changed, 224 insertions(+), 6 deletions(-) create mode 100644 sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java create mode 100644 sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java create mode 100644 sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesLongDateColumnsTest/schema.sql create mode 100644 sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/execute.xml create mode 100644 sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/schema.sql (limited to 'sonar-db/src/test') 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 c766bebda7d..a3153c66f31 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(51); + assertThat(container.size()).isEqualTo(53); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java new file mode 100644 index 00000000000..8e29ecb328b --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java @@ -0,0 +1,50 @@ +/* + * 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.sql.Types; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; +import org.sonar.db.version.MigrationStep; + +public class AddRulesLongDateColumnsTest { + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddRulesLongDateColumnsTest.class, "schema.sql"); + + MigrationStep migration; + + @Before + public void setUp() { + migration = new AddRulesLongDateColumns(db.database()); + } + + @Test + public void update_columns() throws Exception { + migration.execute(); + + db.assertColumnDefinition("rules", "created_at_ms", Types.BIGINT, null); + db.assertColumnDefinition("rules", "updated_at_ms", Types.BIGINT, null); + } + +} 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 new file mode 100644 index 00000000000..84da34783be --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java @@ -0,0 +1,60 @@ +/* + * 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 org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; +import org.sonar.db.version.MigrationStep; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class FeedRulesLongDateColumnsTest { + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedRulesLongDateColumnsTest.class, "schema.sql"); + + static final long NOW = 1500000000000L; + + System2 system = mock(System2.class); + + MigrationStep migration = new FeedRulesLongDateColumns(db.database(), system); + + @Before + public void setUp() throws Exception { + when(system.now()).thenReturn(NOW); + } + + @Test + public void execute() throws Exception { + db.prepareDbUnit(getClass(), "execute.xml"); + + migration.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 + assertThat(db.countSql("select count(*) from rules where created_at_ms='1000000000000' and updated_at_ms='1000000000000'")).isEqualTo(1); + } + +} diff --git a/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabledAndNonManual.xml b/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabledAndNonManual.xml index fe85e591078..59a8dae0f4f 100644 --- a/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabledAndNonManual.xml +++ b/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabledAndNonManual.xml @@ -6,7 +6,10 @@ remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET" remediation_coeff="1h" default_remediation_coeff="5d" remediation_offset="5min" default_remediation_offset="10h" - effort_to_fix_description="squid.S115.effortToFix"/> + effort_to_fix_description="squid.S115.effortToFix" + created_at="2014-05-10" updated_at="2014-05-11" + created_at_ms="1500000000000" updated_at_ms="1600000000000" + /> + effort_to_fix_description="[null]" + created_at="2014-05-10" updated_at="2014-05-11" + created_at_ms="1500000000000" updated_at_ms="1600000000000" + /> + effort_to_fix_description="[null]" + created_at="2014-05-10" updated_at="2014-05-11" + created_at_ms="1500000000000" updated_at_ms="1600000000000" + /> diff --git a/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml index d7d86c81a35..ff4211adfce 100644 --- a/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml +++ b/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml @@ -3,10 +3,16 @@ + tags="bug,performance" system_tags="cwe" + created_at="2014-05-10" updated_at="2014-05-11" + created_at_ms="1500000000000" updated_at_ms="1600000000000" + /> + tags="[null]" system_tags="[null]" + created_at="2014-05-10" updated_at="2014-05-11" + created_at_ms="1500000000000" updated_at_ms="1600000000000" + /> diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesLongDateColumnsTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesLongDateColumnsTest/schema.sql new file mode 100644 index 00000000000..0c7c17f13f8 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesLongDateColumnsTest/schema.sql @@ -0,0 +1,31 @@ +CREATE TABLE "RULES" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL, + "PLUGIN_NAME" VARCHAR(255) NOT NULL, + "DESCRIPTION" VARCHAR(16777215), + "DESCRIPTION_FORMAT" VARCHAR(20), + "PRIORITY" INTEGER, + "IS_TEMPLATE" BOOLEAN DEFAULT FALSE, + "TEMPLATE_ID" INTEGER, + "PLUGIN_CONFIG_KEY" VARCHAR(500), + "NAME" VARCHAR(200), + "STATUS" VARCHAR(40), + "LANGUAGE" VARCHAR(20), + "NOTE_DATA" CLOB(2147483647), + "NOTE_USER_LOGIN" VARCHAR(255), + "NOTE_CREATED_AT" TIMESTAMP, + "NOTE_UPDATED_AT" TIMESTAMP, + "CHARACTERISTIC_ID" INTEGER, + "DEFAULT_CHARACTERISTIC_ID" INTEGER, + "REMEDIATION_FUNCTION" VARCHAR(20), + "DEFAULT_REMEDIATION_FUNCTION" VARCHAR(20), + "REMEDIATION_COEFF" VARCHAR(20), + "DEFAULT_REMEDIATION_COEFF" VARCHAR(20), + "REMEDIATION_OFFSET" VARCHAR(20), + "DEFAULT_REMEDIATION_OFFSET" VARCHAR(20), + "EFFORT_TO_FIX_DESCRIPTION" VARCHAR(4000), + "TAGS" VARCHAR(4000), + "SYSTEM_TAGS" VARCHAR(4000), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/execute.xml b/sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/execute.xml new file mode 100644 index 00000000000..e46c1ac2ac2 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/execute.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/schema.sql new file mode 100644 index 00000000000..39f299d68c6 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/schema.sql @@ -0,0 +1,33 @@ +CREATE TABLE "RULES" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL, + "PLUGIN_NAME" VARCHAR(255) NOT NULL, + "DESCRIPTION" VARCHAR(16777215), + "DESCRIPTION_FORMAT" VARCHAR(20), + "PRIORITY" INTEGER, + "IS_TEMPLATE" BOOLEAN DEFAULT FALSE, + "TEMPLATE_ID" INTEGER, + "PLUGIN_CONFIG_KEY" VARCHAR(500), + "NAME" VARCHAR(200), + "STATUS" VARCHAR(40), + "LANGUAGE" VARCHAR(20), + "NOTE_DATA" CLOB(2147483647), + "NOTE_USER_LOGIN" VARCHAR(255), + "NOTE_CREATED_AT" TIMESTAMP, + "NOTE_UPDATED_AT" TIMESTAMP, + "CHARACTERISTIC_ID" INTEGER, + "DEFAULT_CHARACTERISTIC_ID" INTEGER, + "REMEDIATION_FUNCTION" VARCHAR(20), + "DEFAULT_REMEDIATION_FUNCTION" VARCHAR(20), + "REMEDIATION_COEFF" VARCHAR(20), + "DEFAULT_REMEDIATION_COEFF" VARCHAR(20), + "REMEDIATION_OFFSET" VARCHAR(20), + "DEFAULT_REMEDIATION_OFFSET" VARCHAR(20), + "EFFORT_TO_FIX_DESCRIPTION" VARCHAR(4000), + "TAGS" VARCHAR(4000), + "SYSTEM_TAGS" VARCHAR(4000), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "CREATED_AT_MS" BIGINT, + "UPDATED_AT_MS" BIGINT +); -- cgit v1.2.3