]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6187 Enhance SQALE model with new characteristics
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 17 Feb 2015 16:38:34 +0000 (17:38 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 17 Feb 2015 16:38:34 +0000 (17:38 +0100)
21 files changed:
server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/resources/com/sonar/sqale/technical-debt-model.xml
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/debt/DebtMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/do_nothing_when_already_migrated.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_as_characteristic.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_compliance_already_exists_under_wrong_characteristic.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/fail_if_usability_exists_as_sub_characteristic.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists-result.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/insert_usability_at_the_top_if_security_does_exists.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate-result.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/migrate.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/schema.sql [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists-result.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest/update_usability_if_already_exists.xml [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/722_add_characteristic_usability_and_sub_characteristics_compliance.rb [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java

index 164b766f87e13e37c09bdb1e828ec86738d50aaf..c3c48665ed1dae8b5ef093bc0bd6f764705cb6bf 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.server.db.migrations.v45.DeleteMeasuresOnDeletedProfilesMigrati
 import org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigration;
 import org.sonar.server.db.migrations.v451.DeleteUnescapedActivities;
 import org.sonar.server.db.migrations.v50.*;
+import org.sonar.server.db.migrations.v501.AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration;
 
 import java.util.List;
 
@@ -73,7 +74,10 @@ public interface DatabaseMigrations {
     FeedSnapshotSourcesUpdatedAt.class,
     FeedFileSources.class,
     FeedIssueLongDates.class,
-    RemoveSortFieldFromIssueFiltersMigration.class
+    RemoveSortFieldFromIssueFiltersMigration.class,
+
+    // 5.0.1
+    AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.class
   );
 
 }
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
new file mode 100644 (file)
index 0000000..3ccc765
--- /dev/null
@@ -0,0 +1,312 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.db.migrations.v501;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.BaseDataChange;
+import org.sonar.server.db.migrations.Select;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+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
+ *
+ * Add a new Characteristic 'Usability' with 2 sub-characteristics 'Accessibility' and 'Ease of Use'
+ * and add a new sub-characteristic 'Compliance' for all characteristics.
+ *
+ * @since 5.0.1
+ */
+public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration extends BaseDataChange {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.class);
+
+  private static final String COMPLIANCE_NAME = "Compliance";
+  private static final String COMPLIANCE_KEY_SUFFIX = "_COMPLIANCE";
+
+  private final System2 system;
+
+  public AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration(Database db, System2 system) {
+    super(db);
+    this.system = system;
+  }
+
+  @Override
+  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");
+  }
+
+  /**
+   * If the characteristic 'Security' exists, the new characteristic 'Usability' should be inserted just below it,
+   * so every existing characteristics below Security should move down.
+   *
+   * If the characteristic 'Security' does not exists, the new characteristic 'Usability' should be the first one,
+   * so every existing characteristics should move down.
+   *
+   * If the characteristic 'Usability' is already at the right place, nothing will be done.
+   */
+  private int moveCharacteristicsDownToBeAbleToInsertUsability(CharacteristicsContext characteristicsContext) throws SQLException {
+    Characteristic security = characteristicsContext.findCharacteristicByKey("SECURITY");
+    Characteristic usability = characteristicsContext.findCharacteristicByKey("USABILITY");
+
+    int usabilityOder = 1;
+    int indexToStart = 0;
+    if (security != null) {
+      indexToStart = characteristicsContext.characteristics().indexOf(security) + 1;
+      usabilityOder = security.getOrder() + 1;
+    }
+
+    if (usability == null || usability.getOrder() != usabilityOder) {
+      // Move root characteristics one step lower
+      for (int i = indexToStart; i < characteristicsContext.characteristics().size(); i++) {
+        Characteristic characteristic = characteristicsContext.characteristics().get(i);
+        if (characteristic.getParentId() == null) {
+          characteristicsContext.updateCharacteristicOrder(characteristic.getKey(), characteristic.getOrder() + 1);
+        }
+      }
+    }
+    return usabilityOder;
+  }
+
+  private void createOrUpdateUsabilityCharacteristicAndItsSubCharacteristic(CharacteristicsContext characteristicsContext, int newUsabilityOrder)
+    throws SQLException {
+    String usabilityKey = "USABILITY";
+    Characteristic usability = characteristicsContext.findCharacteristicByKey(usabilityKey);
+    if (usability != null) {
+      if (usability.getOrder() != newUsabilityOrder) {
+        usability.setOrder(newUsabilityOrder);
+        characteristicsContext.updateCharacteristicOrder(usability.getKey(), usability.getOrder());
+      }
+    } else {
+      usability = new Characteristic().setKey(usabilityKey).setName("Usability").setOrder(newUsabilityOrder);
+      characteristicsContext.insertCharacteristic(usability);
+    }
+
+    createSubCharacteristic(characteristicsContext, "USABILITY_ACCESSIBILITY", "Accessibility", usabilityKey);
+    createSubCharacteristic(characteristicsContext, "USABILITY_EASE_OF_USE", "Ease of Use", usabilityKey);
+    createSubCharacteristic(characteristicsContext, "USABILITY" + COMPLIANCE_KEY_SUFFIX, "Usability " + COMPLIANCE_NAME, usabilityKey);
+  }
+
+  private void createSubCharacteristic(CharacteristicsContext characteristicsContext,
+    String subCharacteristicKey, String subCharacteristicName, String parentKey) throws SQLException {
+    Characteristic parent = characteristicsContext.findCharacteristicByKey(parentKey);
+    if (parent != null) {
+      Characteristic subCharacteristic = characteristicsContext.findSubCharacteristicByKey(subCharacteristicKey, parent);
+      if (subCharacteristic == null) {
+        characteristicsContext.insertCharacteristic(new Characteristic().setKey(subCharacteristicKey).setName(subCharacteristicName).setParentId(parent.getId()));
+      }
+    }
+    // If the characteristic parent does not exits, the sub-characteristic is not added
+  }
+
+  private static class Characteristic {
+    private Integer id;
+    private String key;
+    private String name;
+    private Integer order;
+    private Integer parentId;
+
+    public Characteristic setId(Integer id) {
+      this.id = id;
+      return this;
+    }
+
+    public Integer getId() {
+      return id;
+    }
+
+    public Characteristic setKey(String key) {
+      this.key = key;
+      return this;
+    }
+
+    public String getKey() {
+      return key;
+    }
+
+    public Characteristic setName(String name) {
+      this.name = name;
+      return this;
+    }
+
+    public String getName() {
+      return name;
+    }
+
+    public Characteristic setOrder(@Nullable Integer order) {
+      this.order = order;
+      return this;
+    }
+
+    @CheckForNull
+    public Integer getOrder() {
+      return order;
+    }
+
+    public Characteristic setParentId(@Nullable Integer parentId) {
+      this.parentId = parentId;
+      return this;
+    }
+
+    @CheckForNull
+    public Integer getParentId() {
+      return parentId;
+    }
+  }
+
+  private static class CharacteristicsContext {
+    Context context;
+    private final System2 system;
+    Date now;
+    List<Characteristic> characteristics;
+
+    public CharacteristicsContext(Context context, System2 system) throws SQLException {
+      this.context = context;
+      this.system = system;
+      init();
+    }
+
+    private void init() throws SQLException {
+      now = new Date(system.now());
+      characteristics = selectEnabledCharacteristics();
+    }
+
+    public List<Characteristic> characteristics() {
+      return characteristics;
+    }
+
+    @CheckForNull
+    public Characteristic findCharacteristicByKey(final String key) {
+      Characteristic characteristic = Iterables.find(characteristics, new Predicate<Characteristic>() {
+        @Override
+        public boolean apply(@Nullable Characteristic input) {
+          return input != null && input.key.equals(key);
+        }
+      }, null);
+      if (characteristic != null) {
+        if (characteristic.getParentId() != null) {
+          throw new IllegalStateException(String.format("'%s' must be a characteristic", characteristic.getName()));
+        }
+      }
+      return characteristic;
+    }
+
+    @CheckForNull
+    public Characteristic findSubCharacteristicByKey(final String key, Characteristic parent) {
+      Characteristic characteristic = Iterables.find(characteristics, new Predicate<Characteristic>() {
+        @Override
+        public boolean apply(@Nullable Characteristic input) {
+          return input != null && input.key.equals(key);
+        }
+      }, null);
+      if (characteristic != null) {
+        Integer parentId = characteristic.getParentId();
+        if (parentId == null) {
+          throw new IllegalStateException(String.format("'%s' must be a sub-characteristic", characteristic.getName()));
+        } else if (!characteristic.getParentId().equals(parent.getId())) {
+          throw new IllegalStateException(String.format("'%s' must be defined under '%s'", characteristic.getName(), parent.getName()));
+        }
+      }
+      return characteristic;
+    }
+
+    private List<Characteristic> 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")
+        .setBoolean(1, true)
+        .list(new CharacteristicReader());
+    }
+
+    private int selectCharacteristicId(String key) throws SQLException {
+      return context.prepareSelect(
+        "SELECT c.id FROM characteristics c WHERE c.kee = ? AND c.enabled=?")
+        .setString(1, key)
+        .setBoolean(2, true)
+        .get(Select.LONG_READER).intValue();
+    }
+
+    public void insertCharacteristic(Characteristic characteristic) throws SQLException {
+      if (characteristic.getParentId() == null) {
+        LOGGER.info("Insert new characteristic '{}'", characteristic.getKey());
+      } else {
+        LOGGER.info("Insert new sub characteristic '{}'", characteristic.getKey());
+      }
+
+      context.prepareUpsert("INSERT INTO characteristics (kee, name, parent_id, characteristic_order, enabled, created_at) VALUES (?, ?, ?, ?, ?, ?)")
+        .setString(1, characteristic.getKey())
+        .setString(2, characteristic.getName())
+        .setInt(3, characteristic.getParentId())
+        .setInt(4, characteristic.getOrder())
+        .setBoolean(5, true)
+        .setDate(6, now)
+        .execute()
+        .commit();
+      characteristic.setId(selectCharacteristicId(characteristic.getKey()));
+
+      characteristics.add(characteristic);
+    }
+
+    public void updateCharacteristicOrder(String key, Integer order) throws SQLException {
+      LOGGER.info("Update characteristic '{}' order to {}", key, order);
+
+      context.prepareUpsert("UPDATE characteristics SET characteristic_order=?, updated_at=? WHERE kee=?")
+        .setInt(1, order)
+        .setDate(2, now)
+        .setString(3, key)
+        .execute()
+        .commit();
+    }
+
+    private static class CharacteristicReader implements Select.RowReader<Characteristic> {
+      @Override
+      public Characteristic read(Select.Row row) throws SQLException {
+        return new Characteristic()
+          .setId(row.getInt(1))
+          .setKey(row.getString(2))
+          .setName(row.getString(3))
+          .setOrder(row.getInt(4))
+          .setParentId(row.getInt(5));
+      }
+    }
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/package-info.java
new file mode 100644 (file)
index 0000000..dbd5299
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.db.migrations.v501;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
index d2276e82e5dad3694407d09c0f9987a53694be77..4e3277a44b66e037a0206f33cb2f306dc1a4ab40 100644 (file)
@@ -1,24 +1,3 @@
-<!--
-
-    SonarQube, open source software quality management tool.
-    Copyright (C) 2008-2014 SonarSource
-    mailto:contact AT sonarsource DOT com
-
-    SonarQube 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.
-
-    SonarQube 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.
-
--->
 <sqale>
   <chc>
     <key>REUSABILITY</key>
@@ -27,6 +6,10 @@
       <key>MODULARITY</key>
       <name>Modularity</name>
     </chc>
+    <chc>
+      <key>REUSABILITY_COMPLIANCE</key>
+      <name>Reusability Compliance</name>
+    </chc>
     <chc>
       <key>TRANSPORTABILITY</key>
       <name>Transportability</name>
       <key>OS_RELATED_PORTABILITY</key>
       <name>OS</name>
     </chc>
+    <chc>
+      <key>PORTABILITY_COMPLIANCE</key>
+      <name>Portability Compliance</name>
+    </chc>
     <chc>
       <key>SOFTWARE_RELATED_PORTABILITY</key>
       <name>Software</name>
   <chc>
     <key>MAINTAINABILITY</key>
     <name>Maintainability</name>
+    <chc>
+      <key>MAINTAINABILITY_COMPLIANCE</key>
+      <name>Maintainability Compliance</name>
+    </chc>
     <chc>
       <key>READABILITY</key>
       <name>Readability</name>
       <key>INPUT_VALIDATION_AND_REPRESENTATION</key>
       <name>Input validation and representation</name>
     </chc>
+    <chc>
+      <key>SECURITY_COMPLIANCE</key>
+      <name>Security Compliance</name>
+    </chc>
     <chc>
       <key>SECURITY_FEATURES</key>
       <name>Security features</name>
     </chc>
   </chc>
+  <chc>
+    <key>USABILITY</key>
+    <name>Usability</name>
+    <chc>
+      <key>USABILITY_ACCESSIBILITY</key>
+      <name>Accessibility</name>
+    </chc>
+    <chc>
+      <key>USABILITY_EASE_OF_USE</key>
+      <name>Ease of Use</name>
+    </chc>
+    <chc>
+      <key>USABILITY_COMPLIANCE</key>
+      <name>Usability Compliance</name>
+    </chc>
+  </chc>
   <chc>
     <key>EFFICIENCY</key>
     <name>Efficiency</name>
       <key>CPU_EFFICIENCY</key>
       <name>Processor use</name>
     </chc>
+    <chc>
+      <key>EFFICIENCY_COMPLIANCE</key>
+      <name>Efficiency Compliance</name>
+    </chc>
     <chc>
       <key>MEMORY_EFFICIENCY</key>
       <name>Memory use</name>
       <key>ARCHITECTURE_CHANGEABILITY</key>
       <name>Architecture</name>
     </chc>
+    <chc>
+      <key>CHANGEABILITY_COMPLIANCE</key>
+      <name>Changeability Compliance</name>
+    </chc>
     <chc>
       <key>DATA_CHANGEABILITY</key>
       <name>Data</name>
       <key>LOGIC_RELIABILITY</key>
       <name>Logic</name>
     </chc>
+    <chc>
+      <key>RELIABILITY_COMPLIANCE</key>
+      <name>Reliability Compliance</name>
+    </chc>
     <chc>
       <key>RESOURCE_RELIABILITY</key>
       <name>Resource</name>
       <key>INTEGRATION_TESTABILITY</key>
       <name>Integration level</name>
     </chc>
+    <chc>
+      <key>TESTABILITY_COMPLIANCE</key>
+      <name>Testability Compliance</name>
+    </chc>
     <chc>
       <key>UNIT_TESTABILITY</key>
       <name>Unit level</name>
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
new file mode 100644 (file)
index 0000000..d540cd1
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.db.migrations.v501;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.TestDatabase;
+import org.sonar.server.db.migrations.DatabaseMigration;
+
+import static junit.framework.TestCase.fail;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest {
+
+  @ClassRule
+  public static TestDatabase db = new TestDatabase().schema(AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.class, "schema.sql");
+
+  DatabaseMigration migration;
+
+  System2 system = mock(System2.class);
+
+  @Before
+  public void setUp() throws Exception {
+    db.executeUpdateSql("truncate table characteristics");
+
+    when(system.now()).thenReturn(DateUtils.parseDate("2015-02-15").getTime());
+
+    migration = new AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration(db.database(), system);
+  }
+
+  @Test
+  public void migrate() throws Exception {
+    db.prepareDbUnit(getClass(), "migrate.xml");
+    migration.execute();
+    db.assertDbUnit(getClass(), "migrate-result.xml", "characteristics");
+  }
+
+  @Test
+  public void do_nothing_when_already_migrated() throws Exception {
+    db.prepareDbUnit(getClass(), "do_nothing_when_already_migrated.xml");
+    migration.execute();
+    db.assertDbUnit(getClass(), "do_nothing_when_already_migrated.xml", "characteristics");
+  }
+
+  @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");
+    migration.execute();
+    db.assertDbUnit(getClass(), "insert_usability_at_the_top_if_security_does_exists-result.xml", "characteristics");
+  }
+
+  @Test
+  public void update_usability_order_if_already_exists() throws Exception {
+    db.prepareDbUnit(getClass(), "update_usability_if_already_exists.xml");
+    migration.execute();
+    db.assertDbUnit(getClass(), "update_usability_if_already_exists-result.xml", "characteristics");
+  }
+
+  @Test
+  public void fail_if_usability_exists_as_sub_characteristic() throws Exception {
+    db.prepareDbUnit(getClass(), "fail_if_usability_exists_as_sub_characteristic.xml");
+
+    try {
+      migration.execute();
+      fail();
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Usability' must be a characteristic");
+    }
+  }
+
+  @Test
+  public void fail_if_compliance_already_exists_as_characteristic() throws Exception {
+    db.prepareDbUnit(getClass(), "fail_if_compliance_already_exists_as_characteristic.xml");
+
+    try {
+      migration.execute();
+      fail();
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Compliance' must be a sub-characteristic");
+    }
+  }
+
+  @Test
+  public void fail_if_compliance_already_exists_under_wrong_characteristic() throws Exception {
+    db.prepareDbUnit(getClass(), "fail_if_compliance_already_exists_under_wrong_characteristic.xml");
+
+    try {
+      migration.execute();
+      fail();
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Reusability Compliance' must be defined under 'Reusability'");
+    }
+  }
+
+}
index 6a4434ea5ef69370dad5c79bf96c33e6e9199a30..06b87b1f43aed677fa03b05437116ec080994566 100644 (file)
@@ -44,14 +44,14 @@ public class DebtMediumTest {
   }
 
   @Test
-  public void find_characteristics() throws Exception {
+  public void find_default_characteristics() throws Exception {
     DebtModelService debtModelService = serverTester.get(DebtModelService.class);
 
     // Only root characteristics
-    assertThat(debtModelService.characteristics()).hasSize(8);
+    assertThat(debtModelService.characteristics()).hasSize(9);
 
     // Characteristics and sub-characteristics
-    assertThat(debtModelService.allCharacteristics()).hasSize(39);
+    assertThat(debtModelService.allCharacteristics()).hasSize(51);
   }
 
   @Test
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
new file mode 100644 (file)
index 0000000..641a92b
--- /dev/null
@@ -0,0 +1,44 @@
+<dataset>
+
+  <characteristics id="1" kee="REUSABILITY" name="Reusability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+  <characteristics id="2" kee="REUSABILITY_COMPLIANCE" name="Reusability Compliance" parent_id="1" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+  <characteristics id="3" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="2" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+  <characteristics id="4" kee="PORTABILITY_COMPLIANCE" name="Portability Compliance" parent_id="3" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+  <characteristics id="5" kee="MAINTAINABILITY" name="Maintainability" parent_id="[null]" characteristic_order="3" enabled="[true]" created_at="2013-11-20"
+                   updated_at="2013-11-22"/>
+  <characteristics id="6" kee="MAINTAINABILITY_COMPLIANCE" name="Maintainability Compliance" parent_id="5" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+  <characteristics id="7" kee="SECURITY" name="Security" parent_id="[null]" characteristic_order="4" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+  <characteristics id="8" kee="SECURITY_COMPLIANCE" name="Security Compliance" parent_id="7" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+  <characteristics id="9" kee="USABILITY" name="Usability" parent_id="[null]" characteristic_order="5" enabled="[true]" created_at="2013-11-20" updated_at="[null]"/>
+  <characteristics id="10" kee="USABILITY_ACCESSIBILITY" name="Accessibility" parent_id="9" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+  <characteristics id="11" kee="USABILITY_EASE_OF_USE" name="Ease of Use" parent_id="9" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20" updated_at="[null]"/>
+  <characteristics id="12" kee="USABILITY_COMPLIANCE" name="Usability Compliance" parent_id="9" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+  <characteristics id="13" kee="EFFICIENCY" name="Efficiency" parent_id="[null]" characteristic_order="6" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-20"/>
+  <characteristics id="14" kee="EFFICIENCY_COMPLIANCE" name="Efficiency Compliance" parent_id="13" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+  <characteristics id="15" kee="CHANGEABILITY" name="Changeability" parent_id="[null]" characteristic_order="7" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-20"/>
+  <characteristics id="16" kee="CHANGEABILITY_COMPLIANCE" name="Changeability Compliance" parent_id="15" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+  <characteristics id="17" kee="RELIABILITY" name="Reliability" parent_id="[null]" characteristic_order="8" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-20"/>
+  <characteristics id="18" kee="RELIABILITY_COMPLIANCE" name="Reliability Compliance" parent_id="17" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+  <characteristics id="19" kee="TESTABILITY" name="Testability" parent_id="[null]" characteristic_order="9" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-20"/>
+  <characteristics id="20" kee="TESTABILITY_COMPLIANCE" name="Testability Compliance" parent_id="19" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..337697d
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+
+  <characteristics id="1" kee="REUSABILITY" name="Reusability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="2" kee="REUSABILITY_COMPLIANCE" name="Compliance" parent_id="[null]" characteristic_order="2" enabled="[true]" created_at="2013-11-20" updated_at="[null]"/>
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..5164abc
--- /dev/null
@@ -0,0 +1,10 @@
+<dataset>
+
+  <characteristics id="1" kee="REUSABILITY" name="Reusability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="2" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="2" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="3" kee="REUSABILITY_COMPLIANCE" name="Reusability Compliance" parent_id="2" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20"
+                   updated_at="[null]"/>
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..18cb033
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+
+  <characteristics id="1" kee="REUSABILITY" name="Reusability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="2" kee="USABILITY" name="Usability" parent_id="1" characteristic_order="[null]" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..159e774
--- /dev/null
@@ -0,0 +1,26 @@
+<dataset>
+
+  <!-- Oder has changed : this characteristic is now one step lower -->
+  <characteristics id="1" kee="REUSABILITY" name="Reusability" parent_id="[null]" characteristic_order="2" enabled="[true]" created_at="2013-11-20" updated_at="2015-02-15"/>
+
+  <!-- Oder has changed : this characteristic is now one step lower -->
+  <characteristics id="2" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="3" enabled="[true]" created_at="2013-11-20" updated_at="2015-02-15"/>
+
+  <!-- New characteristic 'Usability' is on the top (order 1) -->
+  <characteristics id="3" kee="USABILITY" name="Usability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2015-02-15" updated_at="[null]"/>
+  <characteristics id="4" kee="USABILITY_ACCESSIBILITY" name="Accessibility" parent_id="3" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+  <characteristics id="5" kee="USABILITY_EASE_OF_USE" name="Ease of Use" parent_id="3" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15" updated_at="[null]"/>
+  <characteristics id="6" kee="USABILITY_COMPLIANCE" name="Usability Compliance" parent_id="3" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+
+  <!-- New sub characteristic 'Compliance' under Reusability -->
+  <characteristics id="7" kee="REUSABILITY_COMPLIANCE" name="Reusability Compliance" parent_id="1" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Portability -->
+  <characteristics id="8" kee="PORTABILITY_COMPLIANCE" name="Portability Compliance" parent_id="2" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..1ce991c
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+
+  <characteristics id="1" kee="REUSABILITY" name="Reusability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="2" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="2" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..0a78e76
--- /dev/null
@@ -0,0 +1,65 @@
+<dataset>
+
+  <characteristics id="1" kee="REUSABILITY" name="Reusability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="2" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="2" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="3" kee="MAINTAINABILITY" name="Maintainability" parent_id="[null]" characteristic_order="3" enabled="[true]" created_at="2013-11-20"
+                   updated_at="2013-11-22"/>
+
+  <characteristics id="4" kee="SECURITY" name="Security" parent_id="[null]" characteristic_order="4" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <!-- Oder has changed : this characteristic is now one step lower -->
+  <characteristics id="5" kee="EFFICIENCY" name="Efficiency" parent_id="[null]" characteristic_order="6" enabled="[true]" created_at="2013-11-20" updated_at="2015-02-15"/>
+
+  <!-- Oder has changed : this characteristic is now one step lower -->
+  <characteristics id="6" kee="CHANGEABILITY" name="Changeability" parent_id="[null]" characteristic_order="7" enabled="[true]" created_at="2013-11-20" updated_at="2015-02-15"/>
+
+  <!-- Oder has changed : this characteristic is now one step lower -->
+  <characteristics id="7" kee="RELIABILITY" name="Reliability" parent_id="[null]" characteristic_order="8" enabled="[true]" created_at="2013-11-20" updated_at="2015-02-15"/>
+
+  <!-- Oder has changed : this characteristic is now one step lower -->
+  <characteristics id="8" kee="TESTABILITY" name="Testability" parent_id="[null]" characteristic_order="9" enabled="[true]" created_at="2013-11-20" updated_at="2015-02-15"/>
+
+  <!-- New characteristic 'Usability' is after Security -->
+  <characteristics id="9" kee="USABILITY" name="Usability" parent_id="[null]" characteristic_order="5" enabled="[true]" created_at="2015-02-15" updated_at="[null]"/>
+  <!-- New sub characteristics under Usability -->
+  <characteristics id="10" kee="USABILITY_ACCESSIBILITY" name="Accessibility" parent_id="9" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+  <characteristics id="11" kee="USABILITY_EASE_OF_USE" name="Ease of Use" parent_id="9" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15" updated_at="[null]"/>
+  <characteristics id="12" kee="USABILITY_COMPLIANCE" name="Usability Compliance" parent_id="9" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Reusability -->
+  <characteristics id="13" kee="REUSABILITY_COMPLIANCE" name="Reusability Compliance" parent_id="1" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Portability -->
+  <characteristics id="14" kee="PORTABILITY_COMPLIANCE" name="Portability Compliance" parent_id="2" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Maintainability -->
+  <characteristics id="15" kee="MAINTAINABILITY_COMPLIANCE" name="Maintainability Compliance" parent_id="3" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Security -->
+  <characteristics id="16" kee="SECURITY_COMPLIANCE" name="Security Compliance" parent_id="4" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Efficiency -->
+  <characteristics id="17" kee="EFFICIENCY_COMPLIANCE" name="Efficiency Compliance" parent_id="5" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Changeability -->
+  <characteristics id="18" kee="CHANGEABILITY_COMPLIANCE" name="Changeability Compliance" parent_id="6" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Reliability -->
+  <characteristics id="19" kee="RELIABILITY_COMPLIANCE" name="Reliability Compliance" parent_id="7" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Testability -->
+  <characteristics id="20" kee="TESTABILITY_COMPLIANCE" name="Testability Compliance" parent_id="8" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..1026128
--- /dev/null
@@ -0,0 +1,20 @@
+<dataset>
+
+  <characteristics id="1" kee="REUSABILITY" name="Reusability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="2" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="2" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="3" kee="MAINTAINABILITY" name="Maintainability" parent_id="[null]" characteristic_order="3" enabled="[true]" created_at="2013-11-20"
+                   updated_at="2013-11-22"/>
+
+  <characteristics id="4" kee="SECURITY" name="Security" parent_id="[null]" characteristic_order="4" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="5" kee="EFFICIENCY" name="Efficiency" parent_id="[null]" characteristic_order="5" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="6" kee="CHANGEABILITY" name="Changeability" parent_id="[null]" characteristic_order="6" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="7" kee="RELIABILITY" name="Reliability" parent_id="[null]" characteristic_order="7" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="8" kee="TESTABILITY" name="Testability" parent_id="[null]" characteristic_order="8" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..9afaa00
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "CHARACTERISTICS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "KEE" VARCHAR(100),
+  "NAME" VARCHAR(100),
+  "PARENT_ID" INTEGER,
+  "CHARACTERISTIC_ORDER" INTEGER,
+  "ENABLED" BOOLEAN,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_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
new file mode 100644 (file)
index 0000000..c4073cb
--- /dev/null
@@ -0,0 +1,26 @@
+<dataset>
+
+  <characteristics id="1" kee="SECURITY" name="Security" parent_id="[null]" characteristic_order="4" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <!-- Oder has changed : this characteristic is now one step lower -->
+  <characteristics id="2" kee="EFFICIENCY" name="Efficiency" parent_id="[null]" characteristic_order="6" enabled="[true]" created_at="2013-11-20" updated_at="2015-02-15"/>
+
+  <!-- Usability is moved after Security -->
+  <characteristics id="3" kee="USABILITY" name="Usability" parent_id="[null]" characteristic_order="5" enabled="[true]" created_at="2013-11-20" updated_at="2015-02-15"/>
+
+  <!-- New sub characteristics under Usability -->
+  <characteristics id="4" kee="USABILITY_ACCESSIBILITY" name="Accessibility" parent_id="3" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+  <characteristics id="5" kee="USABILITY_EASE_OF_USE" name="Ease of Use" parent_id="3" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15" updated_at="[null]"/>
+  <characteristics id="6" kee="USABILITY_COMPLIANCE" name="Usability Compliance" parent_id="3" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Security -->
+  <characteristics id="7" kee="SECURITY_COMPLIANCE" name="Security Compliance" parent_id="1" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+  <!-- New sub characteristic 'Compliance' under Efficiency -->
+  <characteristics id="8" kee="EFFICIENCY_COMPLIANCE" name="Efficiency Compliance" parent_id="2" characteristic_order="[null]" enabled="[true]" created_at="2015-02-15"
+                   updated_at="[null]"/>
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..0530387
--- /dev/null
@@ -0,0 +1,10 @@
+<dataset>
+
+  <characteristics id="1" kee="SECURITY" name="Security" parent_id="[null]" characteristic_order="4" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <characteristics id="2" kee="EFFICIENCY" name="Efficiency" parent_id="[null]" characteristic_order="5" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <!-- Usability should be move after Security -->
+  <characteristics id="3" kee="USABILITY" name="Usability" parent_id="[null]" characteristic_order="6" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+</dataset>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/722_add_characteristic_usability_and_sub_characteristics_compliance.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/722_add_characteristic_usability_and_sub_characteristics_compliance.rb
new file mode 100644 (file)
index 0000000..345b12e
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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.
+#
+
+#
+# SonarQube 5.0.1
+# SONAR-6187
+#
+class AddCharacteristicUsabilityAndSubCharacteristicsCompliance < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration 'org.sonar.server.db.migrations.v501.AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration'
+  end
+
+end
index 23736c1892baf758739511d815c119d49855776a..c0374db488da11c217871ca995f730e8cdf5447e 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 721;
+  public static final int LAST_VERSION = 722;
 
   /**
    * List of all the tables.
index 3cf67c0abadc9b28744cb37499c7e4cd1fca0874..441398d2cd38c9571b526236f1fe7813b063837a 100644 (file)
@@ -279,6 +279,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('718');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('719');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('720');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('721');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('722');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 75a5a2bf077a2fdb918dd60b378a2baf0ccba93d..5175925127238c71e32e71bc2970f06b80a9884a 100644 (file)
@@ -293,6 +293,61 @@ public interface RulesDefinition extends ServerExtension {
      */
     public static final String UNIT_TESTABILITY = "UNIT_TESTABILITY";
 
+    /**
+     * Related to characteristic ACCESSIBILITY
+     */
+    public static final String USABILITY_ACCESSIBILITY = "USABILITY_ACCESSIBILITY";
+
+    /**
+     * Related to characteristic ACCESSIBILITY
+     */
+    public static final String USABILITY_COMPLIANCE = "USABILITY_COMPLIANCE";
+
+    /**
+     * Related to characteristic ACCESSIBILITY
+     */
+    public static final String USABILITY_EASE_OF_USE = "USABILITY_EASE_OF_USE";
+
+    /**
+     * Related to characteristic REUSABILITY
+     */
+    public static final String REUSABILITY_COMPLIANCE = "REUSABILITY_COMPLIANCE";
+
+    /**
+     * Related to characteristic PORTABILITY
+     */
+    public static final String PORTABILITY_COMPLIANCE = "PORTABILITY_COMPLIANCE";
+
+    /**
+     * Related to characteristic MAINTAINABILITY
+     */
+    public static final String MAINTAINABILITY_COMPLIANCE = "MAINTAINABILITY_COMPLIANCE";
+
+    /**
+     * Related to characteristic SECURITY
+     */
+    public static final String SECURITY_COMPLIANCE = "SECURITY_COMPLIANCE";
+
+    /**
+     * Related to characteristic EFFICIENCY
+     */
+    public static final String EFFICIENCY_COMPLIANCE = "EFFICIENCY_COMPLIANCE";
+
+    /**
+     * Related to characteristic CHANGEABILITY
+     */
+    public static final String CHANGEABILITY_COMPLIANCE = "CHANGEABILITY_COMPLIANCE";
+
+    /**
+     * Related to characteristic RELIABILITY
+     */
+    public static final String RELIABILITY_COMPLIANCE = "RELIABILITY_COMPLIANCE";
+
+    /**
+     * Related to characteristic TESTABILITY
+     */
+    public static final String TESTABILITY_COMPLIANCE = "TESTABILITY_COMPLIANCE";
+
     private SubCharacteristics() {
       // only constants
     }