aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-webapi
diff options
context:
space:
mode:
authorDejan Milisavljevic <dejan.milisavljevic@sonarsource.com>2024-03-18 11:09:18 +0100
committersonartech <sonartech@sonarsource.com>2024-03-25 20:02:42 +0000
commit494316d9f27f7a64b762e37d4f8bc34e4b4370d7 (patch)
tree99614caafba41b900439722a96483c1b7a9b0421 /server/sonar-webserver-webapi
parentd4518aca0c74114be84a81b9958027255453628d (diff)
downloadsonarqube-494316d9f27f7a64b762e37d4f8bc34e4b4370d7.tar.gz
sonarqube-494316d9f27f7a64b762e37d4f8bc34e4b4370d7.zip
SONAR-21770 Accept new metrics 'new_maintainability_issues', 'new_reliability_issues', 'new_security_issues'
Diffstat (limited to 'server/sonar-webserver-webapi')
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java53
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/IssueCounter.java9
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java15
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java13
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java113
9 files changed, 142 insertions, 66 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
index 00535396b66..62165b7ab7a 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
@@ -60,6 +60,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.api.measures.CoreMetrics.MAINTAINABILITY_ISSUES_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_ISSUES_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_ISSUES_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_ISSUES_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY;
import static org.sonar.api.measures.CoreMetrics.RELIABILITY_ISSUES_KEY;
import static org.sonar.api.measures.CoreMetrics.SECURITY_ISSUES_KEY;
@@ -867,12 +870,10 @@ class ComponentTreeActionIT {
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
db.getDbClient().snapshotDao().insert(dbSession, newAnalysis(mainBranch));
- MetricDto dataMetric = dbClient.metricDao().insert(dbSession, newDataMetricDto(SECURITY_ISSUES_KEY));
- db.measures().insertLiveMeasure(mainBranch, dataMetric, c -> c.setData(SECURITY_ISSUES_KEY + "_data"));
- dataMetric = dbClient.metricDao().insert(dbSession, newDataMetricDto(MAINTAINABILITY_ISSUES_KEY));
- db.measures().insertLiveMeasure(mainBranch, dataMetric, c -> c.setData(MAINTAINABILITY_ISSUES_KEY + "_data"));
- dataMetric = dbClient.metricDao().insert(dbSession, newDataMetricDto(RELIABILITY_ISSUES_KEY));
- db.measures().insertLiveMeasure(mainBranch, dataMetric, c -> c.setData(RELIABILITY_ISSUES_KEY + "_data"));
+
+ insertMetricAndLiveMeasure(mainBranch, SECURITY_ISSUES_KEY, "_data");
+ insertMetricAndLiveMeasure(mainBranch, MAINTAINABILITY_ISSUES_KEY, "_data");
+ insertMetricAndLiveMeasure(mainBranch, RELIABILITY_ISSUES_KEY, "_data");
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -892,6 +893,40 @@ class ComponentTreeActionIT {
}
@Test
+ void execute_whenUsingSupportedNewDATAMetrics_shouldReturnMetrics() {
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ db.components().insertSnapshot(mainBranch);
+ ComponentDto file1 = db.components().insertComponent(newFileDto(mainBranch));
+
+ insertMetricAndLiveMeasure(file1, NEW_SECURITY_ISSUES_KEY, "_data");
+ insertMetricAndLiveMeasure(file1, NEW_MAINTAINABILITY_ISSUES_KEY, "_data");
+ insertMetricAndLiveMeasure(file1, NEW_RELIABILITY_ISSUES_KEY, "_data");
+
+ ComponentTreeWsResponse response = ws.newRequest()
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
+ .setParam(PARAM_METRIC_KEYS, format("%s,%s,%s",
+ NEW_SECURITY_ISSUES_KEY,
+ NEW_MAINTAINABILITY_ISSUES_KEY,
+ NEW_RELIABILITY_ISSUES_KEY
+ ))
+ .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period")
+ .executeProtobuf(ComponentTreeWsResponse.class);
+
+ assertThat(response.getComponents(0).getMeasuresCount()).isEqualTo(3);
+
+ List<Measure> dataMeasures = response.getComponents(0).getMeasuresList();
+
+ assertThat(dataMeasures)
+ .extracting(Measure::getMetric, m-> m.getPeriod().getValue())
+ .containsExactlyInAnyOrder(tuple(NEW_SECURITY_ISSUES_KEY, NEW_SECURITY_ISSUES_KEY + "_data"),
+ tuple(NEW_MAINTAINABILITY_ISSUES_KEY, NEW_MAINTAINABILITY_ISSUES_KEY + "_data"),
+ tuple(NEW_RELIABILITY_ISSUES_KEY, NEW_RELIABILITY_ISSUES_KEY + "_data")
+ );
+ }
+
+ @Test
void fail_when_setting_more_than_15_metric_keys() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
@@ -1125,6 +1160,12 @@ class ComponentTreeActionIT {
.setOptimizedBestValue(false);
}
+ private void insertMetricAndLiveMeasure(ComponentDto dto, String key, String additionalData) {
+ MetricDto dataMetric = dbClient.metricDao().insert(dbSession, newDataMetricDto(key));
+ db.measures().insertLiveMeasure(dto, dataMetric, c -> c.setData(key + additionalData));
+
+ }
+
private static MetricDto newDataMetricDto(String key) {
return newMetricDto().setValueType(DATA.name()).setKey(key);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/IssueCounter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/IssueCounter.java
index 11cc56ac454..e2f3840e667 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/IssueCounter.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/IssueCounter.java
@@ -167,16 +167,16 @@ class IssueCounter {
return onlyInLeak ? count.leak : count.absolute;
}
- public String getBySoftwareQuality(SoftwareQuality softwareQuality) {
+ public String getBySoftwareQuality(SoftwareQuality softwareQuality, boolean onlyInLeak) {
Map<Severity, Count> severityToCount = bySoftwareQualityAndSeverity.get(softwareQuality);
ImpactMeasureBuilder impactMeasureBuilder;
if (severityToCount != null) {
impactMeasureBuilder = ImpactMeasureBuilder.newInstance();
for (Severity severity : Severity.values()) {
- impactMeasureBuilder = impactMeasureBuilder.setSeverity(severity, Optional.ofNullable(severityToCount.get(severity)).map(count -> count.absolute).orElse(0L));
+ impactMeasureBuilder = impactMeasureBuilder.setSeverity(severity, value(severityToCount.get(severity), onlyInLeak));
}
- impactMeasureBuilder = impactMeasureBuilder.setTotal(severityToCount.values().stream().mapToLong(count -> count.absolute).sum());
+ impactMeasureBuilder = impactMeasureBuilder.setTotal(severityToCount.values().stream().mapToLong(count -> value(count, onlyInLeak)).sum());
} else {
impactMeasureBuilder = ImpactMeasureBuilder.createEmpty();
}
@@ -197,6 +197,9 @@ class IssueCounter {
public void add(IssueImpactGroupDto group) {
absolute += group.getCount();
+ if (group.isInLeak()) {
+ leak += group.getCount();
+ }
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java
index 71eb40833c8..7cff81bb3d9 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java
@@ -89,7 +89,7 @@ public class LiveMeasureTreeUpdaterImpl implements LiveMeasureTreeUpdater {
components.getSortedTree().forEach(c -> {
IssueCounter issueCounter = new IssueCounter(dbClient.issueDao().selectIssueGroupsByComponent(dbSession, c, beginningOfLeak),
- dbClient.issueDao().selectIssueImpactGroupsByComponent(dbSession, c));
+ dbClient.issueDao().selectIssueImpactGroupsByComponent(dbSession, c, beginningOfLeak));
for (MeasureUpdateFormula formula : formulaFactory.getFormulas()) {
if (shouldComputeMetric(formula, useLeakFormulas, components.getBranch(), matrix)) {
context.change(c, formula);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java
index f70214658ae..24c02872a79 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java
@@ -60,13 +60,22 @@ public class MeasureUpdateFormulaFactoryImpl implements MeasureUpdateFormulaFact
(context, issues) -> context.setValue(issues.countUnresolvedByType(RuleType.SECURITY_HOTSPOT, false))),
new MeasureUpdateFormula(CoreMetrics.RELIABILITY_ISSUES, false, true, new ImpactAddChildren(),
- (context, issues) -> context.setValue(issues.getBySoftwareQuality(SoftwareQuality.RELIABILITY))),
+ (context, issues) -> context.setValue(issues.getBySoftwareQuality(SoftwareQuality.RELIABILITY, false))),
new MeasureUpdateFormula(CoreMetrics.MAINTAINABILITY_ISSUES, false, true, new ImpactAddChildren(),
- (context, issues) -> context.setValue(issues.getBySoftwareQuality(SoftwareQuality.MAINTAINABILITY))),
+ (context, issues) -> context.setValue(issues.getBySoftwareQuality(SoftwareQuality.MAINTAINABILITY, false))),
new MeasureUpdateFormula(CoreMetrics.SECURITY_ISSUES, false, true, new ImpactAddChildren(),
- (context, issues) -> context.setValue(issues.getBySoftwareQuality(SoftwareQuality.SECURITY))),
+ (context, issues) -> context.setValue(issues.getBySoftwareQuality(SoftwareQuality.SECURITY, false))),
+
+ new MeasureUpdateFormula(CoreMetrics.NEW_RELIABILITY_ISSUES, true, true, new ImpactAddChildren(),
+ (context, issues) -> context.setValue(issues.getBySoftwareQuality(SoftwareQuality.RELIABILITY, true))),
+
+ new MeasureUpdateFormula(CoreMetrics.NEW_MAINTAINABILITY_ISSUES, true, true, new ImpactAddChildren(),
+ (context, issues) -> context.setValue(issues.getBySoftwareQuality(SoftwareQuality.MAINTAINABILITY, true))),
+
+ new MeasureUpdateFormula(CoreMetrics.NEW_SECURITY_ISSUES, true, true, new ImpactAddChildren(),
+ (context, issues) -> context.setValue(issues.getBySoftwareQuality(SoftwareQuality.SECURITY, true))),
new MeasureUpdateFormula(CoreMetrics.VIOLATIONS, false, new AddChildren(),
(context, issues) -> context.setValue(issues.countUnresolved(false))),
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
index 3356cd598e8..98f87ca1bfb 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
@@ -99,6 +99,7 @@ public class ComponentAction implements MeasuresWsAction {
new Change("10.5", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
+ new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'new_maintainability_issues', 'new_reliability_issues', 'new_security_issues'"),
new Change("10.4", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube104())),
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
index 3e65aee8c97..845cf6ccc2c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
@@ -79,6 +79,9 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Optional.ofNullable;
import static org.sonar.api.measures.CoreMetrics.MAINTAINABILITY_ISSUES_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_ISSUES_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_ISSUES_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_ISSUES_KEY;
import static org.sonar.api.measures.CoreMetrics.RELIABILITY_ISSUES_KEY;
import static org.sonar.api.measures.CoreMetrics.SECURITY_ISSUES_KEY;
import static org.sonar.api.measures.Metric.ValueType.DATA;
@@ -184,6 +187,7 @@ public class ComponentTreeAction implements MeasuresWsAction {
.setHandler(this)
.addPagingParams(100, MAX_SIZE)
.setChangelog(
+ new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'new_maintainability_issues', 'new_reliability_issues', 'new_security_issues'"),
new Change("10.5", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
@@ -683,7 +687,14 @@ public class ComponentTreeAction implements MeasuresWsAction {
static final Set<String> FORBIDDEN_METRIC_TYPES = Set.of(DISTRIB.name());
static final Map<String, Set<String>> PARTIALLY_SUPPORTED_METRICS= Map. of(
- DATA.name(), Set.of(SECURITY_ISSUES_KEY, MAINTAINABILITY_ISSUES_KEY, RELIABILITY_ISSUES_KEY));
+ DATA.name(),
+ Set.of(
+ SECURITY_ISSUES_KEY,
+ MAINTAINABILITY_ISSUES_KEY,
+ RELIABILITY_ISSUES_KEY,
+ NEW_SECURITY_ISSUES_KEY,
+ NEW_MAINTAINABILITY_ISSUES_KEY,
+ NEW_RELIABILITY_ISSUES_KEY));
@Override
public boolean test(@Nonnull MetricDto input) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
index fc9743db4ea..6acd198f964 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
@@ -90,6 +90,7 @@ public class SearchAction implements MeasuresWsAction {
new Change("10.5", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
+ new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'new_maintainability_issues', 'new_reliability_issues', 'new_security_issues'"),
new Change("10.4", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube104())),
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
index 1c63a887e3f..2f47507fd31 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
@@ -98,6 +98,7 @@ public class SearchHistoryAction implements MeasuresWsAction {
new Change("10.5", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
+ new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'new_maintainability_issues', 'new_reliability_issues', 'new_security_issues'"),
new Change("10.4", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube104())),
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java
index b8e35b8882b..b3ef284a41d 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java
@@ -31,7 +31,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.measures.CoreMetrics;
@@ -62,13 +62,13 @@ import static org.sonar.api.measures.CoreMetrics.SECURITY_HOTSPOTS_TO_REVIEW_STA
import static org.sonar.api.measures.CoreMetrics.SECURITY_REVIEW_RATING;
import static org.sonar.test.JsonAssert.assertJson;
-public class MeasureUpdateFormulaFactoryImplTest {
+class MeasureUpdateFormulaFactoryImplTest {
- public static final Gson GSON = new GsonBuilder().create();
+ private static final Gson GSON = new GsonBuilder().create();
private final MeasureUpdateFormulaFactoryImpl underTest = new MeasureUpdateFormulaFactoryImpl();
@Test
- public void getFormulaMetrics_include_the_dependent_metrics() {
+ void getFormulaMetrics_include_the_dependent_metrics() {
for (MeasureUpdateFormula formula : underTest.getFormulas()) {
assertThat(underTest.getFormulaMetrics()).contains(formula.getMetric());
for (Metric<?> dependentMetric : formula.getDependentMetrics()) {
@@ -78,7 +78,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void hierarchy_adding_numbers() {
+ void hierarchy_adding_numbers() {
new HierarchyTester(CoreMetrics.VIOLATIONS)
.withValue(1d)
.withChildrenValues(2d, 3d)
@@ -95,7 +95,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void hierarchy_highest_rating() {
+ void hierarchy_highest_rating() {
new HierarchyTester(CoreMetrics.RELIABILITY_RATING)
.withValue(1d)
.withChildrenValues(2d, 3d)
@@ -113,7 +113,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void hierarchy_combining_other_metrics() {
+ void hierarchy_combining_other_metrics() {
new HierarchyTester(SECURITY_HOTSPOTS_TO_REVIEW_STATUS)
.withValue(SECURITY_HOTSPOTS_TO_REVIEW_STATUS, 1d)
.withChildrenHotspotsCounts(10, 10, 2, 10)
@@ -152,7 +152,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_violations() {
+ void test_violations() {
withNoIssues().assertThatValueIs(CoreMetrics.VIOLATIONS, 0);
with(newGroup(), newGroup().setCount(4)).assertThatValueIs(CoreMetrics.VIOLATIONS, 5);
@@ -166,7 +166,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_bugs() {
+ void test_bugs() {
withNoIssues().assertThatValueIs(CoreMetrics.BUGS, 0);
with(
newGroup(RuleType.BUG).setSeverity(Severity.MAJOR).setCount(3),
@@ -179,7 +179,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_code_smells() {
+ void test_code_smells() {
withNoIssues().assertThatValueIs(CoreMetrics.CODE_SMELLS, 0);
with(
newGroup(RuleType.CODE_SMELL).setSeverity(Severity.MAJOR).setCount(3),
@@ -192,7 +192,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_vulnerabilities() {
+ void test_vulnerabilities() {
withNoIssues().assertThatValueIs(CoreMetrics.VULNERABILITIES, 0);
with(
newGroup(RuleType.VULNERABILITY).setSeverity(Severity.MAJOR).setCount(3),
@@ -205,7 +205,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_security_hotspots() {
+ void test_security_hotspots() {
withNoIssues().assertThatValueIs(CoreMetrics.SECURITY_HOTSPOTS, 0);
with(
newGroup(RuleType.SECURITY_HOTSPOT).setSeverity(Severity.MAJOR).setCount(3),
@@ -218,7 +218,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_security_review_rating() {
+ void test_security_review_rating() {
with(
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED).setCount(3),
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setCount(1))
@@ -229,7 +229,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_security_hotspots_reviewed() {
+ void test_security_hotspots_reviewed() {
with(
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED).setCount(3),
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setCount(1))
@@ -240,7 +240,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_security_hotspots_reviewed_status() {
+ void test_security_hotspots_reviewed_status() {
with(
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED).setCount(3),
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setCount(1))
@@ -251,7 +251,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_security_hotspots_to_review_status() {
+ void test_security_hotspots_to_review_status() {
with(
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED).setCount(3),
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setCount(1))
@@ -262,7 +262,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void count_unresolved_by_severity() {
+ void count_unresolved_by_severity() {
withNoIssues()
.assertThatValueIs(CoreMetrics.BLOCKER_VIOLATIONS, 0)
.assertThatValueIs(CoreMetrics.CRITICAL_VIOLATIONS, 0)
@@ -291,7 +291,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void count_resolved() {
+ void count_resolved() {
withNoIssues()
.assertThatValueIs(CoreMetrics.FALSE_POSITIVE_ISSUES, 0)
.assertThatValueIs(CoreMetrics.ACCEPTED_ISSUES, 0);
@@ -312,7 +312,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void count_by_status() {
+ void count_by_status() {
withNoIssues()
.assertThatValueIs(CoreMetrics.CONFIRMED_ISSUES, 0)
.assertThatValueIs(CoreMetrics.OPEN_ISSUES, 0)
@@ -333,7 +333,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_technical_debt() {
+ void test_technical_debt() {
withNoIssues().assertThatValueIs(CoreMetrics.TECHNICAL_DEBT, 0);
with(
@@ -350,7 +350,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_reliability_remediation_effort() {
+ void test_reliability_remediation_effort() {
withNoIssues().assertThatValueIs(CoreMetrics.RELIABILITY_REMEDIATION_EFFORT, 0);
with(
@@ -364,7 +364,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_security_remediation_effort() {
+ void test_security_remediation_effort() {
withNoIssues().assertThatValueIs(CoreMetrics.SECURITY_REMEDIATION_EFFORT, 0);
with(
@@ -378,7 +378,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_sqale_debt_ratio_and_sqale_rating() {
+ void test_sqale_debt_ratio_and_sqale_rating() {
withNoIssues()
.assertThatValueIs(CoreMetrics.SQALE_DEBT_RATIO, 0)
.assertThatValueIs(CoreMetrics.SQALE_RATING, Rating.A);
@@ -449,7 +449,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_effort_to_reach_maintainability_rating_A() {
+ void test_effort_to_reach_maintainability_rating_A() {
withNoIssues()
.assertThatValueIs(CoreMetrics.EFFORT_TO_REACH_MAINTAINABILITY_RATING_A, 0.0);
@@ -493,7 +493,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_reliability_rating() {
+ void test_reliability_rating() {
withNoIssues()
.assertThatValueIs(CoreMetrics.RELIABILITY_RATING, Rating.A);
@@ -513,7 +513,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_security_rating() {
+ void test_security_rating() {
withNoIssues()
.assertThatValueIs(CoreMetrics.SECURITY_RATING, Rating.A);
@@ -533,7 +533,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_bugs() {
+ void test_new_bugs() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_BUGS, 0.0);
with(
@@ -548,7 +548,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_code_smells() {
+ void test_new_code_smells() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_CODE_SMELLS, 0.0);
with(
@@ -562,7 +562,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_vulnerabilities() {
+ void test_new_vulnerabilities() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_VULNERABILITIES, 0.0);
with(
@@ -576,7 +576,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_security_hotspots() {
+ void test_new_security_hotspots() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_SECURITY_HOTSPOTS, 0);
with(
@@ -590,7 +590,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_violations() {
+ void test_new_violations() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_VIOLATIONS, 0.0);
with(
@@ -605,7 +605,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_blocker_violations() {
+ void test_new_blocker_violations() {
withNoIssues()
.assertThatLeakValueIs(CoreMetrics.NEW_BLOCKER_VIOLATIONS, 0.0);
@@ -622,7 +622,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_critical_violations() {
+ void test_new_critical_violations() {
withNoIssues()
.assertThatLeakValueIs(CoreMetrics.NEW_CRITICAL_VIOLATIONS, 0.0);
@@ -639,7 +639,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_major_violations() {
+ void test_new_major_violations() {
withNoIssues()
.assertThatLeakValueIs(CoreMetrics.NEW_MAJOR_VIOLATIONS, 0.0);
@@ -656,7 +656,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_minor_violations() {
+ void test_new_minor_violations() {
withNoIssues()
.assertThatLeakValueIs(CoreMetrics.NEW_MINOR_VIOLATIONS, 0.0);
@@ -673,7 +673,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_info_violations() {
+ void test_new_info_violations() {
withNoIssues()
.assertThatLeakValueIs(CoreMetrics.NEW_INFO_VIOLATIONS, 0.0);
@@ -690,7 +690,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_accepted_issues() {
+ void test_new_accepted_issues() {
withNoIssues()
.assertThatLeakValueIs(CoreMetrics.NEW_ACCEPTED_ISSUES, 0);
@@ -706,7 +706,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_technical_debt() {
+ void test_new_technical_debt() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_TECHNICAL_DEBT, 0.0);
with(
@@ -722,7 +722,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_reliability_remediation_effort() {
+ void test_new_reliability_remediation_effort() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_RELIABILITY_REMEDIATION_EFFORT, 0.0);
with(
@@ -737,7 +737,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_security_remediation_effort() {
+ void test_new_security_remediation_effort() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_SECURITY_REMEDIATION_EFFORT, 0.0);
with(
@@ -752,7 +752,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_reliability_rating() {
+ void test_new_reliability_rating() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_RELIABILITY_RATING, Rating.A);
with(
@@ -769,7 +769,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_security_rating() {
+ void test_new_security_rating() {
withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_SECURITY_RATING, Rating.A);
with(
@@ -786,7 +786,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_security_review_rating() {
+ void test_new_security_review_rating() {
with(
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED).setCount(3).setInLeak(true),
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setCount(1).setInLeak(true),
@@ -799,7 +799,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_security_hotspots_reviewed() {
+ void test_new_security_hotspots_reviewed() {
with(
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED).setCount(3).setInLeak(true),
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setCount(1).setInLeak(true),
@@ -812,7 +812,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_security_hotspots_reviewed_status() {
+ void test_new_security_hotspots_reviewed_status() {
with(
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED).setCount(3).setInLeak(true),
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setCount(1).setInLeak(true),
@@ -825,7 +825,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_security_hotspots_to_review_status() {
+ void test_new_security_hotspots_to_review_status() {
with(
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_REVIEWED).setCount(3).setInLeak(true),
newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setCount(1).setInLeak(true),
@@ -838,7 +838,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void test_new_sqale_debt_ratio_and_new_maintainability_rating() {
+ void test_new_sqale_debt_ratio_and_new_maintainability_rating() {
withNoIssues()
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
@@ -909,7 +909,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void compute_shouldComputeHighImpactAcceptedIssues() {
+ void compute_shouldComputeHighImpactAcceptedIssues() {
withNoIssues()
.assertThatValueIs(CoreMetrics.HIGH_IMPACT_ACCEPTED_ISSUES, 0);
@@ -927,7 +927,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void computeHierarchy_shouldComputeImpactMeasures() {
+ void computeHierarchy_shouldComputeImpactMeasures() {
new HierarchyTester(CoreMetrics.RELIABILITY_ISSUES)
.withValue(impactMeasureToJson(6, 1, 2, 3))
.withChildrenValues(impactMeasureToJson(6, 1, 2, 3), impactMeasureToJson(10, 5, 3, 2))
@@ -939,7 +939,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void compute_shouldComputeImpactMeasures() {
+ void compute_shouldComputeImpactMeasures() {
with(
newImpactGroup(RELIABILITY, HIGH, 3),
newImpactGroup(RELIABILITY, MEDIUM, 4),
@@ -953,11 +953,14 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Test
- public void compute_whenNoIssues_shouldComputeImpactMeasures() {
+ void compute_whenNoIssues_shouldComputeImpactMeasures() {
withNoIssues()
.assertThatJsonValueIs(CoreMetrics.RELIABILITY_ISSUES, impactMeasureToJson(0, 0, 0, 0))
.assertThatJsonValueIs(CoreMetrics.MAINTAINABILITY_ISSUES, impactMeasureToJson(0, 0, 0, 0))
- .assertThatJsonValueIs(CoreMetrics.SECURITY_ISSUES, impactMeasureToJson(0, 0, 0, 0));
+ .assertThatJsonValueIs(CoreMetrics.SECURITY_ISSUES, impactMeasureToJson(0, 0, 0, 0))
+ .assertThatLeakValueIs(CoreMetrics.NEW_RELIABILITY_ISSUES, impactMeasureToJson(0, 0, 0, 0))
+ .assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_ISSUES, impactMeasureToJson(0, 0, 0, 0))
+ .assertThatLeakValueIs(CoreMetrics.NEW_SECURITY_ISSUES, impactMeasureToJson(0, 0, 0, 0));
}
private static String impactMeasureToJson(long total, long high, long medium, long low) {
@@ -1031,6 +1034,12 @@ public class MeasureUpdateFormulaFactoryImplTest {
return this;
}
+ Verifier assertThatLeakValueIs(Metric metric, String expectedValue) {
+ TestContext context = run(metric, true);
+ assertJson(context.stringValue).isSimilarTo(expectedValue);
+ return this;
+ }
+
Verifier assertNoLeakValue(Metric metric) {
TestContext context = run(metric, true);
assertThat(context.ratingValue).isNull();