aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-03 17:52:05 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-03 17:52:32 +0200
commitfcb07c6af06f952f5c241470ffaef47b6d5df8ed (patch)
tree73fe1861970e4ff015b20d8e9039e05cb4041251 /sonar-plugin-api
parentac849445803cfb26d9a7bf298fc4320ae941bd2f (diff)
downloadsonarqube-fcb07c6af06f952f5c241470ffaef47b6d5df8ed.tar.gz
sonarqube-fcb07c6af06f952f5c241470ffaef47b6d5df8ed.zip
Create a new DebtModel API on batch side
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtCharacteristic.java37
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtModel.java58
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/internal/DefaultDebtCharacteristic.java120
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/internal/DefaultDebtModel.java93
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtCharacteristic.java11
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtCharacteristic.java9
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java5
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/internal/DefaultDebtModelTest.java88
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/RulesBuilderTest.java8
14 files changed, 425 insertions, 29 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtCharacteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtCharacteristic.java
new file mode 100644
index 00000000000..01a3a97fe29
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtCharacteristic.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.batch.debt;
+
+import javax.annotation.CheckForNull;
+
+/**
+ * @since 4.3
+ */
+public interface DebtCharacteristic {
+ String key();
+
+ String name();
+
+ @CheckForNull
+ Integer order();
+
+ boolean isSub();
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtModel.java
new file mode 100644
index 00000000000..b5aa6691f4b
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtModel.java
@@ -0,0 +1,58 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.batch.debt;
+
+import javax.annotation.CheckForNull;
+
+import java.util.List;
+
+/**
+ * This class can be used to retrieve characteristics or sub-characteristics from the technical debt model during analysis.
+ *
+ * Unfortunately, this class cannot be used to set characteristic on {@link org.sonar.api.measures.Measure},
+ * because the Measure API still uses deprecated {@link org.sonar.api.technicaldebt.batch.Characteristic}.
+ *
+ * @since 4.3
+ */
+public interface DebtModel {
+
+ /**
+ * Return only characteristics
+ */
+ List<DebtCharacteristic> characteristics();
+
+ /**
+ * Return sub-characteristics of a characteristic
+ */
+ List<DebtCharacteristic> subCharacteristics(String characteristicKey);
+
+ /**
+ * Return characteristics and sub-characteristics
+ */
+ List<DebtCharacteristic> allCharacteristics();
+
+ /**
+ * Return a characteristic or a sub-characteristic by a key
+ */
+ @CheckForNull
+ DebtCharacteristic characteristicByKey(String key);
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/internal/DefaultDebtCharacteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/internal/DefaultDebtCharacteristic.java
new file mode 100644
index 00000000000..bea0f94cce6
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/internal/DefaultDebtCharacteristic.java
@@ -0,0 +1,120 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.batch.debt.internal;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.sonar.api.batch.debt.DebtCharacteristic;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import java.util.Date;
+
+public class DefaultDebtCharacteristic implements DebtCharacteristic {
+
+ private Integer id;
+ private String key;
+ private String name;
+ private Integer order;
+ private Integer parentId;
+ private Date createdAt;
+ private Date updatedAt;
+
+ public Integer id() {
+ return id;
+ }
+
+ public DefaultDebtCharacteristic setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ @Override
+ public String key() {
+ return key;
+ }
+
+ public DefaultDebtCharacteristic setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ public DefaultDebtCharacteristic setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ @Override
+ @CheckForNull
+ public Integer order() {
+ return order;
+ }
+
+ public DefaultDebtCharacteristic setOrder(@Nullable Integer order) {
+ this.order = order;
+ return this;
+ }
+
+ @CheckForNull
+ public Integer parentId() {
+ return parentId;
+ }
+
+ public DefaultDebtCharacteristic setParentId(@Nullable Integer parentId) {
+ this.parentId = parentId;
+ return this;
+ }
+
+ public Date createdAt() {
+ return createdAt;
+ }
+
+ public DefaultDebtCharacteristic setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ return this;
+ }
+
+ @CheckForNull
+ public Date updatedAt() {
+ return updatedAt;
+ }
+
+ public DefaultDebtCharacteristic setUpdatedAt(@Nullable Date updatedAt) {
+ this.updatedAt = updatedAt;
+ return this;
+ }
+
+ @Override
+ public boolean isSub(){
+ return parentId != null;
+ }
+
+ @Override
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+ }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/internal/DefaultDebtModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/internal/DefaultDebtModel.java
new file mode 100644
index 00000000000..853412ac236
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/internal/DefaultDebtModel.java
@@ -0,0 +1,93 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.batch.debt.internal;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
+import org.sonar.api.batch.debt.DebtCharacteristic;
+import org.sonar.api.batch.debt.DebtModel;
+
+import javax.annotation.CheckForNull;
+
+import java.util.List;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+public class DefaultDebtModel implements DebtModel {
+
+ /**
+ * Sub-characteristics list can be retrieved with the characteristic key
+ * Characteristics list can be retrieved by with the null key
+ */
+ private Multimap<String, DebtCharacteristic> characteristicsByKey;
+
+ public DefaultDebtModel() {
+ characteristicsByKey = ArrayListMultimap.create();
+ }
+
+ public DefaultDebtModel addCharacteristic(DebtCharacteristic characteristic) {
+ characteristicsByKey.put(null, characteristic);
+ return this;
+ }
+
+ public DefaultDebtModel addSubCharacteristic(DebtCharacteristic subCharacteristic, String characteristicKey) {
+ characteristicsByKey.put(characteristicKey, subCharacteristic);
+ return this;
+ }
+
+ @Override
+ public List<DebtCharacteristic> characteristics() {
+ return newArrayList(characteristicsByKey.get(null));
+ }
+
+ @Override
+ public List<DebtCharacteristic> subCharacteristics(String characteristicKey) {
+ return newArrayList(characteristicsByKey.get(characteristicKey));
+ }
+
+ @Override
+ public List<DebtCharacteristic> allCharacteristics() {
+ return newArrayList(characteristicsByKey.values());
+ }
+
+ @Override
+ @CheckForNull
+ public DebtCharacteristic characteristicByKey(final String key) {
+ return Iterables.find(characteristicsByKey.values(), new Predicate<DebtCharacteristic>() {
+ @Override
+ public boolean apply(DebtCharacteristic input) {
+ return key.equals(input.key());
+ }
+ }, null);
+ }
+
+ @CheckForNull
+ public DebtCharacteristic characteristicById(final int id) {
+ return Iterables.find(characteristicsByKey.values(), new Predicate<DebtCharacteristic>() {
+ @Override
+ public boolean apply(DebtCharacteristic input) {
+ return id == ((DefaultDebtCharacteristic) input).id();
+ }
+ }, null);
+ }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
index f87317dfdab..475d8e7b600 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
@@ -53,12 +53,12 @@ public interface Rule {
RuleStatus status();
/**
- * Characteristic key.
+ * Sub characteristic key.
*
* @since 4.3
*/
@CheckForNull
- String debtCharacteristic();
+ String debtSubCharacteristic();
/**
* Remediation function : can by Linear (with a coefficient), Linear with offset (with a coefficient and an offset) or Constant per issue (with an offset)
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
index 5b2db0d27b9..cd93c077d60 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
@@ -37,7 +37,7 @@ public class DefaultRule implements Rule {
private final RuleKey key;
private final Integer id;
- private final String name, severity, description, metadata, debtCharacteristic;
+ private final String name, severity, description, metadata, debtSubCharacteristic;
private final RuleStatus status;
private final DebtRemediationFunction debtRemediationFunction;
@@ -51,7 +51,7 @@ public class DefaultRule implements Rule {
this.description = newRule.description;
this.metadata = newRule.metadata;
this.status = newRule.status;
- this.debtCharacteristic = newRule.debtCharacteristic;
+ this.debtSubCharacteristic = newRule.debtSubCharacteristic;
this.debtRemediationFunction = newRule.debtRemediationFunction;
ImmutableMap.Builder<String, RuleParam> builder = ImmutableMap.builder();
@@ -97,8 +97,8 @@ public class DefaultRule implements Rule {
}
@Override
- public String debtCharacteristic() {
- return debtCharacteristic;
+ public String debtSubCharacteristic() {
+ return debtSubCharacteristic;
}
@Override
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
index c3506ff1b50..c921a41ecc4 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
@@ -37,7 +37,7 @@ public class NewRule {
final RuleKey key;
Integer id;
- String name, description, severity = DEFAULT_SEVERITY, metadata, debtCharacteristic;
+ String name, description, severity = DEFAULT_SEVERITY, metadata, debtSubCharacteristic;
DebtRemediationFunction debtRemediationFunction;
RuleStatus status = RuleStatus.defaultStatus();
Map<String, NewRuleParam> params = new HashMap<String, NewRuleParam>();
@@ -76,8 +76,8 @@ public class NewRule {
return this;
}
- public NewRule setDebtCharacteristic(@Nullable String c) {
- this.debtCharacteristic = c;
+ public NewRule setDebtSubCharacteristic(@Nullable String c) {
+ this.debtSubCharacteristic = c;
return this;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtCharacteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtCharacteristic.java
index 81d704ced4a..c8e428213a0 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtCharacteristic.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtCharacteristic.java
@@ -22,13 +22,10 @@ package org.sonar.api.server.debt;
import javax.annotation.CheckForNull;
-import java.util.Date;
-
/**
* @since 4.3
*/
public interface DebtCharacteristic {
- Integer id();
String key();
@@ -37,11 +34,5 @@ public interface DebtCharacteristic {
@CheckForNull
Integer order();
- @CheckForNull
- Integer parentId();
-
- Date createdAt();
-
- @CheckForNull
- Date updatedAt();
+ boolean isSub();
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java
index cfc8f323cba..b2d668fa239 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java
@@ -39,6 +39,9 @@ public interface DebtModel extends ServerComponent {
*/
List<DebtCharacteristic> characteristics();
- DebtCharacteristic characteristicById(int id);
+ /**
+ * Return a characteristic or a sub-characteristic by its key
+ */
+ DebtCharacteristic characteristicByKey(String key);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtCharacteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtCharacteristic.java
index d9df13d4d76..9852e6c7cc1 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtCharacteristic.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtCharacteristic.java
@@ -42,7 +42,6 @@ public class DefaultDebtCharacteristic implements DebtCharacteristic {
private Date createdAt;
private Date updatedAt;
- @Override
public Integer id() {
return id;
}
@@ -83,7 +82,6 @@ public class DefaultDebtCharacteristic implements DebtCharacteristic {
return this;
}
- @Override
@CheckForNull
public Integer parentId() {
return parentId;
@@ -94,7 +92,6 @@ public class DefaultDebtCharacteristic implements DebtCharacteristic {
return this;
}
- @Override
public Date createdAt() {
return createdAt;
}
@@ -104,7 +101,6 @@ public class DefaultDebtCharacteristic implements DebtCharacteristic {
return this;
}
- @Override
@CheckForNull
public Date updatedAt() {
return updatedAt;
@@ -116,6 +112,11 @@ public class DefaultDebtCharacteristic implements DebtCharacteristic {
}
@Override
+ public boolean isSub(){
+ return parentId != null;
+ }
+
+ @Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java
index 27287a14498..fadad455575 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java
@@ -27,7 +27,9 @@ import java.util.List;
/**
* @since 4.1
+ * @deprecated since 4.3
*/
+@Deprecated
public interface Characteristic {
Integer id();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java
index a18212ec83e..33eb7e48a76 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java
@@ -20,6 +20,7 @@
package org.sonar.api.technicaldebt.batch;
+import org.sonar.api.BatchComponent;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
@@ -30,8 +31,10 @@ import java.util.List;
/**
* @since 4.1
* Used by Views plugin
+ * @deprecated since 4.3
*/
-public interface TechnicalDebtModel {
+@Deprecated
+public interface TechnicalDebtModel extends BatchComponent {
@CheckForNull
Characteristic characteristicById(Integer id);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/internal/DefaultDebtModelTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/internal/DefaultDebtModelTest.java
new file mode 100644
index 00000000000..561cb5ed3ae
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/internal/DefaultDebtModelTest.java
@@ -0,0 +1,88 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.batch.debt.internal;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultDebtModelTest {
+
+ private DefaultDebtModel debtModel;
+
+ @Before
+ public void setUp() throws Exception {
+ debtModel = new DefaultDebtModel()
+ .addCharacteristic(
+ new DefaultDebtCharacteristic().setId(1)
+ .setKey("MEMORY_EFFICIENCY")
+ .setName("Memory use")
+ .setOrder(1)
+ )
+ .addSubCharacteristic(
+ new DefaultDebtCharacteristic().setId(2)
+ .setKey("EFFICIENCY")
+ .setName("Efficiency")
+ .setParentId(1),
+ "MEMORY_EFFICIENCY"
+ );
+ }
+
+ @Test
+ public void all_characteristics() throws Exception {
+ assertThat(debtModel.allCharacteristics()).hasSize(2);
+ }
+
+ @Test
+ public void characteristics() throws Exception {
+ assertThat(debtModel.characteristics()).hasSize(1);
+ }
+
+ @Test
+ public void sub_characteristics() throws Exception {
+ assertThat(debtModel.subCharacteristics("MEMORY_EFFICIENCY")).hasSize(1);
+ }
+
+ @Test
+ public void characteristic_by_id() throws Exception {
+ DefaultDebtCharacteristic debtCharacteristic = (DefaultDebtCharacteristic) debtModel.characteristicById(1);
+ assertThat(debtCharacteristic).isNotNull();
+ assertThat(debtCharacteristic.id()).isEqualTo(1);
+ assertThat(debtCharacteristic.key()).isEqualTo("MEMORY_EFFICIENCY");
+ assertThat(debtCharacteristic.name()).isEqualTo("Memory use");
+ assertThat(debtCharacteristic.order()).isEqualTo(1);
+ assertThat(debtCharacteristic.parentId()).isNull();
+ assertThat(debtCharacteristic.isSub()).isFalse();
+ }
+
+ @Test
+ public void characteristic_by_key() throws Exception {
+ DefaultDebtCharacteristic debtCharacteristic = (DefaultDebtCharacteristic) debtModel.characteristicByKey("EFFICIENCY");
+ assertThat(debtCharacteristic).isNotNull();
+ assertThat(debtCharacteristic.id()).isEqualTo(2);
+ assertThat(debtCharacteristic.key()).isEqualTo("EFFICIENCY");
+ assertThat(debtCharacteristic.name()).isEqualTo("Efficiency");
+ assertThat(debtCharacteristic.order()).isNull();
+ assertThat(debtCharacteristic.parentId()).isEqualTo(1);
+ assertThat(debtCharacteristic.isSub()).isTrue();
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/RulesBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/RulesBuilderTest.java
index e569d4e1db1..074fe58aef7 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/RulesBuilderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/RulesBuilderTest.java
@@ -48,7 +48,7 @@ public class RulesBuilderTest {
newSquid1.setMetadata("foo=bar");
newSquid1.setSeverity(Severity.CRITICAL);
newSquid1.setStatus(RuleStatus.BETA);
- newSquid1.setDebtCharacteristic("COMPILER");
+ newSquid1.setDebtSubCharacteristic("COMPILER");
newSquid1.setDebtRemediationFunction(DebtRemediationFunction.create(DebtRemediationFunction.Type.LINEAR_OFFSET, Duration.create(10), Duration.create(60)));
newSquid1.addParam("min");
newSquid1.addParam("max").setDescription("Maximum");
@@ -71,11 +71,11 @@ public class RulesBuilderTest {
assertThat(squid1.metadata()).isEqualTo("foo=bar");
assertThat(squid1.status()).isEqualTo(RuleStatus.BETA);
assertThat(squid1.severity()).isEqualTo(Severity.CRITICAL);
- assertThat(squid1.debtCharacteristic()).isEqualTo("COMPILER");
+ assertThat(squid1.debtSubCharacteristic()).isEqualTo("COMPILER");
assertThat(squid1.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
assertThat(squid1.debtRemediationFunction().coefficient()).isEqualTo(Duration.create(10));
assertThat(squid1.debtRemediationFunction().offset()).isEqualTo(Duration.create(60));
- assertThat(squid1.debtCharacteristic()).isEqualTo("COMPILER");
+ assertThat(squid1.debtSubCharacteristic()).isEqualTo("COMPILER");
assertThat(squid1.params()).hasSize(2);
assertThat(squid1.param("min").key()).isEqualTo("min");
assertThat(squid1.param("min").description()).isNull();
@@ -89,7 +89,7 @@ public class RulesBuilderTest {
assertThat(squid2.metadata()).isNull();
assertThat(squid2.status()).isEqualTo(RuleStatus.defaultStatus());
assertThat(squid2.severity()).isEqualTo(Severity.defaultSeverity());
- assertThat(squid2.debtCharacteristic()).isNull();
+ assertThat(squid2.debtSubCharacteristic()).isNull();
assertThat(squid2.debtRemediationFunction()).isNull();
assertThat(squid2.params()).isEmpty();
}