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;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
import java.util.List;
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;
}
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());
}
}
import javax.annotation.CheckForNull;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
@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() {
}
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(){
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;
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;
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 {
}
}
- 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());
- }
- });
- }
-
}
/**
* @return enabled root characteristics, characteristics and requirements
*
- * @deprecated since 4.3
+ * @deprecated since 4.3 (used by SQALE plugin)
*/
@Deprecated
public List<CharacteristicDto> selectEnabledCharacteristics() {
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;
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)
@Mock
CharacteristicDao dao;
- @Mock
- RuleFinder ruleFinder;
-
DefaultTechnicalDebtManager finder;
@Before
public void setUp() throws Exception {
- finder = new DefaultTechnicalDebtManager(dao, ruleFinder);
+ finder = new DefaultTechnicalDebtManager(dao);
}
@Test
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");
}
@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);
- }
- }
}
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;
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();
+ }
+
}
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;
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.*;
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);
- }
- }
-
}
/**
* @since 4.1
+ * @deprecated since 4.3.
*/
+ @Deprecated
@CheckForNull
public final Requirement getRequirement() {
return requirement;
/**
* @since 4.1
+ * @deprecated since 4.3
*/
+ @Deprecated
public final Measure setRequirement(@Nullable Requirement requirement) {
this.requirement = requirement;
return this;
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();
List<Characteristic> findRootCharacteristics();
/**
- * @deprecated since 4.3
+ * @deprecated since 4.3. Always return null
*/
@Deprecated
Characteristic findRequirementByRule(Rule rule);
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;