aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-16 18:55:30 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-17 11:53:29 +0100
commitd16562b8ee9ff9f73c73fa83147be8632a6c1e70 (patch)
tree42a8ed601575e61ebfbaa47e66691412b2c9caf4 /sonar-db/src/test
parent9194c3363d91e37af5a4ab08d06e0e1e52194a6d (diff)
downloadsonarqube-d16562b8ee9ff9f73c73fa83147be8632a6c1e70.tar.gz
sonarqube-d16562b8ee9ff9f73c73fa83147be8632a6c1e70.zip
SONAR-7330 Add rules long date columns
Diffstat (limited to 'sonar-db/src/test')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java2
-rw-r--r--sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java50
-rw-r--r--sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java60
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabledAndNonManual.xml15
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml10
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesLongDateColumnsTest/schema.sql31
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/execute.xml29
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest/schema.sql33
8 files changed, 224 insertions, 6 deletions
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"
+ />
<rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="AvoidNull" plugin_name="squid" name="Avoid Null" description="Should avoid NULL" status="REMOVED"
note_data="[null]" note_user_login="[null]" note_created_at="[null]" description_format="HTML"
@@ -14,7 +17,10 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_coeff="[null]" default_remediation_coeff="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_description="[null]"/>
+ effort_to_fix_description="[null]"
+ created_at="2014-05-10" updated_at="2014-05-11"
+ created_at_ms="1500000000000" updated_at_ms="1600000000000"
+ />
<rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="AvoidNull" plugin_name="manual" name="Manual Rule" description="Should not appear" status="READY"
note_data="[null]" note_user_login="[null]" note_created_at="[null]" description_format="HTML"
@@ -22,6 +28,9 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_coeff="[null]" default_remediation_coeff="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_description="[null]"/>
+ effort_to_fix_description="[null]"
+ created_at="2014-05-10" updated_at="2014-05-11"
+ created_at_ms="1500000000000" updated_at_ms="1600000000000"
+ />
</dataset>
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 @@
<rules id="1" name="Null Pointer" plugin_rule_key="S001"
plugin_config_key="S1" plugin_name="java" description="[null]" priority="4" status="READY"
is_template="[false]" template_id="[null]"
- tags="bug,performance" system_tags="cwe" />
+ tags="bug,performance" system_tags="cwe"
+ created_at="2014-05-10" updated_at="2014-05-11"
+ created_at_ms="1500000000000" updated_at_ms="1600000000000"
+ />
<rules id="2" name="Slow" plugin_rule_key="S002"
plugin_config_key="S2" plugin_name="java" description="[null]" priority="4" status="BETA"
is_template="[false]" template_id="[null]"
- tags="[null]" system_tags="[null]" />
+ tags="[null]" system_tags="[null]"
+ created_at="2014-05-10" updated_at="2014-05-11"
+ created_at_ms="1500000000000" updated_at_ms="1600000000000"
+ />
</dataset>
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 @@
+<dataset>
+
+ <rules id="1" name="Null Pointer" plugin_rule_key="S001"
+ plugin_config_key="S1" plugin_name="java" description="[null]" priority="4" status="READY"
+ is_template="[false]" template_id="[null]"
+ tags="bug,performance" system_tags="cwe"
+ created_at="2014-05-12" updated_at="2014-05-13"
+ created_at_ms="[null]" updated_at_ms="[null]"
+ />
+
+ <!-- re-entrant migration - ignore the issues that are already fed with new dates -->
+ <rules id="2" name="Slow" plugin_rule_key="S002"
+ plugin_config_key="S2" plugin_name="java" description="[null]" priority="4" status="BETA"
+ is_template="[false]" template_id="[null]"
+ tags="[null]" system_tags="[null]"
+ created_at="2014-05-10" updated_at="2014-05-11"
+ created_at_ms="1000000000000" updated_at_ms="1000000000000"
+ />
+
+ <!-- NULL dates -->
+ <rules id="3" name="Down" plugin_rule_key="S003"
+ plugin_config_key="S3" plugin_name="java" description="[null]" priority="4" status="BETA"
+ is_template="[false]" template_id="[null]"
+ tags="[null]" system_tags="[null]"
+ created_at="[null]" updated_at="[null]"
+ created_at_ms="[null]" updated_at_ms="[null]"
+ />
+
+</dataset>
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
+);