From 4e3786d295d26ab8a1cd94e95e807b011826a102 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 25 Sep 2013 18:54:57 +0200 Subject: SONAR-4357 Reset technical debt model --- .../java/com/sonar/sqale/technical-debt-model.xml | 159 ------------------- .../java/org/sonar/server/platform/Platform.java | 13 +- .../server/startup/RegisterTechnicalDebtModel.java | 47 ++++++ .../server/technicaldebt/TechnicalDebtManager.java | 90 ++++------- .../TechnicalDebtModelDefinition.java | 46 ------ .../technicaldebt/TechnicalDebtModelFinder.java | 24 +-- .../sonar/server/technicaldebt/XMLImporter.java | 6 +- .../com/sonar/sqale/technical-debt-model.xml | 159 +++++++++++++++++++ .../startup/RegisterTechnicalDebtModelTest.java | 43 ++++++ .../technicaldebt/TechnicalDebtManagerTest.java | 168 ++++++++------------- .../TechnicalDebtModelDefinitionTest.java | 41 ----- .../TechnicalDebtModelFinderTest.java | 9 +- .../technicaldebt/TechnicalDebtModelTest.java | 9 +- .../server/technicaldebt/XMLImporterTest.java | 3 +- ...ate_default_model_on_first_execution-result.xml | 16 ++ .../create_default_model_on_first_execution.xml | 2 + ...ments_from_plugin_on_first_execution-result.xml | 34 +++++ ...requirements_from_plugin_on_first_execution.xml | 2 + ...ve_requirements_when_resetting_model-result.xml | 56 +++++++ ...nd_remove_requirements_when_resetting_model.xml | 38 +++++ ...java-model-with-additionnale-characteristic.xml | 80 ++++++++++ .../TechnicalDebtManagerTest/fake-java-model.xml | 18 +-- .../persist_merge-result.xml | 19 --- .../TechnicalDebtManagerTest/persist_merge.xml | 12 -- .../persist_restore-result.xml | 21 --- .../TechnicalDebtManagerTest/persist_restore.xml | 15 -- .../TechnicalDebtManagerTest/reset_model.xml | 3 +- .../warn_when_restoring_unknown_rule-result.xml | 2 +- 28 files changed, 619 insertions(+), 516 deletions(-) delete mode 100644 sonar-server/src/main/java/com/sonar/sqale/technical-debt-model.xml create mode 100644 sonar-server/src/main/java/org/sonar/server/startup/RegisterTechnicalDebtModel.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtModelDefinition.java create mode 100644 sonar-server/src/main/resources/com/sonar/sqale/technical-debt-model.xml create mode 100644 sonar-server/src/test/java/org/sonar/server/startup/RegisterTechnicalDebtModelTest.java delete mode 100644 sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelDefinitionTest.java create mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_default_model_on_first_execution-result.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_default_model_on_first_execution.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_model_with_requirements_from_plugin_on_first_execution-result.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_model_with_requirements_from_plugin_on_first_execution.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/disable_characteristics_and_remove_requirements_when_resetting_model-result.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/disable_characteristics_and_remove_requirements_when_resetting_model.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/fake-java-model-with-additionnale-characteristic.xml delete mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_merge-result.xml delete mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_merge.xml delete mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_restore-result.xml delete mode 100644 sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_restore.xml (limited to 'sonar-server/src') diff --git a/sonar-server/src/main/java/com/sonar/sqale/technical-debt-model.xml b/sonar-server/src/main/java/com/sonar/sqale/technical-debt-model.xml deleted file mode 100644 index 2a35e4f003f..00000000000 --- a/sonar-server/src/main/java/com/sonar/sqale/technical-debt-model.xml +++ /dev/null @@ -1,159 +0,0 @@ - - - - PORTABILITY - Portability - - COMPILER_RELATED_PORTABILITY - Compiler - - - HARDWARE_RELATED_PORTABILITY - Hardware - - - LANGUAGE_RELATED_PORTABILITY - Language - - - OS_RELATED_PORTABILITY - OS - - - SOFTWARE_RELATED_PORTABILITY - Software - - - TIME_ZONE_RELATED_PORTABILITY - Time zone - - - - MAINTAINABILITY - Maintainability - - READABILITY - Readability - - - UNDERSTANDABILITY - Understandability - - - - SECURITY - Security - - API_ABUSE - API abuse - - - ERRORS - Errors - - - INPUT_VALIDATION_AND_REPRESENTATION - Input validation and representation - - - SECURITY_FEATURES - Security features - - - - EFFICIENCY - Efficiency - - MEMORY_EFFICIENCY - Memory use - - - CPU_EFFICIENCY - Processor use - - - - CHANGEABILITY - Changeability - - ARCHITECTURE_CHANGEABILITY - Architecture - - - DATA_CHANGEABILITY - Data - - - LOGIC_CHANGEABILITY - Logic - - - - RELIABILITY - Reliability - - ARCHITECTURE_RELIABILITY - Architecture - - - DATA_RELIABILITY - Data - - - EXCEPTION_HANDLING - Exception handling - - - FAULT_TOLERANCE - Fault tolerance - - - INSTRUCTION_RELIABILITY - Instruction - - - LOGIC_RELIABILITY - Logic - - - SYNCHRONIZATION_RELIABILITY - Synchronization - - - UNIT_TESTS - Unit tests - - - - TESTABILITY - Testability - - INTEGRATION_TESTABILITY - Integration level - - - UNIT_TESTABILITY - Unit level - - - diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 9949cb18e2e..6e2f73aaae1 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -75,10 +75,10 @@ import org.sonar.server.component.DefaultComponentFinder; import org.sonar.server.component.DefaultRubyComponentService; import org.sonar.server.configuration.Backup; import org.sonar.server.configuration.ProfilesManager; -import org.sonar.server.db.migrations.DatabaseMigration; -import org.sonar.server.db.migrations.DatabaseMigrator; import org.sonar.server.db.EmbeddedDatabaseFactory; +import org.sonar.server.db.migrations.DatabaseMigration; import org.sonar.server.db.migrations.DatabaseMigrations; +import org.sonar.server.db.migrations.DatabaseMigrator; import org.sonar.server.issue.*; import org.sonar.server.notifications.NotificationCenter; import org.sonar.server.notifications.NotificationService; @@ -90,6 +90,9 @@ import org.sonar.server.rule.RubyRuleService; import org.sonar.server.rules.ProfilesConsole; import org.sonar.server.rules.RulesConsole; import org.sonar.server.startup.*; +import org.sonar.server.technicaldebt.TechnicalDebtManager; +import org.sonar.server.technicaldebt.TechnicalDebtModelFinder; +import org.sonar.server.technicaldebt.XMLImporter; import org.sonar.server.text.MacroInterpreter; import org.sonar.server.text.RubyTextService; import org.sonar.server.ui.*; @@ -307,6 +310,11 @@ public final class Platform { // rules servicesContainer.addSingleton(RubyRuleService.class); + // technical debt + servicesContainer.addSingleton(TechnicalDebtManager.class); + servicesContainer.addSingleton(TechnicalDebtModelFinder.class); + servicesContainer.addSingleton(XMLImporter.class); + // text servicesContainer.addSingleton(MacroInterpreter.class); servicesContainer.addSingleton(RubyTextService.class); @@ -337,6 +345,7 @@ public final class Platform { startupContainer.addSingleton(RegisterNewProfiles.class); startupContainer.addSingleton(JdbcDriverDeployer.class); startupContainer.addSingleton(RegisterQualityModels.class); +// startupContainer.addSingleton(RegisterTechnicalDebtModel.class); startupContainer.addSingleton(DeleteDeprecatedMeasures.class); startupContainer.addSingleton(GeneratePluginIndex.class); startupContainer.addSingleton(GenerateBootstrapIndex.class); diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterTechnicalDebtModel.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterTechnicalDebtModel.java new file mode 100644 index 00000000000..645082c8a84 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterTechnicalDebtModel.java @@ -0,0 +1,47 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.startup; + +import org.sonar.api.rules.RuleFinder; +import org.sonar.api.utils.ValidationMessages; +import org.sonar.server.technicaldebt.RuleCache; +import org.sonar.server.technicaldebt.TechnicalDebtManager; + +public final class RegisterTechnicalDebtModel { + + public static final String TECHNICAL_DEBT_MODEL = "TECHNICAL_DEBT"; + + private final TechnicalDebtManager technicalDebtManager; + private final RuleFinder ruleFinder; + + /** + * @param registerRulesBeforeModels used only to be started after the creation of check templates + */ + public RegisterTechnicalDebtModel(TechnicalDebtManager technicalDebtManager, RuleFinder ruleFinder, RegisterRules registerRulesBeforeModels) { + this.technicalDebtManager = technicalDebtManager; + this.ruleFinder = ruleFinder; + } + + public void start() { + RuleCache ruleCache = new RuleCache(ruleFinder); + technicalDebtManager.reset(ValidationMessages.create(), ruleCache); + } + +} diff --git a/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtManager.java b/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtManager.java index e4bf7f73cf0..5387b1d9178 100644 --- a/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtManager.java +++ b/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtManager.java @@ -29,10 +29,10 @@ import org.sonar.api.qualitymodel.Model; import org.sonar.api.qualitymodel.ModelFinder; import org.sonar.api.utils.ValidationMessages; import org.sonar.jpa.session.DatabaseSessionFactory; +import org.sonar.server.startup.RegisterTechnicalDebtModel; import java.io.Reader; import java.util.Collection; -import java.util.List; /** * TODO test merge properties + property.value + text_value @@ -42,6 +42,8 @@ public class TechnicalDebtManager implements ServerExtension { private static final Logger LOG = LoggerFactory.getLogger(TechnicalDebtManager.class); + private static final int REQUIREMENT_LEVEL = 3; + private DatabaseSessionFactory sessionFactory; private ModelFinder modelFinder; private TechnicalDebtModelFinder languageModelFinder; @@ -55,69 +57,30 @@ public class TechnicalDebtManager implements ServerExtension { this.importer = importer; } - public void restore(Model model, ValidationMessages messages, RuleCache rulesCache) { - Model persisted = modelFinder.findByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - if (persisted != null) { - disable(persisted); - } - merge(model, messages, rulesCache); - } - - public Model resetModel(ValidationMessages messages, RuleCache ruleCache) { - Model persisted = modelFinder.findByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - if (persisted != null) { - disable(persisted); - } + public Model reset(ValidationMessages messages, RuleCache rulesCache) { + DatabaseSession session = sessionFactory.getSession(); - Model model = modelFinder.findByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - importDefaultSqaleModel(model, messages, ruleCache); - populateModelWithInitialValues(model, messages, ruleCache); + resetExistingModel(); + Model model = populateModel(messages, rulesCache); - DatabaseSession session = sessionFactory.getSession(); session.save(model); session.commit(); - return model; } - public Model createInitialModel(ValidationMessages messages, RuleCache ruleCache) { - Model initialModel = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - importDefaultSqaleModel(initialModel, messages, ruleCache); - populateModelWithInitialValues(initialModel, messages, ruleCache); - return initialModel; - } - - public void merge(List pluginKeys, ValidationMessages messages, RuleCache ruleCache) { - for (String pluginKey : pluginKeys) { - ValidationMessages currentMessages = ValidationMessages.create(); - Model model = null; - Reader xmlFileReader = null; - try { - xmlFileReader = languageModelFinder.createReaderForXMLFile(pluginKey); - model = importer.importXML(xmlFileReader, currentMessages, ruleCache); - } finally { - IOUtils.closeQuietly(xmlFileReader); - } - if (!currentMessages.hasErrors()) { - merge(model, messages, ruleCache); - } else { - for (String error : currentMessages.getErrors()) { - messages.addErrorText(error); - } - } - } + private Model populateModel(ValidationMessages messages, RuleCache ruleCache) { + Model model = getModel(); + importDefaultModel(model, messages, ruleCache); + populateModelWithInitialValues(model, messages, ruleCache); + return model; } - public void merge(Model with, ValidationMessages messages, RuleCache ruleCache) { - DatabaseSession session = sessionFactory.getSession(); - Model sqale = modelFinder.findByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - if (sqale == null) { - sqale = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - session.saveWithoutFlush(sqale); + private Model getModel() { + Model existingModel = modelFinder.findByName(RegisterTechnicalDebtModel.TECHNICAL_DEBT_MODEL); + if (existingModel == null) { + return Model.createByName(RegisterTechnicalDebtModel.TECHNICAL_DEBT_MODEL); } - new TechnicalDebtModel(sqale).mergeWith(with, messages, ruleCache); - session.saveWithoutFlush(sqale); - session.commit(); + return existingModel; } private void populateModelWithInitialValues(Model initialModel, ValidationMessages messages, RuleCache ruleCache) { @@ -126,12 +89,15 @@ public class TechnicalDebtManager implements ServerExtension { } } + private void importDefaultModel(Model initialModel, ValidationMessages messages, RuleCache ruleCache) { + mergePlugin(initialModel, TechnicalDebtModelFinder.DEFAULT_MODEL, messages, ruleCache); + } + private void mergePlugin(Model initialModel, String pluginKey, ValidationMessages messages, RuleCache ruleCache) { Model model = null; Reader xmlFileReader = null; try { xmlFileReader = languageModelFinder.createReaderForXMLFile(pluginKey); - model = importer.importXML(xmlFileReader, messages, ruleCache); } finally { IOUtils.closeQuietly(xmlFileReader); @@ -143,18 +109,18 @@ public class TechnicalDebtManager implements ServerExtension { } } - private void disable(Model persisted) { - for (Characteristic root : persisted.getRootCharacteristics()) { - persisted.removeCharacteristic(root); + private void resetExistingModel() { + Model existingModel = modelFinder.findByName(RegisterTechnicalDebtModel.TECHNICAL_DEBT_MODEL); + if (existingModel != null) { + for (Characteristic root : existingModel.getCharacteristicsByDepth(REQUIREMENT_LEVEL)) { + existingModel.removeCharacteristic(root); + } + sessionFactory.getSession().commit(); } - sessionFactory.getSession().commit(); } private Collection getContributingPluginListWithoutSqale(){ return languageModelFinder.getContributingPluginList(); } - private void importDefaultSqaleModel(Model initialModel, ValidationMessages messages, RuleCache ruleCache) { - mergePlugin(initialModel, TechnicalDebtModelFinder.DEFAULT_MODEL, messages, ruleCache); - } } diff --git a/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtModelDefinition.java b/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtModelDefinition.java deleted file mode 100644 index 17da4ae421c..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtModelDefinition.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.technicaldebt; - -import org.sonar.api.qualitymodel.Model; -import org.sonar.api.qualitymodel.ModelDefinition; -import org.sonar.api.rules.RuleFinder; -import org.sonar.api.utils.ValidationMessages; - -public final class TechnicalDebtModelDefinition extends ModelDefinition { - - public static final String TECHNICAL_DEBT_MODEL = "TECHNICAL_DEBT"; - - private final TechnicalDebtManager technicalDebtManager; - private final RuleFinder ruleFinder; - - public TechnicalDebtModelDefinition(TechnicalDebtManager technicalDebtManager, RuleFinder ruleFinder) { - super(TECHNICAL_DEBT_MODEL); - this.technicalDebtManager = technicalDebtManager; - this.ruleFinder = ruleFinder; - } - - @Override - public Model createModel() { - RuleCache ruleCache = new RuleCache(ruleFinder); - return technicalDebtManager.createInitialModel(ValidationMessages.create(), ruleCache); - } - -} diff --git a/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtModelFinder.java b/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtModelFinder.java index f893f4ce6be..a90a38a65ea 100644 --- a/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtModelFinder.java +++ b/sonar-server/src/main/java/org/sonar/server/technicaldebt/TechnicalDebtModelFinder.java @@ -55,10 +55,6 @@ public class TechnicalDebtModelFinder implements ServerExtension, Startable { private PluginRepository pluginRepository; private Map contributingPluginKeyToClassLoader; - /** - * - * @param pluginRepository - */ public TechnicalDebtModelFinder(PluginRepository pluginRepository) { this.pluginRepository = pluginRepository; this.xmlFilePrefix = XML_FILE_PREFIX; @@ -90,20 +86,23 @@ public class TechnicalDebtModelFinder implements ServerExtension, Startable { for (PluginMetadata metadata : pluginRepository.getMetadata()) { String pluginKey = metadata.getKey(); ClassLoader classLoader = pluginRepository.getPlugin(pluginKey).getClass().getClassLoader(); - if (classLoader.getResource(getXMLFilePathForPlugin(pluginKey)) != null) { + if (classLoader.getResource(getXMLFilePath(pluginKey)) != null) { contributingPluginKeyToClassLoader.put(pluginKey, classLoader); } } + // Add default model + contributingPluginKeyToClassLoader.put(DEFAULT_MODEL, getClass().getClassLoader()); } contributingPluginKeyToClassLoader = Collections.unmodifiableMap(contributingPluginKeyToClassLoader); } - protected String getXMLFilePathForPlugin(String pluginKey) { - return xmlFilePrefix + pluginKey + XML_FILE_SUFFIX; + @VisibleForTesting + String getXMLFilePath(String model) { + return xmlFilePrefix + model + XML_FILE_SUFFIX; } /** - * Returns the list of plugins that can contribute to the SQALE model (without the default model provided by this plugin). + * Returns the list of plugins that can contribute to the technical debt model (without the default model). * * @return the list of plugin keys */ @@ -115,16 +114,21 @@ public class TechnicalDebtModelFinder implements ServerExtension, Startable { /** * Creates a new {@link java.io.Reader} for the XML file that contains the model contributed by the given plugin. - * + * * @param pluginKey the key of the plugin that contributes the XML file * @return the reader, that must be closed once its use is finished. */ public Reader createReaderForXMLFile(String pluginKey) { ClassLoader classLoader = contributingPluginKeyToClassLoader.get(pluginKey); - String xmlFilePath = getXMLFilePathForPlugin(pluginKey); + String xmlFilePath = getXMLFilePath(pluginKey); return new InputStreamReader(classLoader.getResourceAsStream(xmlFilePath)); } + @VisibleForTesting + Map getContributingPluginKeyToClassLoader(){ + return contributingPluginKeyToClassLoader; + } + /** * {@inheritDoc} */ diff --git a/sonar-server/src/main/java/org/sonar/server/technicaldebt/XMLImporter.java b/sonar-server/src/main/java/org/sonar/server/technicaldebt/XMLImporter.java index 95e81e2e22a..8ffa024f8de 100644 --- a/sonar-server/src/main/java/org/sonar/server/technicaldebt/XMLImporter.java +++ b/sonar-server/src/main/java/org/sonar/server/technicaldebt/XMLImporter.java @@ -33,6 +33,7 @@ import org.sonar.api.qualitymodel.Characteristic; import org.sonar.api.qualitymodel.Model; import org.sonar.api.rules.Rule; import org.sonar.api.utils.ValidationMessages; +import org.sonar.server.startup.RegisterTechnicalDebtModel; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; @@ -50,7 +51,7 @@ public class XMLImporter implements ServerExtension { } public Model importXML(Reader xml, ValidationMessages messages, RuleCache repositoryCache) { - Model sqale = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); + Model sqale = Model.createByName(RegisterTechnicalDebtModel.TECHNICAL_DEBT_MODEL); try { SMInputFactory inputFactory = initStax(); SMHierarchicCursor cursor = inputFactory.rootElementCursor(xml); @@ -81,8 +82,7 @@ public class XMLImporter implements ServerExtension { return new SMInputFactory(xmlFactory); } - private Characteristic processCharacteristic(Model sqale, SMInputCursor chcCursor, ValidationMessages messages, - RuleCache ruleCache) throws XMLStreamException { + private Characteristic processCharacteristic(Model sqale, SMInputCursor chcCursor, ValidationMessages messages, RuleCache ruleCache) throws XMLStreamException { Characteristic characteristic = Characteristic.create(); SMInputCursor cursor = chcCursor.childElementCursor(); diff --git a/sonar-server/src/main/resources/com/sonar/sqale/technical-debt-model.xml b/sonar-server/src/main/resources/com/sonar/sqale/technical-debt-model.xml new file mode 100644 index 00000000000..2a35e4f003f --- /dev/null +++ b/sonar-server/src/main/resources/com/sonar/sqale/technical-debt-model.xml @@ -0,0 +1,159 @@ + + + + PORTABILITY + Portability + + COMPILER_RELATED_PORTABILITY + Compiler + + + HARDWARE_RELATED_PORTABILITY + Hardware + + + LANGUAGE_RELATED_PORTABILITY + Language + + + OS_RELATED_PORTABILITY + OS + + + SOFTWARE_RELATED_PORTABILITY + Software + + + TIME_ZONE_RELATED_PORTABILITY + Time zone + + + + MAINTAINABILITY + Maintainability + + READABILITY + Readability + + + UNDERSTANDABILITY + Understandability + + + + SECURITY + Security + + API_ABUSE + API abuse + + + ERRORS + Errors + + + INPUT_VALIDATION_AND_REPRESENTATION + Input validation and representation + + + SECURITY_FEATURES + Security features + + + + EFFICIENCY + Efficiency + + MEMORY_EFFICIENCY + Memory use + + + CPU_EFFICIENCY + Processor use + + + + CHANGEABILITY + Changeability + + ARCHITECTURE_CHANGEABILITY + Architecture + + + DATA_CHANGEABILITY + Data + + + LOGIC_CHANGEABILITY + Logic + + + + RELIABILITY + Reliability + + ARCHITECTURE_RELIABILITY + Architecture + + + DATA_RELIABILITY + Data + + + EXCEPTION_HANDLING + Exception handling + + + FAULT_TOLERANCE + Fault tolerance + + + INSTRUCTION_RELIABILITY + Instruction + + + LOGIC_RELIABILITY + Logic + + + SYNCHRONIZATION_RELIABILITY + Synchronization + + + UNIT_TESTS + Unit tests + + + + TESTABILITY + Testability + + INTEGRATION_TESTABILITY + Integration level + + + UNIT_TESTABILITY + Unit level + + + diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterTechnicalDebtModelTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterTechnicalDebtModelTest.java new file mode 100644 index 00000000000..e2f5596a562 --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterTechnicalDebtModelTest.java @@ -0,0 +1,43 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.startup; + +import org.junit.Test; +import org.sonar.api.rules.RuleFinder; +import org.sonar.api.utils.ValidationMessages; +import org.sonar.server.technicaldebt.RuleCache; +import org.sonar.server.technicaldebt.TechnicalDebtManager; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.*; + +public class RegisterTechnicalDebtModelTest { + + @Test + public void shouldCreateModel() throws Exception { + TechnicalDebtManager technicalDebtManager = mock(TechnicalDebtManager.class); + RuleFinder ruleFinder = mock(RuleFinder.class); + RegisterTechnicalDebtModel sqaleDefinition = new RegisterTechnicalDebtModel(technicalDebtManager, ruleFinder, null); + + sqaleDefinition.start(); + + verify(technicalDebtManager, times(1)).reset(any(ValidationMessages.class), any(RuleCache.class)); + } +} diff --git a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtManagerTest.java b/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtManagerTest.java index 2472c1d3ae1..099387fa9d7 100644 --- a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtManagerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtManagerTest.java @@ -20,7 +20,6 @@ package org.sonar.server.technicaldebt; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import com.google.common.io.Resources; import org.junit.Before; import org.junit.Test; @@ -45,146 +44,112 @@ import static org.mockito.Mockito.when; public class TechnicalDebtManagerTest extends AbstractDbUnitTestCase { private TechnicalDebtManager manager; - private TechnicalDebtModelFinder TechnicalDebtModelFinder; + private TechnicalDebtModelFinder technicalDebtModelFinder = mock(TechnicalDebtModelFinder.class); @Before public void init() throws Exception { - TechnicalDebtModelFinder = mock(TechnicalDebtModelFinder.class); - when(TechnicalDebtModelFinder.getContributingPluginList()).thenReturn(ImmutableList.of("java", "technical-debt")); - when(TechnicalDebtModelFinder.createReaderForXMLFile("java")).thenReturn( + technicalDebtModelFinder = mock(TechnicalDebtModelFinder.class); + when(technicalDebtModelFinder.getContributingPluginList()).thenReturn(ImmutableList.of("java")); + when(technicalDebtModelFinder.createReaderForXMLFile("java")).thenReturn( new FileReader(Resources.getResource(TechnicalDebtManagerTest.class, "TechnicalDebtManagerTest/fake-java-model.xml").getPath())); - // Mock default sqale model - when(TechnicalDebtModelFinder.createReaderForXMLFile("technical-debt")).thenReturn( + // Mock default model + when(technicalDebtModelFinder.createReaderForXMLFile("technical-debt")).thenReturn( new FileReader(Resources.getResource(TechnicalDebtManagerTest.class, "TechnicalDebtManagerTest/fake-default-model.xml").getPath())); - manager = new TechnicalDebtManager(getSessionFactory(), new DefaultModelFinder(getSessionFactory()), TechnicalDebtModelFinder, new XMLImporter()); + manager = new TechnicalDebtManager(getSessionFactory(), new DefaultModelFinder(getSessionFactory()), technicalDebtModelFinder, new XMLImporter()); } @Test - public void reset_model() { - setupData("reset_model"); + public void create_only_default_model_on_first_execution_when_no_plugin() throws Exception { + setupData("create_default_model_on_first_execution"); - Model model = manager.resetModel(ValidationMessages.create(), defaultRuleCache()); - assertThat(model.getCharacteristics().size()).isGreaterThan(3); - assertThat(model.getCharacteristics().size()).isGreaterThan(model.getRootCharacteristics().size()); - for (Characteristic portabilityCharacteristic : model.getCharacteristicByKey("PORTABILITY").getChildren()) { - assertThat(portabilityCharacteristic.getName()).contains("portability"); - Characteristic requirement = portabilityCharacteristic.getChildren().get(0); - assertThat(requirement).isNotNull(); - Rule rule = requirement.getRule(); - assertThat(rule).isNotNull(); - assertThat(rule.getName()).isEqualTo("Regular exp"); - } - assertThat(model.getCharacteristicByKey("testability")).isNull(); - assertThat(model.getCharacteristicByKey("unit_testability")).isNull(); + TechnicalDebtModelFinder technicalDebtModelFinder = mock(TechnicalDebtModelFinder.class); + when(technicalDebtModelFinder.createReaderForXMLFile("technical-debt")).thenReturn( + new FileReader(Resources.getResource(TechnicalDebtManagerTest.class, "TechnicalDebtManagerTest/fake-default-model.xml").getPath())); + + TechnicalDebtManager manager = new TechnicalDebtManager(getSessionFactory(), new DefaultModelFinder(getSessionFactory()), technicalDebtModelFinder, new XMLImporter()); + manager.reset(ValidationMessages.create(), defaultRuleCache()); + getSession().commit(); + + checkTables("create_default_model_on_first_execution", "quality_models", "characteristics", "characteristic_edges"); } @Test - public void provided_plugin_should_not_override_default_model_when_resetting_model() throws FileNotFoundException { - setupData("reset_model"); + public void create_model_with_requirements_from_plugin_on_first_execution() throws Exception { + setupData("create_model_with_requirements_from_plugin_on_first_execution"); - Model model = manager.resetModel(ValidationMessages.create(), defaultRuleCache()); - // Default model values - assertThat(model.getCharacteristicByKey("PORTABILITY").getName()).isEqualTo("Portability"); - assertThat(model.getCharacteristicByKey("COMPILER_RELATED_PORTABILITY").getName()).isEqualTo("Compiler related portability"); - assertThat(model.getCharacteristicByKey("HARDWARE_RELATED_PORTABILITY").getName()).isEqualTo("Hardware related portability"); - assertThat(model.getCharacteristicByKey("MAINTAINABILITY").getName()).isEqualTo("Maintainability"); + TechnicalDebtModelFinder technicalDebtModelFinder = mock(TechnicalDebtModelFinder.class); - // Plugin has renamed it the value stay as defined by default model - assertThat(model.getCharacteristicByKey("READABILITY").getName()).isEqualTo("Readability"); + when(technicalDebtModelFinder.getContributingPluginList()).thenReturn(ImmutableList.of("java")); + when(technicalDebtModelFinder.createReaderForXMLFile("java")).thenReturn( + new FileReader(Resources.getResource(TechnicalDebtManagerTest.class, "TechnicalDebtManagerTest/fake-java-model.xml").getPath())); + when(technicalDebtModelFinder.createReaderForXMLFile("technical-debt")).thenReturn( + new FileReader(Resources.getResource(TechnicalDebtManagerTest.class, "TechnicalDebtManagerTest/fake-default-model.xml").getPath())); + + RuleCache ruleCache = mock(RuleCache.class); + Rule rule1 = Rule.create("checkstyle", "import", "Regular expression"); + rule1.setId(1); + when(ruleCache.getRule("checkstyle", "import")).thenReturn(rule1); + Rule rule2 = Rule.create("checkstyle", "export", "Regular expression"); + rule2.setId(2); + when(ruleCache.getRule("checkstyle", "export")).thenReturn(rule2); - // Characteristic provided only by the plugin - assertThat(model.getCharacteristicByKey("UNDERSTANDABILITY").getName()).isEqualTo("Understandability related maintainability"); + TechnicalDebtManager manager = new TechnicalDebtManager(getSessionFactory(), new DefaultModelFinder(getSessionFactory()), technicalDebtModelFinder, new XMLImporter()); + manager.reset(ValidationMessages.create(), ruleCache); + getSession().commit(); + + checkTables("create_model_with_requirements_from_plugin_on_first_execution", "quality_models", "characteristics", "characteristic_edges", "characteristic_properties"); } @Test - public void not_fail_if_unknown_rule_when_resetting_model() { - setupData("reset_model"); + public void disable_characteristics_and_remove_requirements_when_resetting_model() throws Exception { + setupData("disable_characteristics_and_remove_requirements_when_resetting_model"); - RuleFinder ruleFinder = mock(RuleFinder.class); - when(ruleFinder.findByKey(anyString(), anyString())).thenReturn(null); + TechnicalDebtModelFinder technicalDebtModelFinder = mock(TechnicalDebtModelFinder.class); - manager = new TechnicalDebtManager(getSessionFactory(), new DefaultModelFinder(getSessionFactory()), - TechnicalDebtModelFinder, new XMLImporter()); + when(technicalDebtModelFinder.getContributingPluginList()).thenReturn(ImmutableList.of("java")); + when(technicalDebtModelFinder.createReaderForXMLFile("java")).thenReturn( + new FileReader(Resources.getResource(TechnicalDebtManagerTest.class, "TechnicalDebtManagerTest/fake-java-model.xml").getPath())); + when(technicalDebtModelFinder.createReaderForXMLFile("technical-debt")).thenReturn( + new FileReader(Resources.getResource(TechnicalDebtManagerTest.class, "TechnicalDebtManagerTest/fake-default-model.xml").getPath())); - Model model = manager.resetModel(ValidationMessages.create(), new RuleCache(ruleFinder)); - assertThat(model.getCharacteristics().size()).isGreaterThanOrEqualTo(3); - assertThat(model.getCharacteristics().size()).isGreaterThan(model.getRootCharacteristics().size()); - List hardwareControls = model.getCharacteristicByKey("HARDWARE_RELATED_PORTABILITY").getChildren(); - assertThat(hardwareControls.isEmpty()).isTrue(); + TechnicalDebtManager manager = new TechnicalDebtManager(getSessionFactory(), new DefaultModelFinder(getSessionFactory()), technicalDebtModelFinder, new XMLImporter()); + manager.reset(ValidationMessages.create(), defaultRuleCache()); + getSession().commit(); + + checkTables("disable_characteristics_and_remove_requirements_when_resetting_model", "quality_models", "characteristics", "characteristic_edges", "characteristic_properties"); } @Test - public void create_initial_model() { - Model model = manager.createInitialModel(ValidationMessages.create(), defaultRuleCache()); - + public void provided_plugin_should_not_override_default_model_when_resetting_model() throws FileNotFoundException { + Model model = manager.reset(ValidationMessages.create(), defaultRuleCache()); // Default model values assertThat(model.getCharacteristicByKey("PORTABILITY").getName()).isEqualTo("Portability"); assertThat(model.getCharacteristicByKey("COMPILER_RELATED_PORTABILITY").getName()).isEqualTo("Compiler related portability"); assertThat(model.getCharacteristicByKey("HARDWARE_RELATED_PORTABILITY").getName()).isEqualTo("Hardware related portability"); assertThat(model.getCharacteristicByKey("MAINTAINABILITY").getName()).isEqualTo("Maintainability"); - // Plugin has renamed it the value stay as defined by default model + // Plugin has renamed it, but the value should stay as defined by default model assertThat(model.getCharacteristicByKey("READABILITY").getName()).isEqualTo("Readability"); - - // Characteristic provided only by the plugin - assertThat(model.getCharacteristicByKey("UNDERSTANDABILITY").getName()).isEqualTo("Understandability related maintainability"); - } - - @Test - public void persist_merge() { - setupData("persist_merge"); - - Model with = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - Characteristic efficiency = with.createCharacteristicByKey("efficiency", "Efficiency"); - Characteristic ramEfficiency = with.createCharacteristicByKey("ram-efficiency", "RAM Efficiency"); - efficiency.addChild(ramEfficiency); - ramEfficiency.addChild(with.createCharacteristicByRule(newRegexpRule())); - - manager.merge(with, ValidationMessages.create(), defaultRuleCache()); - - checkTables("persist_merge", "quality_models", "characteristics", "characteristic_edges"); - } - - @Test - public void persist_merge_with_plugin_files() throws Exception { - setupData("persist_merge"); - - manager.merge(Lists.newArrayList("java"), ValidationMessages.create(), defaultRuleCache()); - - Model model = (new DefaultModelFinder(getSessionFactory())).findByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - assertThat(model.getCharacteristics()).contains(Characteristic.createByKey("PORTABILITY", "Portability")); } @Test - public void persist_restore() { - setupData("persist_restore"); - - Model with = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - Characteristic efficiency = with.createCharacteristicByKey("efficiency", "Efficiency"); - Characteristic ramEfficiency = with.createCharacteristicByKey("ram-efficiency", "RAM Efficiency"); - efficiency.addChild(ramEfficiency); - ramEfficiency.addChild(with.createCharacteristicByRule(newRegexpRule())); - - manager.restore(with, ValidationMessages.create(), defaultRuleCache()); - - checkTables("persist_restore", "quality_models", "characteristics", "characteristic_edges"); - } + public void no_failure_on_unknown_rule_when_resetting_model() { + setupData("reset_model"); - @Test - public void warn_when_restoring_unknown_rule() { - setupData("warn_when_restoring_unknown_rule"); + RuleFinder ruleFinder = mock(RuleFinder.class); + when(ruleFinder.findByKey(anyString(), anyString())).thenReturn(null); - Model with = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); - Characteristic efficiency = with.createCharacteristicByKey("efficiency", "Efficiency"); - efficiency.addChild(with.createCharacteristicByRule(newRegexpRule())); + manager = new TechnicalDebtManager(getSessionFactory(), new DefaultModelFinder(getSessionFactory()), technicalDebtModelFinder, new XMLImporter()); ValidationMessages messages = ValidationMessages.create(); - manager.restore(with, messages, defaultRuleCache()); + Model model = manager.reset(messages, new RuleCache(ruleFinder)); + assertThat(model.getCharacteristics().size()).isGreaterThanOrEqualTo(3); + assertThat(model.getCharacteristics().size()).isGreaterThan(model.getRootCharacteristics().size()); + List hardwareControls = model.getCharacteristicByKey("HARDWARE_RELATED_PORTABILITY").getChildren(); + assertThat(hardwareControls.isEmpty()).isTrue(); - checkTables("warn_when_restoring_unknown_rule", "quality_models", "characteristics", "characteristic_edges"); - assertThat(messages.getWarnings()).hasSize(1); - assertThat(messages.getWarnings().get(0)).contains("regexp"); + assertThat(messages.getWarnings()).hasSize(3); } private RuleCache defaultRuleCache() { @@ -194,4 +159,5 @@ public class TechnicalDebtManagerTest extends AbstractDbUnitTestCase { private Rule newRegexpRule() { return Rule.create("checkstyle", "regexp", "Regular expression"); } + } diff --git a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelDefinitionTest.java b/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelDefinitionTest.java deleted file mode 100644 index 5864323ad8f..00000000000 --- a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelDefinitionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.technicaldebt; - -import org.junit.Test; -import org.sonar.api.rules.RuleFinder; -import org.sonar.api.utils.ValidationMessages; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; - -public class TechnicalDebtModelDefinitionTest { - - @Test - public void shouldCreateModel() throws Exception { - TechnicalDebtManager technicalDebtManager = mock(TechnicalDebtManager.class); - RuleFinder ruleFinder = mock(RuleFinder.class); - TechnicalDebtModelDefinition sqaleDefinition = new TechnicalDebtModelDefinition(technicalDebtManager, ruleFinder); - - sqaleDefinition.createModel(); - - verify(technicalDebtManager, times(1)).createInitialModel(any(ValidationMessages.class), any(RuleCache.class)); - } -} diff --git a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelFinderTest.java b/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelFinderTest.java index 83cecc03f85..b63ac6691ee 100644 --- a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelFinderTest.java +++ b/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelFinderTest.java @@ -105,7 +105,14 @@ public class TechnicalDebtModelFinderTest { @Test public void return_xml_file_path_for_plugin() throws Exception { initModel(); - assertThat(modelFinder.getXMLFilePathForPlugin("foo")).isEqualTo(TEST_XML_PREFIX_PATH + "foo-model.xml"); + assertThat(modelFinder.getXMLFilePath("foo")).isEqualTo(TEST_XML_PREFIX_PATH + "foo-model.xml"); + } + + @Test + public void contain_default_model() throws Exception { + modelFinder = new TechnicalDebtModelFinder(mock(PluginRepository.class)); + modelFinder.start(); + assertThat(modelFinder.getContributingPluginKeyToClassLoader().keySet()).containsOnly("technical-debt"); } private void initModel() throws MalformedURLException { diff --git a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelTest.java b/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelTest.java index 747871a245e..a294496300d 100644 --- a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelTest.java +++ b/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtModelTest.java @@ -28,6 +28,7 @@ import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleQuery; import org.sonar.api.utils.ValidationMessages; +import org.sonar.server.startup.RegisterTechnicalDebtModel; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -41,13 +42,13 @@ public class TechnicalDebtModelTest { @Before public void setUpModel() { - model = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); + model = Model.createByName(RegisterTechnicalDebtModel.TECHNICAL_DEBT_MODEL); technicalDebtModel = new TechnicalDebtModel(model); } @Test public void shouldMergeWithEmptyModel() { - Model with = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); + Model with = Model.createByName(RegisterTechnicalDebtModel.TECHNICAL_DEBT_MODEL); Characteristic efficiency = with.createCharacteristicByKey("efficiency", "Efficiency"); efficiency.addChild(with.createCharacteristicByKey("ram-efficiency", "RAM Efficiency")); with.createCharacteristicByKey("usability", "Usability"); @@ -66,7 +67,7 @@ public class TechnicalDebtModelTest { public void shouldNotUpdateExistingCharacteristics() { model.createCharacteristicByKey("efficiency", "Efficiency"); - Model with = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); + Model with = Model.createByName(RegisterTechnicalDebtModel.TECHNICAL_DEBT_MODEL); with.createCharacteristicByKey("efficiency", "New efficiency"); technicalDebtModel.mergeWith(with, ValidationMessages.create(), mockRuleCache()); @@ -78,7 +79,7 @@ public class TechnicalDebtModelTest { @Test public void shouldWarnOnMissingRule() { - Model with = Model.createByName(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); + Model with = Model.createByName(RegisterTechnicalDebtModel.TECHNICAL_DEBT_MODEL); Characteristic efficiency = with.createCharacteristicByKey("efficiency", "Efficiency"); Rule fooRule = Rule.create("foo", "bar", "Bar"); Characteristic requirement = with.createCharacteristicByRule(fooRule); diff --git a/sonar-server/src/test/java/org/sonar/server/technicaldebt/XMLImporterTest.java b/sonar-server/src/test/java/org/sonar/server/technicaldebt/XMLImporterTest.java index 75ac44008a6..3cec0b311a6 100644 --- a/sonar-server/src/test/java/org/sonar/server/technicaldebt/XMLImporterTest.java +++ b/sonar-server/src/test/java/org/sonar/server/technicaldebt/XMLImporterTest.java @@ -29,6 +29,7 @@ import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleQuery; import org.sonar.api.utils.ValidationMessages; +import org.sonar.server.startup.RegisterTechnicalDebtModel; import java.io.IOException; @@ -102,7 +103,7 @@ public class XMLImporterTest { private void checkXmlCorrectlyImported(Model sqale, ValidationMessages messages) { assertThat(messages.getErrors()).isEmpty(); - assertThat(sqale.getName()).isEqualTo(TechnicalDebtModelDefinition.TECHNICAL_DEBT_MODEL); + assertThat(sqale.getName()).isEqualTo(RegisterTechnicalDebtModel.TECHNICAL_DEBT_MODEL); // characteristics assertThat(sqale.getRootCharacteristics()).hasSize(2); diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_default_model_on_first_execution-result.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_default_model_on_first_execution-result.xml new file mode 100644 index 00000000000..10ea4bbcc65 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_default_model_on_first_execution-result.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_default_model_on_first_execution.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_default_model_on_first_execution.xml new file mode 100644 index 00000000000..fb0854fccbe --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_default_model_on_first_execution.xml @@ -0,0 +1,2 @@ + + diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_model_with_requirements_from_plugin_on_first_execution-result.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_model_with_requirements_from_plugin_on_first_execution-result.xml new file mode 100644 index 00000000000..1872525d83a --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_model_with_requirements_from_plugin_on_first_execution-result.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_model_with_requirements_from_plugin_on_first_execution.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_model_with_requirements_from_plugin_on_first_execution.xml new file mode 100644 index 00000000000..fb0854fccbe --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/create_model_with_requirements_from_plugin_on_first_execution.xml @@ -0,0 +1,2 @@ + + diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/disable_characteristics_and_remove_requirements_when_resetting_model-result.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/disable_characteristics_and_remove_requirements_when_resetting_model-result.xml new file mode 100644 index 00000000000..735b6f97e2b --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/disable_characteristics_and_remove_requirements_when_resetting_model-result.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/disable_characteristics_and_remove_requirements_when_resetting_model.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/disable_characteristics_and_remove_requirements_when_resetting_model.xml new file mode 100644 index 00000000000..be70284b5ab --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/disable_characteristics_and_remove_requirements_when_resetting_model.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/fake-java-model-with-additionnale-characteristic.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/fake-java-model-with-additionnale-characteristic.xml new file mode 100644 index 00000000000..19a8642bb35 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/fake-java-model-with-additionnale-characteristic.xml @@ -0,0 +1,80 @@ + + + PORTABILITY + Portability + + COMPILER_RELATED_PORTABILITY + Compiler related portability + + checkstyle + import + + remediationFactor + 30.0 + mn + + + remediationFunction + linear + + + + + HARDWARE_RELATED_PORTABILITY + Hardware related portability + + checkstyle + export + + remediationFactor + 1.0 + h + + + remediationFunction + linear + + + + + + MAINTAINABILITY + Maintainability + + READABILITY + + Readability related maintainability + + checkstyle + ConstantNameCheck + + remediationFactor + 10.0 + mn + + + remediationFunction + linear + + + + + + UNDERSTANDABILITY + Understandability related maintainability + + checkstyle + JavadocMethodCheck + + remediationFactor + 30.0 + mn + + + remediationFunction + linear + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/fake-java-model.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/fake-java-model.xml index 6d610083e59..46e4a228391 100644 --- a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/fake-java-model.xml +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/fake-java-model.xml @@ -42,6 +42,7 @@ Maintainability READABILITY + Readability related maintainability checkstyle @@ -57,22 +58,5 @@ - - UNDERSTANDABILITY - Understandability related maintainability - - checkstyle - JavadocMethodCheck - - remediationFactor - 30.0 - mn - - - remediationFunction - linear - - - diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_merge-result.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_merge-result.xml deleted file mode 100644 index 3f84f54b6a0..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_merge-result.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_merge.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_merge.xml deleted file mode 100644 index 4e2fb09f44c..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_merge.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_restore-result.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_restore-result.xml deleted file mode 100644 index 612de620d26..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_restore-result.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_restore.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_restore.xml deleted file mode 100644 index 1561bdb21cd..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/persist_restore.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/reset_model.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/reset_model.xml index 4c82f6e589a..ff53f92ff0a 100644 --- a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/reset_model.xml +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/reset_model.xml @@ -1,6 +1,7 @@ - + + diff --git a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/warn_when_restoring_unknown_rule-result.xml b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/warn_when_restoring_unknown_rule-result.xml index 7566ea2ad3c..1da76f127aa 100644 --- a/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/warn_when_restoring_unknown_rule-result.xml +++ b/sonar-server/src/test/resources/org/sonar/server/technicaldebt/TechnicalDebtManagerTest/warn_when_restoring_unknown_rule-result.xml @@ -1,6 +1,6 @@ - + -- cgit v1.2.3