]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6187 Nothing should be done when there's no characteristic in db
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 18 Feb 2015 08:24:45 +0000 (09:24 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 18 Feb 2015 08:24:45 +0000 (09:24 +0100)
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v453/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v453/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v453/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/empty.xml [new file with mode: 0644]

index 3405ff28dceb1cdd67fcdb6d1ad7a043412d2902..68c38e32495d6ef9216a6f448ae5b1c1663cbfcc 100644 (file)
@@ -44,6 +44,8 @@ import static com.google.common.collect.Lists.newArrayList;
  * Add a new Characteristic 'Usability' with 2 sub-characteristics 'Accessibility' and 'Ease of Use'
  * 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 4.5.3
  */
 public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration extends BaseDataChange {
@@ -64,17 +66,20 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration
   public void execute(Context context) throws SQLException {
     CharacteristicsContext characteristicsContext = new CharacteristicsContext(context, system);
 
-    int usabilityOder = moveCharacteristicsDownToBeAbleToInsertUsability(characteristicsContext);
-    createOrUpdateUsabilityCharacteristicAndItsSubCharacteristic(characteristicsContext, usabilityOder);
-
-    createSubCharacteristic(characteristicsContext, "REUSABILITY" + COMPLIANCE_KEY_SUFFIX, "Reusability " + COMPLIANCE_NAME, "REUSABILITY");
-    createSubCharacteristic(characteristicsContext, "PORTABILITY" + COMPLIANCE_KEY_SUFFIX, "Portability " + COMPLIANCE_NAME, "PORTABILITY");
-    createSubCharacteristic(characteristicsContext, "MAINTAINABILITY" + COMPLIANCE_KEY_SUFFIX, "Maintainability " + COMPLIANCE_NAME, "MAINTAINABILITY");
-    createSubCharacteristic(characteristicsContext, "SECURITY" + COMPLIANCE_KEY_SUFFIX, "Security " + COMPLIANCE_NAME, "SECURITY");
-    createSubCharacteristic(characteristicsContext, "EFFICIENCY" + COMPLIANCE_KEY_SUFFIX, "Efficiency " + COMPLIANCE_NAME, "EFFICIENCY");
-    createSubCharacteristic(characteristicsContext, "CHANGEABILITY" + COMPLIANCE_KEY_SUFFIX, "Changeability " + COMPLIANCE_NAME, "CHANGEABILITY");
-    createSubCharacteristic(characteristicsContext, "RELIABILITY" + COMPLIANCE_KEY_SUFFIX, "Reliability " + COMPLIANCE_NAME, "RELIABILITY");
-    createSubCharacteristic(characteristicsContext, "TESTABILITY" + COMPLIANCE_KEY_SUFFIX, "Testability " + COMPLIANCE_NAME, "TESTABILITY");
+    // On an empty DB, there are no characteristics, they're all gonna be created after in RegisterDebtModel
+    if (!characteristicsContext.characteristics().isEmpty()) {
+      int usabilityOder = moveCharacteristicsDownToBeAbleToInsertUsability(characteristicsContext);
+      createOrUpdateUsabilityCharacteristicAndItsSubCharacteristic(characteristicsContext, usabilityOder);
+
+      createSubCharacteristic(characteristicsContext, "REUSABILITY" + COMPLIANCE_KEY_SUFFIX, "Reusability " + COMPLIANCE_NAME, "REUSABILITY");
+      createSubCharacteristic(characteristicsContext, "PORTABILITY" + COMPLIANCE_KEY_SUFFIX, "Portability " + COMPLIANCE_NAME, "PORTABILITY");
+      createSubCharacteristic(characteristicsContext, "MAINTAINABILITY" + COMPLIANCE_KEY_SUFFIX, "Maintainability " + COMPLIANCE_NAME, "MAINTAINABILITY");
+      createSubCharacteristic(characteristicsContext, "SECURITY" + COMPLIANCE_KEY_SUFFIX, "Security " + COMPLIANCE_NAME, "SECURITY");
+      createSubCharacteristic(characteristicsContext, "EFFICIENCY" + COMPLIANCE_KEY_SUFFIX, "Efficiency " + COMPLIANCE_NAME, "EFFICIENCY");
+      createSubCharacteristic(characteristicsContext, "CHANGEABILITY" + COMPLIANCE_KEY_SUFFIX, "Changeability " + COMPLIANCE_NAME, "CHANGEABILITY");
+      createSubCharacteristic(characteristicsContext, "RELIABILITY" + COMPLIANCE_KEY_SUFFIX, "Reliability " + COMPLIANCE_NAME, "RELIABILITY");
+      createSubCharacteristic(characteristicsContext, "TESTABILITY" + COMPLIANCE_KEY_SUFFIX, "Testability " + COMPLIANCE_NAME, "TESTABILITY");
+    }
   }
 
   /**
index d233b4a775ff3a9e3b41d2d941a24510507b21f5..ab44f784a89ed21c9c2eebbcb755e521ce32012f 100644 (file)
@@ -64,6 +64,13 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationT
     db.assertDbUnit(getClass(), "do_nothing_when_already_migrated.xml", "characteristics");
   }
 
+  @Test
+  public void do_nothing_when_no_characteristics() throws Exception {
+    db.prepareDbUnit(getClass(), "empty.xml");
+    migration.execute();
+    assertThat(db.count("select count(id) from characteristics")).isEqualTo(0);
+  }
+
   @Test
   public void insert_usability_at_the_top_if_security_does_exists() throws Exception {
     db.prepareDbUnit(getClass(), "insert_usability_at_the_top_if_security_does_exists.xml");
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v453/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v453/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/empty.xml
new file mode 100644 (file)
index 0000000..019d0f1
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+
+ </dataset>