]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5056 Deprecate Requirement
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 11 Mar 2014 10:58:49 +0000 (11:58 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 11 Mar 2014 10:58:49 +0000 (11:58 +0100)
sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManager.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModel.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizer.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModelTest.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizerTest.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java
sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/TechnicalDebtManager.java
sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java

index 9257520c8abfbe77367a11971d83a2d3bcf07549..8a65bbe586cd288703e56e494ecf341cb0a424a1 100644 (file)
@@ -21,9 +21,7 @@
 package org.sonar.core.technicaldebt;
 
 
-import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.technicaldebt.server.Characteristic;
 import org.sonar.api.technicaldebt.server.TechnicalDebtManager;
 import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic;
@@ -31,7 +29,6 @@ import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 
 import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
 
 import java.util.List;
 
@@ -43,18 +40,16 @@ import static com.google.common.collect.Lists.newArrayList;
 public class DefaultTechnicalDebtManager implements TechnicalDebtManager {
 
   private final CharacteristicDao dao;
-  private final RuleFinder ruleFinder;
 
-  public DefaultTechnicalDebtManager(CharacteristicDao dao, RuleFinder ruleFinder) {
+  public DefaultTechnicalDebtManager(CharacteristicDao dao) {
     this.dao = dao;
-    this.ruleFinder = ruleFinder;
   }
 
   public List<Characteristic> findRootCharacteristics() {
     List<CharacteristicDto> dtos = dao.selectEnabledRootCharacteristics();
     List<Characteristic> characteristics = newArrayList();
     for (CharacteristicDto dto : dtos) {
-      characteristics.add(toCharacteristic(dto, null));
+      characteristics.add(toCharacteristic(dto));
     }
     return characteristics;
   }
@@ -63,57 +58,33 @@ public class DefaultTechnicalDebtManager implements TechnicalDebtManager {
   public Characteristic findCharacteristicById(Integer id) {
     CharacteristicDto dto = dao.selectById(id);
     if (dto != null) {
-      return toCharacteristic(dto, null);
+      return toCharacteristic(dto);
     }
     return null;
   }
 
   /**
-   * @deprecated since 4.3
+   * @deprecated since 4.3. Always return null
    */
   @Deprecated
   @CheckForNull
   public Characteristic findRequirementByRuleId(int ruleId) {
-    CharacteristicDto requirementDto = dao.selectByRuleId(ruleId);
-    if (requirementDto != null) {
-      Rule rule = ruleFinder.findById(ruleId);
-      if (rule == null) {
-        throw new IllegalArgumentException(String.format("Rule with id '%s' do not exists.", ruleId));
-      }
-      return toCharacteristic(requirementDto, RuleKey.of(rule.getRepositoryKey(), rule.getKey()));
-    }
     return null;
   }
 
-  /**
-   * @deprecated since 4.3
-   */
-  @Deprecated
   @CheckForNull
   public Characteristic findRequirementByRule(Rule rule) {
-    CharacteristicDto requirementDto = dao.selectByRuleId(rule.getId());
-    if (requirementDto != null) {
-      return toCharacteristic(requirementDto, RuleKey.of(rule.getRepositoryKey(), rule.getKey()));
-    }
     return null;
   }
 
-  private static Characteristic toCharacteristic(CharacteristicDto dto, @Nullable RuleKey ruleKey) {
-    Double factorValue = dto.getFactorValue();
-    Double offsetValue = dto.getOffsetValue();
+  private static Characteristic toCharacteristic(CharacteristicDto dto) {
     return new DefaultCharacteristic()
       .setId(dto.getId())
       .setKey(dto.getKey())
       .setName(dto.getName())
       .setOrder(dto.getOrder())
       .setParentId(dto.getParentId())
-      .setRootId(dto.getRootId())
-      .setRuleKey(ruleKey)
-      .setFunction(dto.getFunction())
-      .setFactorValue(factorValue != null ? factorValue.intValue() : null)
-      .setFactorUnit(DefaultCharacteristic.toUnit(dto.getFactorUnit()))
-      .setOffsetValue(offsetValue != null ? offsetValue.intValue() : null)
-      .setOffsetUnit(DefaultCharacteristic.toUnit(dto.getOffsetUnit()));
+      .setRootId(dto.getRootId());
   }
 
 }
index 6c9c50d55e44043b1d31d4133a0b030dea3c0d14..9404f62f718e1b5652233eff34322384198fd3fa 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement;
 import javax.annotation.CheckForNull;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
@@ -78,22 +79,12 @@ public class DefaultTechnicalDebtModel implements TechnicalDebtModel {
 
   @CheckForNull
   public DefaultRequirement requirementsByRule(final RuleKey ruleKey) {
-    return Iterables.find(requirements(), new Predicate<DefaultRequirement>() {
-      @Override
-      public boolean apply(DefaultRequirement input) {
-        return input.ruleKey().equals(ruleKey);
-      }
-    }, null);
+    return null;
   }
 
   @CheckForNull
   public DefaultRequirement requirementsById(final Integer id){
-    return Iterables.find(requirements(), new Predicate<DefaultRequirement>() {
-      @Override
-      public boolean apply(DefaultRequirement input) {
-        return input.id().equals(id);
-      }
-    }, null);
+    return null;
   }
 
   public List<DefaultCharacteristic> characteristics() {
@@ -108,13 +99,7 @@ public class DefaultTechnicalDebtModel implements TechnicalDebtModel {
   }
 
   public List<DefaultRequirement> requirements() {
-    List<DefaultRequirement> allRequirements = newArrayList();
-    for (DefaultCharacteristic characteristic : characteristics()) {
-      for (DefaultRequirement requirement : characteristic.requirements()) {
-        allRequirements.add(requirement);
-      }
-    }
-    return allRequirements;
+    return Collections.emptyList();
   }
 
   public boolean isEmpty(){
index 349a08bc9cb82963516a23b6f1a9ee6de67eb187..4a7b1e1d3aa598e33bddbed603fc0ae425274960 100644 (file)
 
 package org.sonar.core.technicaldebt;
 
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
 import org.apache.commons.io.IOUtils;
 import org.apache.ibatis.session.SqlSession;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.ServerExtension;
-import org.sonar.api.rules.Rule;
 import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
-import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement;
 import org.sonar.api.utils.ValidationMessages;
 import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 
-import javax.annotation.CheckForNull;
-
 import java.io.Reader;
-import java.util.Collection;
 import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
@@ -76,8 +69,6 @@ public class TechnicalDebtModelSynchronizer implements ServerExtension {
   public List<CharacteristicDto> synchronize(ValidationMessages messages, TechnicalDebtRuleCache rulesCache, SqlSession session) {
     DefaultTechnicalDebtModel defaultModel = loadModelFromXml(TechnicalDebtModelRepository.DEFAULT_MODEL, messages, rulesCache);
     List<CharacteristicDto> model = loadOrCreateModelFromDb(defaultModel, session);
-    disableRequirementsOnRemovedRules(model, rulesCache, session);
-    mergePlugins(model, defaultModel, messages, rulesCache, session);
     messages.log(LOG);
 
     return model;
@@ -110,35 +101,6 @@ public class TechnicalDebtModelSynchronizer implements ServerExtension {
     return characteristics;
   }
 
-  private void mergePlugins(List<CharacteristicDto> existingModel, DefaultTechnicalDebtModel defaultModel, ValidationMessages messages, TechnicalDebtRuleCache rulesCache,
-                            SqlSession session) {
-    for (String pluginKey : getContributingPluginListWithoutSqale()) {
-      DefaultTechnicalDebtModel pluginModel = loadModelFromXml(pluginKey, messages, rulesCache);
-      checkPluginDoNotAddNewCharacteristic(pluginModel, defaultModel);
-      mergePlugin(pluginModel, existingModel, messages, rulesCache, session);
-    }
-  }
-
-  private void mergePlugin(DefaultTechnicalDebtModel pluginModel, List<CharacteristicDto> existingModel, ValidationMessages messages, TechnicalDebtRuleCache rulesCache,
-                           SqlSession session) {
-    if (!messages.hasErrors()) {
-      for (DefaultRequirement pluginRequirement : pluginModel.requirements()) {
-        Rule rule = rulesCache.getByRuleKey(pluginRequirement.ruleKey());
-        if (!isRequirementExists(existingModel, rule)) {
-          CharacteristicDto characteristicDto = findCharacteristic(existingModel, pluginRequirement.characteristic().key());
-          if (characteristicDto != null) {
-            Integer rootId = characteristicDto.getRootId();
-            if (rootId == null) {
-              throw new IllegalArgumentException("Requirement on rule '" + pluginRequirement.ruleKey() + "' should not be linked on a root characteristic.");
-            }
-            CharacteristicDto requirementDto = CharacteristicDto.toDto(pluginRequirement, characteristicDto.getId(), rootId, rule.getId());
-            dao.insert(requirementDto, session);
-          }
-        }
-      }
-    }
-  }
-
   public DefaultTechnicalDebtModel loadModelFromXml(String pluginKey, ValidationMessages messages, TechnicalDebtRuleCache rulesCache) {
     Reader xmlFileReader = null;
     try {
@@ -149,49 +111,4 @@ public class TechnicalDebtModelSynchronizer implements ServerExtension {
     }
   }
 
-  private void checkPluginDoNotAddNewCharacteristic(DefaultTechnicalDebtModel pluginModel, DefaultTechnicalDebtModel defaultModel) {
-    List<DefaultCharacteristic> characteristics = defaultModel.characteristics();
-    for (DefaultCharacteristic characteristic : pluginModel.characteristics()) {
-      if (!characteristics.contains(characteristic)) {
-        throw new IllegalArgumentException("The characteristic : " + characteristic.key() + " cannot be used as it's not available in default characteristics.");
-      }
-    }
-  }
-
-  private void disableRequirementsOnRemovedRules(List<CharacteristicDto> existingModel, TechnicalDebtRuleCache rulesCache, SqlSession session) {
-    for (CharacteristicDto characteristicDto : existingModel) {
-      Integer ruleId = characteristicDto.getRuleId();
-      if (ruleId != null && !rulesCache.exists(ruleId)) {
-        dao.disable(characteristicDto.getId(), session);
-      }
-    }
-  }
-
-  private Collection<String> getContributingPluginListWithoutSqale() {
-    Collection<String> pluginList = newArrayList(languageModelFinder.getContributingPluginList());
-    pluginList.remove(TechnicalDebtModelRepository.DEFAULT_MODEL);
-    return pluginList;
-  }
-
-  @CheckForNull
-  private CharacteristicDto findCharacteristic(List<CharacteristicDto> existingModel, final String key) {
-    return Iterables.find(existingModel, new Predicate<CharacteristicDto>() {
-      @Override
-      public boolean apply(CharacteristicDto input) {
-        String characteristicKey = input.getKey();
-        return input.getRuleId() == null && characteristicKey != null && characteristicKey.equals(key);
-      }
-    }, null);
-  }
-
-  private boolean isRequirementExists(List<CharacteristicDto> existingModel, final Rule rule) {
-    return Iterables.any(existingModel, new Predicate<CharacteristicDto>() {
-      @Override
-      public boolean apply(CharacteristicDto input) {
-        Integer ruleId = input.getRuleId();
-        return ruleId != null && ruleId.equals(rule.getId());
-      }
-    });
-  }
-
 }
index 6e6ff49879ae84bb5117d1d6ebe8572a444b4808..491d77d17ed6c63b1ac20de8974224d28aa5c14d 100644 (file)
@@ -40,7 +40,7 @@ public class CharacteristicDao implements BatchComponent, ServerComponent {
   /**
    * @return enabled root characteristics, characteristics and requirements
    *
-   * @deprecated since 4.3
+   * @deprecated since 4.3 (used by SQALE plugin)
    */
   @Deprecated
   public List<CharacteristicDto> selectEnabledCharacteristics() {
index 9095488504c5e8dc7d16a3f4cb7b737c468187d9..99c83b33dd7dba26b44ae8a4eb52fdfbbb3b29ad 100644 (file)
@@ -25,11 +25,8 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.technicaldebt.server.Characteristic;
-import org.sonar.api.utils.internal.WorkDuration;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 
@@ -37,7 +34,6 @@ import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
 import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -46,14 +42,11 @@ public class DefaultTechnicalDebtManagerTest {
   @Mock
   CharacteristicDao dao;
 
-  @Mock
-  RuleFinder ruleFinder;
-
   DefaultTechnicalDebtManager finder;
 
   @Before
   public void setUp() throws Exception {
-    finder = new DefaultTechnicalDebtManager(dao, ruleFinder);
+    finder = new DefaultTechnicalDebtManager(dao);
   }
 
   @Test
@@ -74,41 +67,6 @@ public class DefaultTechnicalDebtManagerTest {
     assertThat(rootCharacteristic.rootId()).isNull();
   }
 
-  @Test
-  public void find_requirement() throws Exception {
-    Rule rule = Rule.create("repo", "key");
-    rule.setId(1);
-
-    when(dao.selectByRuleId(rule.getId())).thenReturn(
-      new CharacteristicDto().setId(3).setRuleId(10).setParentId(2).setRootId(1).setFunction("linear")
-        .setFactorValue(30.0).setFactorUnit("mn")
-        .setOffsetValue(0.0).setOffsetUnit("d")
-    );
-
-    Characteristic result = finder.findRequirementByRule(rule);
-
-    assertThat(result.id()).isEqualTo(3);
-    assertThat(result.parentId()).isEqualTo(2);
-    assertThat(result.rootId()).isEqualTo(1);
-    assertThat(result.ruleKey()).isEqualTo(RuleKey.of("repo", "key"));
-    assertThat(result.function()).isEqualTo("linear");
-    assertThat(result.factorValue()).isEqualTo(30);
-    assertThat(result.factorUnit()).isEqualTo(WorkDuration.UNIT.MINUTES);
-    assertThat(result.offsetValue()).isEqualTo(0);
-    assertThat(result.offsetUnit()).isEqualTo(WorkDuration.UNIT.DAYS);
-  }
-
-  @Test
-  public void not_find_requirement() throws Exception {
-    Rule rule = Rule.create("repo", "key");
-    rule.setId(1);
-
-    when(dao.selectByRuleId(rule.getId())).thenReturn(null);
-
-    Characteristic result = finder.findRequirementByRule(rule);
-    assertThat(result).isNull();
-  }
-
   @Test
   public void find_characteristic() throws Exception {
     Rule rule = Rule.create("repo", "key");
@@ -138,54 +96,13 @@ public class DefaultTechnicalDebtManagerTest {
   }
 
   @Test
-  public void find_requirement_by_rule_id() throws Exception {
-    Rule rule = Rule.create("repo", "key");
-    rule.setId(1);
-
-    when(ruleFinder.findById(1)).thenReturn(rule);
-
-    when(dao.selectByRuleId(rule.getId())).thenReturn(
-      new CharacteristicDto().setId(3).setRuleId(10).setParentId(2).setRootId(1).setFunction("linear")
-        .setFactorValue(30.0).setFactorUnit("mn")
-        .setOffsetValue(0.0).setOffsetUnit("d")
-    );
-
-    Characteristic result = finder.findRequirementByRuleId(1);
-
-    assertThat(result.id()).isEqualTo(3);
-    assertThat(result.parentId()).isEqualTo(2);
-    assertThat(result.rootId()).isEqualTo(1);
-    assertThat(result.ruleKey()).isEqualTo(RuleKey.of("repo", "key"));
-    assertThat(result.function()).isEqualTo("linear");
-    assertThat(result.factorValue()).isEqualTo(30);
-    assertThat(result.factorUnit()).isEqualTo(WorkDuration.UNIT.MINUTES);
-    assertThat(result.offsetValue()).isEqualTo(0);
-    assertThat(result.offsetUnit()).isEqualTo(WorkDuration.UNIT.DAYS);
-
+  public void find_requirement_always_return_null() throws Exception {
+    assertThat(finder.findRequirementByRule(Rule.create("repo", "key"))).isNull();
   }
 
   @Test
-  public void not_find_requirement_by_rule_id_on_unknown_requirement() throws Exception {
-    Rule rule = Rule.create("repo", "key");
-    rule.setId(1);
-
-    when(ruleFinder.findById(1)).thenReturn(rule);
-
-    when(dao.selectByRuleId(rule.getId())).thenReturn(null);
-
+  public void find_requirement_by_rule_id_always_return_null() throws Exception {
     assertThat(finder.findRequirementByRuleId(1)).isNull();
   }
 
-  @Test
-  public void fail_to_find_requirement_by_rule_id_if_unknown_rule_id() throws Exception {
-    when(dao.selectByRuleId(1)).thenReturn(
-      new CharacteristicDto().setId(3).setRuleId(10).setParentId(2).setRootId(1).setFunction("linear").setFactorValue(30.0).setFactorUnit("mn"));
-    when(ruleFinder.findById(1)).thenReturn(null);
-    try {
-      finder.findRequirementByRuleId(1);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalArgumentException.class);
-    }
-  }
 }
index 05e793599563eed44cd2ba369647ceaf7f5608d7..e53af369ec7e8529bad2d2d6fd82d08341bede91 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.core.technicaldebt;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
 import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -73,4 +74,19 @@ public class DefaultTechnicalDebtModelTest {
     assertThat(sqaleModel.characteristicByKey("UNKNOWN")).isNull();
   }
 
+  @Test
+  public void get_requirement_by_rule_key_always_return_null() throws Exception {
+    assertThat(sqaleModel.requirementsByRule(RuleKey.of("checkstyle", "Regexp"))).isNull();
+  }
+
+  @Test
+  public void get_requirement_by_id_always_return_null() throws Exception {
+    assertThat(sqaleModel.requirementsById(1)).isNull();
+  }
+
+  @Test
+  public void get_requirements_always_return_empty_list() throws Exception {
+    assertThat(sqaleModel.requirements()).isEmpty();
+  }
+
 }
index 5419bb969783cc4405d81d9d6060bfb726ef73a2..f17050a990654f8e5148d4bba7a1a2ba33579e62 100644 (file)
@@ -30,12 +30,8 @@ import org.mockito.Mock;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.mockito.stubbing.Answer;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rules.Rule;
 import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
-import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement;
 import org.sonar.api.utils.ValidationMessages;
-import org.sonar.api.utils.internal.WorkDuration;
 import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
@@ -44,9 +40,7 @@ import java.io.Reader;
 import java.util.Collections;
 import java.util.List;
 
-import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.*;
@@ -121,161 +115,4 @@ public class TechnicalDebtModelSynchronizerTest {
     verifyNoMoreInteractions(dao);
   }
 
-  @Test
-  public void create_model_with_requirements_from_plugin_on_first_execution() throws Exception {
-    // Default model
-    DefaultCharacteristic defaultRootCharacteristic = new DefaultCharacteristic().setKey("PORTABILITY");
-    new DefaultCharacteristic().setKey("COMPILER_RELATED_PORTABILITY").setParent(defaultRootCharacteristic).setRoot(defaultRootCharacteristic);
-    defaultModel.addRootCharacteristic(defaultRootCharacteristic);
-
-    // No db model
-    when(dao.selectEnabledCharacteristics()).thenReturn(Lists.<CharacteristicDto>newArrayList());
-
-    // Java model
-    DefaultTechnicalDebtModel javaModel = new DefaultTechnicalDebtModel();
-    DefaultCharacteristic javaRootCharacteristic = new DefaultCharacteristic().setKey("PORTABILITY");
-    DefaultCharacteristic javaCharacteristic = new DefaultCharacteristic().setKey("COMPILER_RELATED_PORTABILITY").setParent(javaRootCharacteristic).setRoot(javaRootCharacteristic);
-    javaModel.addRootCharacteristic(javaRootCharacteristic);
-
-    Rule rule = Rule.create();
-    rule.setId(10);
-    RuleKey ruleKey = RuleKey.of("checkstyle", "import");
-    when(ruleCache.getByRuleKey(ruleKey)).thenReturn(rule);
-    new DefaultRequirement().setRuleKey(ruleKey)
-      .setFunction("linear")
-      .setFactorValue(30)
-      .setFactorUnit(WorkDuration.UNIT.MINUTES)
-      .setCharacteristic(javaCharacteristic)
-      .setRootCharacteristic(javaRootCharacteristic);
-
-    Reader javaModelReader = mock(Reader.class);
-    when(xmlImporter.importXML(eq(javaModelReader), any(ValidationMessages.class), eq(ruleCache))).thenReturn(javaModel);
-    when(technicalDebtModelRepository.createReaderForXMLFile("java")).thenReturn(javaModelReader);
-    when(technicalDebtModelRepository.getContributingPluginList()).thenReturn(newArrayList("java"));
-
-    manager.synchronize(ValidationMessages.create(), ruleCache);
-
-    verify(dao).selectEnabledCharacteristics();
-    ArgumentCaptor<CharacteristicDto> characteristicCaptor = ArgumentCaptor.forClass(CharacteristicDto.class);
-    verify(dao, times(3)).insert(characteristicCaptor.capture(), eq(session));
-
-    List<CharacteristicDto> result = characteristicCaptor.getAllValues();
-    assertThat(result.get(0).getKey()).isEqualTo("PORTABILITY");
-    assertThat(result.get(1).getKey()).isEqualTo("COMPILER_RELATED_PORTABILITY");
-    assertThat(result.get(2).getRuleId()).isEqualTo(10);
-    verifyNoMoreInteractions(dao);
-  }
-
-  @Test
-  public void add_new_requirements_from_plugin() throws Exception {
-    // Default model
-    DefaultCharacteristic defaultRootCharacteristic = new DefaultCharacteristic().setKey("PORTABILITY");
-    new DefaultCharacteristic().setKey("COMPILER_RELATED_PORTABILITY").setParent(defaultRootCharacteristic).setRoot(defaultRootCharacteristic);
-    defaultModel.addRootCharacteristic(defaultRootCharacteristic);
-
-    // Db model
-    CharacteristicDto dbRootCharacteristic = new CharacteristicDto().setId(1).setKey("PORTABILITY");
-    CharacteristicDto dbCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER_RELATED_PORTABILITY").setParentId(1).setRootId(1);
-    CharacteristicDto requirement = new CharacteristicDto().setId(3)
-      .setRuleId(10).setParentId(2).setRootId(1).setFactorValue(30.0).setFactorUnit("mn");
-
-    RuleKey ruleKey1 = RuleKey.of("checkstyle", "import");
-    Rule rule1 = Rule.create();
-    rule1.setId(10);
-    when(ruleCache.getByRuleKey(ruleKey1)).thenReturn(rule1);
-    when(ruleCache.exists(10)).thenReturn(true);
-    when(dao.selectEnabledCharacteristics()).thenReturn(newArrayList(requirement, dbCharacteristic, dbRootCharacteristic));
-
-    // Java model
-    DefaultTechnicalDebtModel javaModel = new DefaultTechnicalDebtModel();
-    DefaultCharacteristic javaRootCharacteristic = new DefaultCharacteristic().setKey("PORTABILITY");
-    DefaultCharacteristic javaCharacteristic = new DefaultCharacteristic().setKey("COMPILER_RELATED_PORTABILITY").setParent(javaRootCharacteristic).setRoot(javaRootCharacteristic);
-    javaModel.addRootCharacteristic(javaRootCharacteristic);
-
-    RuleKey ruleKey2 = RuleKey.of("checkstyle", "export");
-    Rule rule2 = Rule.create();
-    rule2.setId(11);
-    when(ruleCache.getByRuleKey(ruleKey2)).thenReturn(rule2);
-
-    // New requirement
-    new DefaultRequirement().setRuleKey(ruleKey2)
-      .setFunction("linear")
-      .setFactorValue(1)
-      .setFactorUnit(WorkDuration.UNIT.HOURS)
-      .setCharacteristic(javaCharacteristic)
-      .setRootCharacteristic(javaRootCharacteristic);
-
-    Reader javaModelReader = mock(Reader.class);
-    when(technicalDebtModelRepository.createReaderForXMLFile("java")).thenReturn(javaModelReader);
-    when(xmlImporter.importXML(eq(javaModelReader), any(ValidationMessages.class), eq(ruleCache))).thenReturn(javaModel);
-    when(technicalDebtModelRepository.getContributingPluginList()).thenReturn(newArrayList("java"));
-
-    manager.synchronize(ValidationMessages.create(), ruleCache);
-
-    verify(dao).selectEnabledCharacteristics();
-    ArgumentCaptor<CharacteristicDto> characteristicCaptor = ArgumentCaptor.forClass(CharacteristicDto.class);
-    verify(dao).insert(characteristicCaptor.capture(), eq(session));
-    assertThat(characteristicCaptor.getValue().getRuleId()).isEqualTo(11);
-    verifyNoMoreInteractions(dao);
-  }
-
-  @Test
-  public void disable_requirements_on_not_existing_rules() throws Exception {
-    // Default model
-    DefaultCharacteristic defaultRootCharacteristic = new DefaultCharacteristic().setKey("PORTABILITY");
-    new DefaultCharacteristic().setKey("COMPILER_RELATED_PORTABILITY").setParent(defaultRootCharacteristic);
-    defaultModel.addRootCharacteristic(defaultRootCharacteristic);
-
-    // Db model
-    CharacteristicDto dbRootCharacteristic = new CharacteristicDto().setId(1).setKey("PORTABILITY");
-    CharacteristicDto dbCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER_RELATED_PORTABILITY").setParentId(1);
-    // To be disabled as rule does not exists
-    CharacteristicDto requirement = new CharacteristicDto().setId(3)
-      .setRuleId(10).setParentId(2).setFactorValue(30.0).setFactorUnit("mn");
-
-    when(ruleCache.exists(10)).thenReturn(false);
-
-    when(dao.selectEnabledCharacteristics()).thenReturn(newArrayList(dbRootCharacteristic, dbCharacteristic, requirement));
-
-    manager.synchronize(ValidationMessages.create(), ruleCache);
-
-    verify(dao).selectEnabledCharacteristics();
-    verify(dao).disable(eq(3), eq(session));
-    verifyNoMoreInteractions(dao);
-  }
-
-  @Test
-  public void fail_when_plugin_defines_characteristics_not_defined_in_default_model() throws Exception {
-    try {
-      // Default model
-      DefaultCharacteristic defaultRootCharacteristic = new DefaultCharacteristic().setKey("PORTABILITY");
-      new DefaultCharacteristic().setKey("COMPILER_RELATED_PORTABILITY").setParent(defaultRootCharacteristic);
-      defaultModel.addRootCharacteristic(defaultRootCharacteristic);
-
-      // Db model
-      CharacteristicDto dbRootCharacteristic = new CharacteristicDto().setId(1).setKey("PORTABILITY");
-      CharacteristicDto dbCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER_RELATED_PORTABILITY").setParentId(1);
-      when(dao.selectEnabledCharacteristics()).thenReturn(newArrayList(dbRootCharacteristic, dbCharacteristic));
-
-      // Java model
-      DefaultTechnicalDebtModel javaModel = new DefaultTechnicalDebtModel();
-      DefaultCharacteristic javaRootCharacteristic = new DefaultCharacteristic().setKey("PORTABILITY");
-      new DefaultCharacteristic().setKey("NEW_CHARACTERISTIC").setParent(javaRootCharacteristic);
-      javaModel.addRootCharacteristic(javaRootCharacteristic);
-
-      Reader javaModelReader = mock(Reader.class);
-      when(technicalDebtModelRepository.createReaderForXMLFile("java")).thenReturn(javaModelReader);
-      when(xmlImporter.importXML(eq(javaModelReader), any(ValidationMessages.class), eq(ruleCache))).thenReturn(javaModel);
-      when(technicalDebtModelRepository.getContributingPluginList()).thenReturn(newArrayList("java"));
-
-      manager.synchronize(ValidationMessages.create(), ruleCache);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("The characteristic : NEW_CHARACTERISTIC cannot be used as it's not available in default characteristics.");
-    } finally {
-      verify(dao).selectEnabledCharacteristics();
-      verifyNoMoreInteractions(dao);
-    }
-  }
-
 }
index c47dd1f17f6c3bc74cfbd9f110984e23886ba928..b2a0c301632510ee27722a78acff08eeb91a9d42 100644 (file)
@@ -604,7 +604,9 @@ public class Measure {
 
   /**
    * @since 4.1
+   * @deprecated since 4.3.
    */
+  @Deprecated
   @CheckForNull
   public final Requirement getRequirement() {
     return requirement;
@@ -612,7 +614,9 @@ public class Measure {
 
   /**
    * @since 4.1
+   * @deprecated since 4.3
    */
+  @Deprecated
   public final Measure setRequirement(@Nullable Requirement requirement) {
     this.requirement = requirement;
     return this;
index ad99777dc58c0f0b120ad347d4bccbb475f56d68..d1bcd7c1101344526b1990df4cb75a805be61f4b 100644 (file)
@@ -38,21 +38,21 @@ public interface TechnicalDebtModel {
   Characteristic characteristicByKey(String key);
 
   /**
-   * @deprecated since 4.3
+   * @deprecated since 4.3. Always return null
    */
   @CheckForNull
   @Deprecated
   Requirement requirementsByRule(RuleKey ruleKey);
 
   /**
-   * @deprecated since 4.3
+   * @deprecated since 4.3. Always return null
    */
   @CheckForNull
   @Deprecated
   Requirement requirementsById(Integer id);
 
   /**
-   * @deprecated since 4.3
+   * @deprecated since 4.3. Always return empty list
    */
   @Deprecated
   List<? extends Requirement> requirements();
index f97294c381ea0dae8a22055c0955d680024c3150..d1f06b759ee68eee0a3ed20f25210f54bbfc34e3 100644 (file)
@@ -34,7 +34,7 @@ public interface TechnicalDebtManager extends ServerComponent {
   List<Characteristic> findRootCharacteristics();
 
   /**
-   * @deprecated since 4.3
+   * @deprecated since 4.3. Always return null
    */
   @Deprecated
   Characteristic findRequirementByRule(Rule rule);
index 06918b3b3a6f12667ace8572552e643e1d04dec2..8d4d544868c2a9976430fb120a331592cdf11ac2 100644 (file)
@@ -107,21 +107,37 @@ public class DefaultCharacteristic implements Characteristic {
     return this;
   }
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   @CheckForNull
   public RuleKey ruleKey() {
     return ruleKey;
   }
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   public DefaultCharacteristic setRuleKey(@Nullable RuleKey ruleKey) {
     this.ruleKey = ruleKey;
     return this;
   }
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   @CheckForNull
   public String function() {
     return function;
   }
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   public DefaultCharacteristic setFunction(@Nullable String function) {
     this.function = function;
     return this;