]> source.dussan.org Git - sonarqube.git/blob
ed9119174ecabaae7236583dc5e1788df25aa1d2
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2024 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 package org.sonar.server.measure.index;
21
22 import java.util.HashMap;
23 import java.util.Map;
24 import org.junit.jupiter.api.Test;
25 import org.sonar.api.measures.CoreMetrics;
26 import org.sonar.core.metric.SoftwareQualitiesMetrics;
27 import org.sonar.server.measure.Rating;
28
29 import static org.assertj.core.api.Assertions.assertThat;
30
31 class ProjectMeasuresSoftwareQualityRatingsInitializerTest {
32
33   @Test
34   void initializeSoftwareQualityRatings_whenNoRating_thenNoSoftwareQualityRatingMetric() {
35     Map<String, Double> initialMeasures = new HashMap<>();
36     initialMeasures.put(CoreMetrics.BRANCH_COVERAGE_KEY, null);
37     initialMeasures.put(CoreMetrics.ACCEPTED_ISSUES_KEY, 12.0);
38     initialMeasures.put(CoreMetrics.SQALE_RATING_KEY, null);
39
40     Map<String, Double> measures = new HashMap<>(initialMeasures);
41     ProjectMeasuresSoftwareQualityRatingsInitializer.initializeSoftwareQualityRatings(measures);
42
43     assertThat(measures).containsExactlyInAnyOrderEntriesOf(initialMeasures);
44   }
45
46   @Test
47   void initializeSoftwareQualityRatings_whenRatingAndNoSoftwareQualityRating_thenSoftwareQualityRatingMetricAreCreated() {
48     Map<String, Double> initialMeasures = new HashMap<>();
49     initialMeasures.put(CoreMetrics.SQALE_RATING_KEY, 1.0);
50     initialMeasures.put(CoreMetrics.RELIABILITY_RATING_KEY, 2.0);
51     initialMeasures.put(CoreMetrics.SECURITY_RATING_KEY, 3.0);
52     initialMeasures.put(CoreMetrics.SECURITY_REVIEW_RATING_KEY, 4.0);
53     initialMeasures.put(CoreMetrics.NEW_SECURITY_RATING_KEY, 4.0);
54     initialMeasures.put(CoreMetrics.NEW_SECURITY_REVIEW_RATING_KEY, 3.0);
55     initialMeasures.put(CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY, 2.0);
56     initialMeasures.put(CoreMetrics.NEW_RELIABILITY_RATING_KEY, 1.0);
57
58     Map<String, Double> measures = new HashMap<>(initialMeasures);
59
60     ProjectMeasuresSoftwareQualityRatingsInitializer.initializeSoftwareQualityRatings(measures);
61
62     assertThat(measures).hasSize(initialMeasures.size() * 2)
63       .containsAllEntriesOf(initialMeasures)
64       .containsEntry(SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY, 1.0)
65       .containsEntry(SoftwareQualitiesMetrics.SOFTWARE_QUALITY_RELIABILITY_RATING_KEY, 2.0)
66       .containsEntry(SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_RATING_KEY, 3.0)
67       .containsEntry(SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY, 4.0)
68       .containsEntry(SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_RATING_KEY, 4.0)
69       .containsEntry(SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY, 3.0)
70       .containsEntry(SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY, 2.0)
71       .containsEntry(SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_RELIABILITY_RATING_KEY, 1.0);
72   }
73
74   @Test
75   void initializeSoftwareQualityRatings_whenERating_thenSoftwareQualityRatingCreatedWithD() {
76     Map<String, Double> initialMeasures = new HashMap<>();
77     initialMeasures.put(CoreMetrics.SQALE_RATING_KEY, (double) Rating.E.getIndex());
78     initialMeasures.put(CoreMetrics.RELIABILITY_RATING_KEY, (double) Rating.E.getIndex());
79     initialMeasures.put(CoreMetrics.SECURITY_RATING_KEY, (double) Rating.E.getIndex());
80     initialMeasures.put(CoreMetrics.SECURITY_REVIEW_RATING_KEY, (double) Rating.E.getIndex());
81     initialMeasures.put(CoreMetrics.NEW_SECURITY_RATING_KEY, (double) Rating.E.getIndex());
82     initialMeasures.put(CoreMetrics.NEW_SECURITY_REVIEW_RATING_KEY, (double) Rating.E.getIndex());
83     initialMeasures.put(CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY, (double) Rating.E.getIndex());
84     initialMeasures.put(CoreMetrics.NEW_RELIABILITY_RATING_KEY, (double) Rating.E.getIndex());
85
86     Map<String, Double> measures = new HashMap<>(initialMeasures);
87
88     ProjectMeasuresSoftwareQualityRatingsInitializer.initializeSoftwareQualityRatings(measures);
89
90     assertThat(measures).hasSize(initialMeasures.size() * 2)
91       .containsAllEntriesOf(initialMeasures)
92       .containsEntry(SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY, (double) Rating.D.getIndex())
93       .containsEntry(SoftwareQualitiesMetrics.SOFTWARE_QUALITY_RELIABILITY_RATING_KEY, (double) Rating.D.getIndex())
94       .containsEntry(SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_RATING_KEY, (double) Rating.D.getIndex())
95       .containsEntry(SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY, (double) Rating.D.getIndex())
96       .containsEntry(SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_RATING_KEY, (double) Rating.D.getIndex())
97       .containsEntry(SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY, (double) Rating.D.getIndex())
98       .containsEntry(SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY, (double) Rating.D.getIndex())
99       .containsEntry(SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_RELIABILITY_RATING_KEY, (double) Rating.D.getIndex());
100   }
101 }