import org.sonar.server.es.SearchIdResult;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.es.metadata.MetadataIndex;
-import org.sonar.server.plugins.DetectPluginChange;
import org.sonar.server.plugins.ServerPluginRepository;
import org.sonar.server.property.InternalProperties;
import org.sonar.server.property.MapInternalProperties;
.key(s.getKey())
.content(s.getHtmlContent())
.context(s.getContext().map(c -> RuleDescriptionSectionContextDto.of(c.getKey(), c.getDisplayName())).orElse(null))
- .build()
- )
+ .build())
.collect(Collectors.toSet());
return Sets.union(ruleDescriptionSectionDtos, Set.of(builder().uuid(UuidFactoryFast.getInstance().create()).key("default").content(description).build()));
});
assertThat(rule1.getType()).isEqualTo(RuleType.BUG.getDbConstant());
assertThat(rule1.getCreatedAt()).isEqualTo(DATE1.getTime());
assertThat(rule1.getUpdatedAt()).isEqualTo(DATE2.getTime());
- assertThat(rule1.getEducationPrinciples()).containsOnly("concept1","concept4");
+ assertThat(rule1.getEducationPrinciples()).containsOnly("concept1", "concept4");
}
@Test
}
private static Object[][] allRenamingCases() {
- return new Object[][]{
+ return new Object[][] {
{"repo1", "rule1", "repo1", "rule2"},
{"repo1", "rule1", "repo2", "rule1"},
{"repo1", "rule1", "repo2", "rule2"},
RuleDescriptionSection section1context1 = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx1 content", "ctx_1");
RuleDescriptionSection section1context2 = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx2 content", "ctx_2");
RuleDescriptionSection section2context1 = createRuleDescriptionSection(RESOURCES_SECTION_KEY, "section2 content", "ctx_1");
- RuleDescriptionSection section2context2 = createRuleDescriptionSection(RESOURCES_SECTION_KEY,"section2 ctx2 content", "ctx_2");
+ RuleDescriptionSection section2context2 = createRuleDescriptionSection(RESOURCES_SECTION_KEY, "section2 ctx2 content", "ctx_2");
RuleDescriptionSection section3noContext = createRuleDescriptionSection(ASSESS_THE_PROBLEM_SECTION_KEY, "section3 content", null);
RuleDescriptionSection section4noContext = createRuleDescriptionSection(ROOT_CAUSE_SECTION_KEY, "section4 content", null);
executeWithPluginRules(context -> {
@Test
void removed_rule_should_appear_in_changelog() {
- //GIVEN
+ // GIVEN
QProfileDto qProfileDto = db.qualityProfiles().insert();
RuleDto ruleDto = db.rules().insert(RULE_KEY1);
db.qualityProfiles().activateRule(qProfileDto, ruleDto);
ActiveRuleChange arChange = new ActiveRuleChange(DEACTIVATED, ActiveRuleDto.createFor(qProfileDto, ruleDto), ruleDto);
when(qProfileRules.deleteRule(any(DbSession.class), eq(ruleDto))).thenReturn(List.of(arChange));
- //WHEN
+ // WHEN
executeWithPluginRules(context -> context.createRepository("fake", "java").done());
- //THEN
+ // THEN
List<QProfileChangeDto> qProfileChangeDtos = dbClient.qProfileChangeDao().selectByQuery(db.getSession(), new QProfileChangeQuery(qProfileDto.getKee()));
assertThat(qProfileChangeDtos).extracting(QProfileChangeDto::getRulesProfileUuid, QProfileChangeDto::getChangeType, QProfileChangeDto::getSqVersion)
.contains(tuple(qProfileDto.getRulesProfileUuid(), "DEACTIVATED", sonarQubeVersion.toString()));
@Test
void removed_rule_should_be_deleted_when_renamed_repository() {
- //GIVEN
+ // GIVEN
RuleDto removedRuleDto = db.rules().insert(RuleKey.of("old_repo", "removed_rule"));
RuleDto renamedRuleDto = db.rules().insert(RuleKey.of("old_repo", "renamed_rule"));
- //WHEN
+ // WHEN
executeWithPluginRules(context -> createRule(context, "java", "new_repo", renamedRuleDto.getRuleKey(),
rule -> rule.addDeprecatedRuleKey(renamedRuleDto.getRepositoryKey(), renamedRuleDto.getRuleKey())));
- //THEN
+ // THEN
verify(qProfileRules).deleteRule(any(DbSession.class), eq(removedRuleDto));
}
repo.createRule("rule1")
.setName("any")
.setHtmlDescription("html")
+ .setType(RuleType.VULNERABILITY)
.addDefaultImpact(SoftwareQuality.SECURITY, Severity.HIGH)
.setSeverity(SeverityUtil.getSeverityFromOrdinal(2));
repo.done();
repo.createRule("rule1")
.setName("any")
.setHtmlDescription("html")
+ .setType(RuleType.VULNERABILITY)
.addDefaultImpact(SoftwareQuality.SECURITY, Severity.LOW)
.setSeverity(SeverityUtil.getSeverityFromOrdinal(2));
repo.done();
}
@Test
- void mapImpactSeverities_whenOneDifferentImpact_shouldReturnOverriddenImpact() {
+ void mapImpactSeverities_whenOneDifferentImpact_shouldNotOverrideImpact() {
Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> result = QProfileImpactSeverityMapper.mapImpactSeverities(Severity.INFO,
Map.of(SoftwareQuality.RELIABILITY,
org.sonar.api.issue.impact.Severity.HIGH),
RuleType.CODE_SMELL);
- assertThat(result).hasSize(1).containsEntry(SoftwareQuality.RELIABILITY, org.sonar.api.issue.impact.Severity.INFO);
+ assertThat(result).hasSize(1).containsEntry(SoftwareQuality.RELIABILITY, org.sonar.api.issue.impact.Severity.HIGH);
}
@Test
}
@Test
- void mapSeverity_whenOneImpact_ShouldReturnMappedImpactSeverity() {
+ void mapSeverity_whenOneImpactNotMatchingRuleType_ShouldReturnSameSeverity() {
String severity = QProfileImpactSeverityMapper.mapSeverity(
Map.of(SoftwareQuality.MAINTAINABILITY, org.sonar.api.issue.impact.Severity.HIGH),
RuleType.BUG, Severity.BLOCKER);
- assertThat(severity).isEqualTo(Severity.CRITICAL);
+ assertThat(severity).isEqualTo(Severity.BLOCKER);
}
@Test