From 688d9e3a2bca75972a7e6cb7833b780609d38c18 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 18 Feb 2015 14:38:06 +0100 Subject: [PATCH] SONAR-6187 Exclude requirements when getting all characteristics --- ...SubCharacteristicsComplianceMigration.java | 10 +-- ...haracteristicsComplianceMigrationTest.java | 7 ++ .../do_nothing_when_already_migrated.xml | 63 ++++++++++-------- ...iance_already_exists_as_characteristic.xml | 6 +- ...eady_exists_under_wrong_characteristic.xml | 9 ++- ...usability_exists_as_sub_characteristic.xml | 6 +- ...the_top_if_security_does_exists-result.xml | 24 ++++--- ...ity_at_the_top_if_security_does_exists.xml | 6 +- .../migrate-result.xml | 65 +++++++++++-------- .../migrate.xml | 23 ++++--- ...ecated_requirements_still_exists_in_db.xml | 14 ++++ .../schema.sql | 1 + ...ate_usability_if_already_exists-result.xml | 22 ++++--- .../update_usability_if_already_exists.xml | 9 ++- 14 files changed, 166 insertions(+), 99 deletions(-) create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java index 536c531b6f8..23d2e79e95f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java @@ -35,8 +35,6 @@ import java.sql.SQLException; import java.util.Date; import java.util.List; -import static com.google.common.collect.Lists.newArrayList; - /** * See http://jira.codehaus.org/browse/SONAR-6187 * @@ -44,8 +42,9 @@ import static com.google.common.collect.Lists.newArrayList; * and add a new sub-characteristic 'Compliance' for all characteristics. * * Nothing will be done if there's no characteristics in db, as they're all gonna be created by {@link org.sonar.server.startup.RegisterDebtModel} - * - * @since 5.0.1 + * + * Before 4.3 the characteristics table contains requirements, then when selecting characteristics we should not forget to exclude them (with a filter on rule_id IS NULL) + * */ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration extends BaseDataChange { @@ -257,7 +256,8 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration private List selectEnabledCharacteristics() throws SQLException { return context.prepareSelect( - "SELECT c.id, c.kee, c.name, c.characteristic_order, c.parent_id FROM characteristics c WHERE c.enabled=? ORDER BY c.characteristic_order") + // Exclude requirements (to not fail when coming from a version older than 4.3) + "SELECT c.id, c.kee, c.name, c.characteristic_order, c.parent_id FROM characteristics c WHERE c.enabled=? AND c.rule_id IS NULL ORDER BY c.characteristic_order") .setBoolean(1, true) .list(new CharacteristicReader()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java index d55148fd56e..a1ca4e5fe1c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java @@ -121,4 +121,11 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationT } } + @Test + public void not_fail_if_some_deprecated_requirements_still_exists_in_db() throws Exception { + db.prepareDbUnit(getClass(), "not_fail_if_some_deprecated_requirements_still_exists_in_db.xml"); + migration.execute(); + db.assertDbUnit(getClass(), "not_fail_if_some_deprecated_requirements_still_exists_in_db.xml", "characteristics"); + } + } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/do_nothing_when_already_migrated.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/do_nothing_when_already_migrated.xml index 641a92b0c39..b8ff37c389e 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/do_nothing_when_already_migrated.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/do_nothing_when_already_migrated.xml @@ -1,44 +1,53 @@ - - + + - - + + - - + - - + - - - - - - - + - - + + - - + + - - + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_as_characteristic.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_as_characteristic.xml index 337697d4bae..1f2f39bdbef 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_as_characteristic.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_as_characteristic.xml @@ -1,7 +1,9 @@ - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml index 5164abcf144..3dbfebd4153 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml @@ -1,10 +1,13 @@ - + - + - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_usability_exists_as_sub_characteristic.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_usability_exists_as_sub_characteristic.xml index 18cb033a7eb..70016cc2d9d 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_usability_exists_as_sub_characteristic.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_usability_exists_as_sub_characteristic.xml @@ -1,7 +1,9 @@ - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists-result.xml index 159e774bbf2..4f596203e6d 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists-result.xml @@ -1,26 +1,30 @@ - + - + - - - - + + - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists.xml index 1ce991c6bff..7ab9a9726ac 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists.xml @@ -1,7 +1,9 @@ - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate-result.xml index 0a78e76bfd8..91f1c6ab778 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate-result.xml @@ -1,65 +1,74 @@ - + - + - - + - + - + - + - + - + - - - + - + - + - + - + - + - + - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate.xml index 10261289eff..2d92c7cc413 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate.xml @@ -1,20 +1,27 @@ - + - + - - + - + - + - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml new file mode 100644 index 00000000000..6953f5230bb --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/not_fail_if_some_deprecated_requirements_still_exists_in_db.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/schema.sql index 9afaa00825b..98c025def6b 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/schema.sql +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/schema.sql @@ -3,6 +3,7 @@ CREATE TABLE "CHARACTERISTICS" ( "KEE" VARCHAR(100), "NAME" VARCHAR(100), "PARENT_ID" INTEGER, + "RULE_ID" INTEGER, "CHARACTERISTIC_ORDER" INTEGER, "ENABLED" BOOLEAN, "CREATED_AT" TIMESTAMP, diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists-result.xml index c4073cba9bb..1b12df0872e 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists-result.xml @@ -1,26 +1,30 @@ - + - + - + - - - + - - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists.xml index 05303878913..33d901de062 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists.xml @@ -1,10 +1,13 @@ - + - + - + -- 2.39.5