import org.sonar.core.resource.ResourceKeyUpdaterDao;
import org.sonar.core.rule.RuleDao;
import org.sonar.core.source.jdbc.SnapshotDataDao;
-import org.sonar.core.technicaldebt.db.RequirementDao;
import org.sonar.core.template.LoadedTemplateDao;
import org.sonar.core.user.AuthorDao;
import org.sonar.core.user.AuthorizationDao;
PermissionTemplateDao.class,
PropertiesDao.class,
PurgeDao.class,
- RequirementDao.class,
ResourceIndexerDao.class,
ResourceDao.class,
ResourceKeyUpdaterDao.class,
import org.sonar.core.source.jdbc.SnapshotDataDto;
import org.sonar.core.source.jdbc.SnapshotDataMapper;
import org.sonar.core.source.jdbc.SnapshotSourceMapper;
-import org.sonar.core.technicaldebt.db.*;
import org.sonar.core.template.LoadedTemplateDto;
import org.sonar.core.template.LoadedTemplateMapper;
import org.sonar.core.user.*;
loadAlias(conf, "PermissionTemplate", PermissionTemplateDto.class);
loadAlias(conf, "PermissionTemplateUser", PermissionTemplateUserDto.class);
loadAlias(conf, "PermissionTemplateGroup", PermissionTemplateGroupDto.class);
- loadAlias(conf, "Characteristic", CharacteristicDto.class);
- loadAlias(conf, "Requirement", RequirementDto.class);
- loadAlias(conf, "RequirementProperty", RequirementPropertyDto.class);
// AuthorizationMapper has to be loaded before IssueMapper because this last one used it
loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, ResourceSnapshotMapper.class, RoleMapper.class, RuleMapper.class,
SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class,
- NotificationQueueMapper.class, CharacteristicMapper.class, RequirementPropertyMapper.class, RequirementMapper.class
+ NotificationQueueMapper.class
};
loadMappers(conf, mappers);
configureLogback(mappers);
new XMLMapperBuilder(input, configuration, mapperName, configuration.getSqlFragments()).parse();
configuration.addLoadedResource(mapperName);
} catch (Exception e) {
- throw new RuntimeException("Unable to load mapper "+ mapperName, e);
+ throw new RuntimeException("Unable to load mapper " + mapperName, e);
} finally {
Closeables.closeQuietly(input);
}
+++ /dev/null
-/*
- * 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.core.technicaldebt;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-
-public class DefaultCharacteristic {
-
- private String key;
- private String name;
-
- public String key() {
- return key;
- }
-
- public DefaultCharacteristic setKey(String key) {
- this.key = StringUtils.trimToNull(key);
- return this;
- }
-
- public String name() {
- return name;
- }
-
- public DefaultCharacteristic setName(String name) {
- this.name = name;
- return this;
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- DefaultCharacteristic that = (DefaultCharacteristic) o;
- return key.equals(that.key);
- }
-
- @Override
- public int hashCode() {
- return key.hashCode();
- }
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt;
-
-import com.google.common.collect.ImmutableList;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.rule.RuleKey;
-
-import javax.annotation.CheckForNull;
-
-import java.util.List;
-
-public class DefaultRequirement {
-
- public static final String FUNCTION_CONSTANT = "constant_resource";
- public static final String FUNCTION_LINEAR = "linear";
- public static final String FUNCTION_LINEAR_WITH_OFFSET = "linear_offset";
- public static final String FUNCTION_LINEAR_WITH_THRESHOLD = "linear_threshold";
-
- public static final List<String> FUNCTIONS = ImmutableList.of(FUNCTION_CONSTANT, FUNCTION_LINEAR, FUNCTION_LINEAR_WITH_OFFSET, FUNCTION_LINEAR_WITH_THRESHOLD);
-
- private RuleKey ruleKey;
- private DefaultCharacteristic rootCharacteristic;
- private DefaultCharacteristic characteristic;
-
- private String function;
- private WorkUnit factor;
- private WorkUnit offset;
-
- public RuleKey ruleKey() {
- return ruleKey;
- }
-
- public DefaultRequirement setRuleKey(RuleKey ruleKey) {
- this.ruleKey = ruleKey;
- return this;
- }
-
- public DefaultCharacteristic rootCharacteristic() {
- return rootCharacteristic;
- }
-
- public DefaultRequirement setRootCharacteristic(DefaultCharacteristic rootCharacteristic) {
- this.rootCharacteristic = rootCharacteristic;
- return this;
- }
-
- public DefaultCharacteristic characteristic() {
- return characteristic;
- }
-
- public DefaultRequirement setCharacteristic(DefaultCharacteristic characteristic) {
- this.characteristic = characteristic;
- return this;
- }
-
- public DefaultRequirement addProperty(DefaultRequirementProperty property) {
- if (property.key().equals(DefaultRequirementProperty.PROPERTY_REMEDIATION_FUNCTION)) {
- String textValue = property.textValue();
- if (!FUNCTIONS.contains(textValue)) {
- throw new IllegalArgumentException("Function is not valid. Should be one of : "+ FUNCTIONS);
- }
- this.function = property.textValue();
- } else if (property.key().equals(DefaultRequirementProperty.PROPERTY_REMEDIATION_FACTOR)) {
- this.factor = WorkUnit.create(property.value(), property.textValue());
- } else if (property.key().equals(DefaultRequirementProperty.PROPERTY_OFFSET)) {
- this.offset = WorkUnit.create(property.value(), property.textValue());
- } else {
- throw new IllegalArgumentException("Property key is not found");
- }
- return this;
- }
-
- public String function() {
- return function;
- }
-
- public WorkUnit factor() {
- return factor;
- }
-
- @CheckForNull
- public WorkUnit offset() {
- return offset;
- }
-
- public boolean isConstant(){
- return FUNCTION_CONSTANT.equals(function);
- }
-
- public boolean isLinear(){
- return FUNCTION_LINEAR.equals(function);
- }
-
- public boolean isLinearWithThreshold(){
- return FUNCTION_LINEAR_WITH_THRESHOLD.equals(function);
- }
-
- public boolean isLinearWithOffset(){
- return FUNCTION_LINEAR_WITH_OFFSET.equals(function);
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
- }
-
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-
-public class DefaultRequirementProperty {
-
- public static final String PROPERTY_REMEDIATION_FUNCTION = "remediationFunction";
- public static final String PROPERTY_REMEDIATION_FACTOR = "remediationFactor";
- public static final String PROPERTY_OFFSET = "offset";
-
- private String key;
- private Double value;
- private String textValue;
-
- public String key() {
- return key;
- }
-
- public DefaultRequirementProperty setKey(String key) {
- this.key = key;
- return this;
- }
-
- public Double value() {
- return value;
- }
-
- public DefaultRequirementProperty setValue(Double value) {
- this.value = value;
- return this;
- }
-
- public String textValue() {
- return textValue;
- }
-
- public DefaultRequirementProperty setTextValue(String textValue) {
- this.textValue = textValue;
- return this;
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
- }
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-import org.sonar.core.technicaldebt.DefaultCharacteristic;
-
-import java.io.Serializable;
-
-public class CharacteristicDto implements Serializable {
-
- private Long id;
- private String kee;
- private String name;
- private Integer depth;
- private Integer order;
-
- public Long getId() {
- return id;
- }
-
- public CharacteristicDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public String getKey() {
- return kee;
- }
-
- public CharacteristicDto setKey(String s) {
- this.kee = s;
- return this;
- }
-
- public String getName() {
- return name;
- }
-
- public CharacteristicDto setName(String s) {
- this.name = s;
- return this;
- }
-
- public Integer getDepth() {
- return depth;
- }
-
- public CharacteristicDto setDepth(Integer i) {
- this.depth = i;
- return this;
- }
-
- public int getOrder() {
- return order;
- }
-
- public CharacteristicDto setOrder(Integer i) {
- this.order = i;
- return this;
- }
-
- public DefaultCharacteristic toDefaultCharacteristic() {
- return new DefaultCharacteristic()
- .setKey(kee)
- .setName(name);
- }
-
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-public interface CharacteristicMapper {
-
-
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.ServerComponent;
-import org.sonar.core.persistence.MyBatis;
-
-import javax.annotation.CheckForNull;
-
-public class RequirementDao implements ServerComponent {
-
- private final MyBatis mybatis;
-
- public RequirementDao(MyBatis mybatis) {
- this.mybatis = mybatis;
- }
-
- @CheckForNull
- public RequirementDto selectByRuleId(long ruleId) {
- SqlSession session = mybatis.openSession();
- RequirementMapper mapper = session.getMapper(RequirementMapper.class);
- try {
- return mapper.selectByRuleId(ruleId);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-import org.sonar.api.rule.RuleKey;
-import org.sonar.core.rule.RuleDto;
-import org.sonar.core.technicaldebt.DefaultRequirement;
-
-import java.util.List;
-
-public class RequirementDto {
-
- private Long id;
- private RuleDto rule;
- private List<RequirementPropertyDto> properties;
- private CharacteristicDto characteristic;
- private CharacteristicDto rootCharacteristic;
-
- public Long getId() {
- return id;
- }
-
- public RequirementDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public RuleDto getRule() {
- return rule;
- }
-
- public RequirementDto setRule(RuleDto rule) {
- this.rule = rule;
- return this;
- }
-
- public CharacteristicDto getRootCharacteristic() {
- return rootCharacteristic;
- }
-
- public RequirementDto setRootCharacteristic(CharacteristicDto rootCharacteristic) {
- this.rootCharacteristic = rootCharacteristic;
- return this;
- }
-
- public CharacteristicDto getCharacteristic() {
- return characteristic;
- }
-
- public RequirementDto setCharacteristic(CharacteristicDto characteristic) {
- this.characteristic = characteristic;
-
- return this;
- }
-
- public List<RequirementPropertyDto> getProperties() {
- return properties;
- }
-
- public RequirementDto setProperties(List<RequirementPropertyDto> properties) {
- this.properties = properties;
- return this;
- }
-
- public DefaultRequirement toDefaultRequirement() {
- DefaultRequirement requirement = new DefaultRequirement()
- .setRuleKey(RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey()))
- .setCharacteristic(characteristic.toDefaultCharacteristic())
- .setRootCharacteristic(rootCharacteristic.toDefaultCharacteristic());
- for (RequirementPropertyDto property : properties) {
- requirement.addProperty(property.toDefaultRequirementProperty());
- }
- return requirement;
- }
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-import org.apache.ibatis.annotations.Param;
-
-public interface RequirementMapper {
-
- RequirementDto selectByRuleId(@Param("ruleId") Long ruleId);
-
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-import org.sonar.core.technicaldebt.DefaultRequirementProperty;
-
-import java.io.Serializable;
-
-public class RequirementPropertyDto implements Serializable {
-
- private Long id;
- private String kee;
- private Double value;
- private String textValue;
-
- public Long getId() {
- return id;
- }
-
- public RequirementPropertyDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public String getKey() {
- return kee;
- }
-
- public RequirementPropertyDto setKey(String key) {
- this.kee = key;
- return this;
- }
-
- public Double getValue() {
- return value;
- }
-
- public RequirementPropertyDto setValue(Double value) {
- this.value = value;
- return this;
- }
-
- public String getTextValue() {
- return textValue;
- }
-
- public RequirementPropertyDto setTextValue(String textValue) {
- this.textValue = textValue;
- return this;
- }
-
- public DefaultRequirementProperty toDefaultRequirementProperty() {
- return new DefaultRequirementProperty()
- .setKey(kee)
- .setTextValue(textValue)
- .setValue(value);
- }
-
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-public interface RequirementPropertyMapper {
-
-
-}
+++ /dev/null
-/*
- * 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.core.technicaldebt.db;
-
-import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mappei.dtd">
-
-<mapper namespace="org.sonar.core.technicaldebt.db.CharacteristicMapper">
-
- <sql id="characteristicColumns">
- c.id,
- c.kee as kee,
- c.name as name,
- c.depth as depth,
- c.order as order
- </sql>
-
-</mapper>
-
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mappei.dtd">
-
-<mapper namespace="org.sonar.core.technicaldebt.db.RequirementMapper">
-
- <select id="selectByRuleId" parameterType="int" resultMap="requirementResult">
- select
- req.id as id,
- req.rule_id as rule_id,
- req_rule.id as rule_id,
- req_rule.plugin_rule_key as rule_key,
- req_rule.plugin_name as rule_repository_key,
- req_rule.name as rule_name,
- prop.id as prop_id,
- prop.kee as prop_kee,
- prop.value as prop_value,
- prop.text_value as prop_textValue,
- root_char.id as root_char_id,
- root_char.kee as root_char_kee,
- root_char.name as root_char_name,
- characteristic.id as char_id,
- characteristic.kee as char_kee,
- characteristic.name as char_name
- from characteristics req
- inner join quality_models on quality_models.id = req.quality_model_id and quality_models.name = 'SQALE'
- inner join rules req_rule on req_rule.id = req.rule_id
- inner join characteristic_properties prop on prop.characteristic_id = req.id
- inner join characteristic_edges req_to_char on req_to_char.child_id = req.id
- inner join characteristics characteristic on characteristic.id = req_to_char.parent_id and characteristic.enabled = ${_true}
- inner join characteristic_edges char_to_root_char on char_to_root_char.child_id = characteristic.id
- inner join characteristics root_char on root_char.id = char_to_root_char.parent_id and root_char.enabled = ${_true}
- <where>
- req.rule_id = #{ruleId}
- and req.enabled = ${_true}
- </where>
- </select>
-
- <resultMap id="requirementResult" type="Requirement">
- <id property="id" column="id"/>
-
- <association property="rule" javaType="Rule">
- <id property="id" column="rule_id"/>
- <result property="ruleKey" column="rule_key"/>
- <result property="repositoryKey" column="rule_repository_key"/>
- <result property="name" column="rule_name"/>
- </association>
-
- <association property="characteristic" javaType="Characteristic">
- <id property="id" column="char_id"/>
- <result property="key" column="char_kee"/>
- <result property="name" column="char_name"/>
- </association>
-
- <association property="rootCharacteristic" javaType="Characteristic">
- <id property="id" column="root_char_id"/>
- <result property="key" column="root_char_kee"/>
- <result property="name" column="root_char_name"/>
- </association>
-
- <collection property="properties" ofType="RequirementProperty">
- <id property="id" column="prop_id"/>
- <result property="key" column="prop_kee"/>
- <result property="value" column="prop_value"/>
- <result property="textValue" column="prop_textValue"/>
- </collection>
- </resultMap>
-
-</mapper>
-
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mappei.dtd">
-
-<mapper namespace="org.sonar.core.technicaldebt.db.RequirementPropertyMapper">
-
- <sql id="requirementPropertyColumns">
- p.id,
- p.kee as kee,
- p.value as value,
- p.textValue as textValue
- </sql>
-
-</mapper>
-
+++ /dev/null
-/*
- * 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.core.technicaldebt;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class DefaultRequirementTest {
-
- @Test
- public void add_factor_property() {
- DefaultRequirementProperty property = new DefaultRequirementProperty()
- .setKey("remediationFactor")
- .setValue(30d)
- .setTextValue("mn");
-
- DefaultRequirement requirement = new DefaultRequirement();
- requirement.addProperty(property);
-
- assertThat(requirement.factor()).isNotNull();
- assertThat(requirement.factor().getUnit()).isEqualTo("mn");
- assertThat(requirement.factor().getValue()).isEqualTo(30d);
- }
-
- @Test
- public void add_offset_property() {
- DefaultRequirementProperty property = new DefaultRequirementProperty()
- .setKey("offset")
- .setValue(30d)
- .setTextValue("mn");
-
- DefaultRequirement requirement = new DefaultRequirement();
- requirement.addProperty(property);
-
- assertThat(requirement.offset()).isNotNull();
- assertThat(requirement.offset().getValue()).isEqualTo(30d);
- assertThat(requirement.offset().getUnit()).isEqualTo("mn");
- }
-
- @Test
- public void add_linear_function_property() {
- DefaultRequirementProperty property = new DefaultRequirementProperty()
- .setKey("remediationFunction")
- .setTextValue("linear");
-
- DefaultRequirement requirement = new DefaultRequirement();
- requirement.addProperty(property);
-
- assertThat(requirement.function()).isEqualTo("linear");
- }
-
- @Test
- public void add_constant_function_property() {
- DefaultRequirementProperty property = new DefaultRequirementProperty()
- .setKey("remediationFunction")
- .setTextValue("constant_resource");
-
- DefaultRequirement requirement = new DefaultRequirement();
- requirement.addProperty(property);
-
- assertThat(requirement.function()).isEqualTo("constant_resource");
- assertThat(requirement.factor()).isNull();
- assertThat(requirement.offset()).isNull();
- }
-
- @Test
- public void fail_on_invalid_function() {
- DefaultRequirementProperty property = new DefaultRequirementProperty()
- .setKey("remediationFunction")
- .setTextValue("unknown");
-
- DefaultRequirement requirement = new DefaultRequirement();
- try {
- requirement.addProperty(property);
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Function is not valid. Should be one of : [constant_resource, linear, linear_offset, linear_threshold]");
- }
- }
-
- @Test
- public void fail_on_invalid_property_key() {
- DefaultRequirementProperty property = new DefaultRequirementProperty()
- .setKey("unknown");
-
- DefaultRequirement requirement = new DefaultRequirement();
- try {
- requirement.addProperty(property);
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Property key is not found");
- }
- }
-
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-import org.junit.Test;
-import org.sonar.core.technicaldebt.DefaultCharacteristic;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class CharacteristicDtoTest {
-
- @Test
- public void to_default_characteristic(){
- CharacteristicDto characteristicDto = new CharacteristicDto()
- .setKey("COMPILER_RELATED_PORTABILITY")
- .setName("Compiler");
-
- DefaultCharacteristic defaultCharacteristic = characteristicDto.toDefaultCharacteristic();
- assertThat(defaultCharacteristic.key()).isEqualTo("COMPILER_RELATED_PORTABILITY");
- assertThat(defaultCharacteristic.name()).isEqualTo("Compiler");
- }
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.core.persistence.AbstractDaoTestCase;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class RequirementDaoTest extends AbstractDaoTestCase {
-
- RequirementDao dao;
-
- @Before
- public void createDao() {
- dao = new RequirementDao(getMyBatis());
- }
-
- @Test
- public void select_requirement_from_rule() {
- setupData("select_requirement_from_rule");
-
- RequirementDto requirementDto = dao.selectByRuleId(1L);
-
- assertThat(requirementDto).isNotNull();
- assertThat(requirementDto.getId()).isEqualTo(2);
-
- assertThat(requirementDto.getRule().getId()).isEqualTo(1);
- assertThat(requirementDto.getRule().getRepositoryKey()).isEqualTo("checkstyle");
- assertThat(requirementDto.getRule().getRuleKey()).isEqualTo("import");
- assertThat(requirementDto.getRule().getName()).isEqualTo("Regular exp");
-
- assertThat(requirementDto.getRootCharacteristic().getId()).isEqualTo(3);
- assertThat(requirementDto.getRootCharacteristic().getKey()).isEqualTo("PORTABILITY");
-
- assertThat(requirementDto.getCharacteristic().getId()).isEqualTo(1);
- assertThat(requirementDto.getCharacteristic().getKey()).isEqualTo("COMPILER_RELATED_PORTABILITY");
-
- assertThat(requirementDto.getProperties()).hasSize(1);
- RequirementPropertyDto prop = requirementDto.getProperties().get(0);
- assertThat(prop.getId()).isEqualTo(1);
- assertThat(prop.getKey()).isEqualTo("remediationFactor");
- assertThat(prop.getValue()).isEqualTo(30d);
- assertThat(prop.getTextValue()).isEqualTo("mn");
- }
-
- @Test
- public void select_requirement_from_rule_with_two_properties(){
- setupData("select_requirement_from_rule_with_two_properties");
-
- RequirementDto requirementDto = dao.selectByRuleId(1L);
-
- assertThat(requirementDto.getProperties()).hasSize(2);
- }
-
- @Test
- public void return_null_on_unknown_rule(){
- setupData("select_requirement_from_rule");
-
- RequirementDto requirementDto = dao.selectByRuleId(999L);
-
- assertThat(requirementDto).isNull();
- }
-
-
-}
+++ /dev/null
-/*
- * 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.core.technicaldebt.db;
-
-import org.junit.Test;
-import org.sonar.core.rule.RuleDto;
-import org.sonar.core.technicaldebt.DefaultRequirement;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.fest.assertions.Assertions.assertThat;
-
-public class RequirementDtoTest {
-
- @Test
- public void to_default_requirement(){
- RuleDto ruleDto = new RuleDto();
- ruleDto.setRepositoryKey("squid");
- ruleDto.setRuleKey("AvoidCycle");
- CharacteristicDto characteristicDto = new CharacteristicDto();
- CharacteristicDto rootCharacteristicDto = new CharacteristicDto();
-
- RequirementPropertyDto requirementPropertyDto1 = new RequirementPropertyDto()
- .setKey("remediationFactor")
- .setValue(30d)
- .setTextValue("mn");
- RequirementPropertyDto requirementPropertyDto2 = new RequirementPropertyDto()
- .setKey("remediationFunction")
- .setTextValue("linear");
-
- RequirementDto dto = new RequirementDto()
- .setId(1L)
- .setRule(ruleDto)
- .setCharacteristic(characteristicDto)
- .setRootCharacteristic(rootCharacteristicDto)
- .setProperties(newArrayList(requirementPropertyDto1, requirementPropertyDto2));
-
- DefaultRequirement result = dto.toDefaultRequirement();
- assertThat(result).isNotNull();
- assertThat(result.ruleKey()).isNotNull();
- assertThat(result.characteristic()).isNotNull();
- assertThat(result.rootCharacteristic()).isNotNull();
- assertThat(result.function()).isNotNull();
- assertThat(result.factor()).isNotNull();
- }
-}
+++ /dev/null
-<dataset>
-
- <quality_models id="1" name="SQALE"/>
-
- <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2"
- description="[null]" enabled="[true]"/>
-
- <!-- requirement -->
- <characteristics id="2" kee="[null]" name="[null]" quality_model_id="1" rule_id="1" characteristic_order="6" depth="3"
- description="[null]" enabled="[true]"/>
-
- <characteristics id="3" kee="PORTABILITY" name="Portability" quality_model_id="1" rule_id="[null]" characteristic_order="2" depth="1" description="[null]" enabled="[true]"/>
-
- <characteristic_edges child_id="1" parent_id="3"/>
- <characteristic_edges child_id="2" parent_id="1"/>
-
- <characteristic_properties id="1" characteristic_id="2" kee="remediationFactor" value="30.0" text_value="mn"/>
-
- <rules id="1" plugin_rule_key="import" plugin_config_key="regexp" plugin_name="checkstyle" description="[null]" priority="3" status="READY" cardinality="SINGLE" parent_id="[null]" name="Regular exp"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <quality_models id="1" name="SQALE"/>
-
- <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2"
- description="[null]" enabled="[true]"/>
-
- <!-- requirement -->
- <characteristics id="2" kee="[null]" name="[null]" quality_model_id="1" rule_id="1" characteristic_order="6" depth="3"
- description="[null]" enabled="[true]"/>
-
- <characteristics id="3" kee="PORTABILITY" name="Portability" quality_model_id="1" rule_id="[null]" characteristic_order="2" depth="1" description="[null]" enabled="[true]"/>
-
- <characteristic_edges child_id="1" parent_id="3"/>
- <characteristic_edges child_id="2" parent_id="1"/>
-
- <characteristic_properties id="1" characteristic_id="2" kee="remediationFactor" value="30.0" text_value="mn"/>
- <characteristic_properties id="2" characteristic_id="2" kee="remediationFunction" value="[null]" text_value="linear"/>
-
- <rules id="1" plugin_rule_key="import" plugin_config_key="regexp" plugin_name="checkstyle" description="[null]" priority="3" status="READY" cardinality="SINGLE" parent_id="[null]" name="Regular exp"/>
-
-</dataset>
import org.sonar.server.rules.ProfilesConsole;
import org.sonar.server.rules.RulesConsole;
import org.sonar.server.startup.*;
-import org.sonar.server.technicaldebt.RubyTechnicalDebtService;
import org.sonar.server.text.MacroInterpreter;
import org.sonar.server.text.RubyTextService;
import org.sonar.server.ui.*;
servicesContainer.addSingleton(TechnicalDebtModelRepository.class);
servicesContainer.addSingleton(TechnicalDebtXMLImporter.class);
servicesContainer.addSingleton(TechnicalDebtConverter.class);
- servicesContainer.addSingleton(RubyTechnicalDebtService.class);
// text
servicesContainer.addSingleton(MacroInterpreter.class);
+++ /dev/null
-/*
- * 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.ServerComponent;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.core.technicaldebt.DefaultRequirement;
-import org.sonar.core.technicaldebt.db.RequirementDao;
-import org.sonar.core.technicaldebt.db.RequirementDto;
-import org.sonar.server.exceptions.BadRequestException;
-
-import javax.annotation.CheckForNull;
-
-public class RubyTechnicalDebtService implements ServerComponent {
-
- private final RequirementDao requirementDao;
- private final RuleFinder rulefinder;
-
- public RubyTechnicalDebtService(RequirementDao requirementDao, RuleFinder rulefinder) {
- this.requirementDao = requirementDao;
- this.rulefinder = rulefinder;
- }
-
- @CheckForNull
- public DefaultRequirement requirement(RuleKey ruleKey) {
- Rule rule = rulefinder.findByKey(ruleKey);
- if (rule == null) {
- throw new BadRequestException("Unknown rule: " + ruleKey);
- }
-
- RequirementDto dto = requirementDao.selectByRuleId(rule.getId());
- return dto != null ? dto.toDefaultRequirement() : null;
- }
-
-}
+++ /dev/null
-/*
- * 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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.technicaldebt;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
require_parameters :id
@issue_results = Api.issues.find(params[:id])
@issue = @issue_results.first()
- @requirement = Internal.technical_debt.requirement(@issue.ruleKey)
+
+ rule_id = @issue_results.rule(@issue).id
+ @requirement = Characteristic.first(
+ :conditions => ['quality_models.name=? AND characteristics.rule_id=? AND characteristics.enabled=?', 'SQALE', rule_id, true],
+ :include => [:quality_model, {:parents => :parents}, :characteristic_properties]
+ )
render :partial => 'issue/technicaldebt'
end
default_value
end
end
+
+
+ ### For Requirement
+
+ def function
+ property(CharacteristicProperty::PROPERTY_REMEDIATION_FUNCTION)
+ end
+
+ def factor
+ property(CharacteristicProperty::PROPERTY_REMEDIATION_FACTOR)
+ end
+
+ def offset
+ property(CharacteristicProperty::PROPERTY_OFFSET)
+ end
+
end
class CharacteristicProperty < ActiveRecord::Base
KEY_MAX_SIZE=100
+ PROPERTY_REMEDIATION_FUNCTION = "remediationFunction";
+ PROPERTY_REMEDIATION_FACTOR = "remediationFactor";
+ PROPERTY_OFFSET = "offset";
+
+ FUNCTION_CONSTANT = "constant_resource";
+ FUNCTION_LINEAR = "linear";
+ FUNCTION_LINEAR_WITH_OFFSET = "linear_offset";
+ FUNCTION_LINEAR_WITH_THRESHOLD = "linear_threshold";
+
+ DAY = "d"
+ HOUR = "h"
+ MINUTE = "mn"
+
belongs_to :characteristic
validates_length_of :kee, :in => 1..KEY_MAX_SIZE, :allow_blank => false
kee
end
-end
\ No newline at end of file
+ def constant?
+ text_value == FUNCTION_CONSTANT
+ end
+
+ def linear?
+ text_value == FUNCTION_LINEAR
+ end
+
+ def linearWithThreshold?
+ text_value == FUNCTION_LINEAR_WITH_THRESHOLD
+ end
+
+ def linearWithOffset?
+ text_value == FUNCTION_LINEAR_WITH_OFFSET
+ end
+
+end
component(Java::OrgSonarServerPermission::InternalPermissionTemplateService.java_class)
end
- def self.technical_debt
- component(Java::OrgSonarServerTechnicaldebt::RubyTechnicalDebtService.java_class)
- end
private
+
def self.component(component_java_class)
Java::OrgSonarServerPlatform::Platform.component(component_java_class)
end
+
end
-<div class="<%= @requirement.isLinear() ? '' : 'marginbottom10' %>">
- <% if @requirement.isConstant() %>
+<% function = @requirement.function %>
+
+<div class="<%= function.linear? ? '' : 'marginbottom10' %>">
+ <% if function.constant? %>
<%= message('issue.technical_debt.constant_resource') -%>
- <% elsif @requirement.isLinearWithThreshold() or @requirement.isLinearWithOffset() %>
+ <% elsif function.linearWithThreshold? or function.linearWithOffset? %>
<%
- case @requirement.offset.unit
- when 'd'
- value = message('issue.technical_debt.x_days', :params => @requirement.factor.value)
- when 'h'
- value = message('issue.technical_debt.x_hours', :params => @requirement.factor.value)
- when 'mn'
- value = message('issue.technical_debt.x_minutes', :params => @requirement.factor.value)
+ case @requirement.offset.text_value
+ when CharacteristicProperty::DAY
+ value = message('issue.technical_debt.x_days', :params => @requirement.offset.value)
+ when CharacteristicProperty::HOUR
+ value = message('issue.technical_debt.x_hours', :params => @requirement.offset.value)
+ when CharacteristicProperty::MINUTE
+ value = message('issue.technical_debt.x_minutes', :params => @requirement.offset.value)
end
%>
- <% if @requirement.isLinearWithThreshold() %>
+ <% if function.linearWithThreshold? %>
<%= message('issue.technical_debt.linear_threshold', :params => value) -%>
<% else %>
<%= message('issue.technical_debt.linear_offset', :params => value) -%>
</div>
<div class="note">
- <%= @requirement.rootCharacteristic.name %> > <%= @requirement.characteristic.name %>
+ <%= @requirement.parent.parent.name %> > <%= @requirement.parent.name %>
</div>
+++ /dev/null
-/*
- * 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.Before;
-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.core.technicaldebt.DefaultRequirement;
-import org.sonar.core.technicaldebt.db.RequirementDao;
-import org.sonar.core.technicaldebt.db.RequirementDto;
-import org.sonar.server.exceptions.BadRequestException;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RubyTechnicalDebtServiceTest {
-
-
- private RubyTechnicalDebtService service;
-
- @Mock
- private RequirementDao requirementDao;
-
- @Mock
- private RuleFinder rulefinder;
-
- @Before
- public void before() {
- service = new RubyTechnicalDebtService(requirementDao, rulefinder);
- }
-
- @Test
- public void return_requirement() {
- RuleKey ruleKey = RuleKey.of("squid", "AvoidCycle");
- Rule rule = Rule.create("squid", "AvoidCycle");
- rule.setId(1);
- when(rulefinder.findByKey(ruleKey)).thenReturn(rule);
-
- DefaultRequirement defaultRequirement = mock(DefaultRequirement.class);
- RequirementDto requirement = mock(RequirementDto.class);
- when(requirement.toDefaultRequirement()).thenReturn(defaultRequirement);
- when(requirementDao.selectByRuleId(1)).thenReturn(requirement);
-
- DefaultRequirement result = service.requirement(ruleKey);
- assertThat(result).isEqualTo(defaultRequirement);
- }
-
- @Test
- public void return_null_requirement_if_rule_does_not_exists() {
- when(rulefinder.findByKey(any(RuleKey.class))).thenReturn(null);
-
- RequirementDto requirement = new RequirementDto();
- when(requirementDao.selectByRuleId(1)).thenReturn(requirement);
-
- try {
- service.requirement(RuleKey.of("squid", "AvoidCycle"));
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("Unknown rule: squid:AvoidCycle");
- }
- }
-
-}