aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/it/java
diff options
context:
space:
mode:
authorPierre Guillot <pierre.guillot@sonarsource.com>2024-12-10 15:29:09 +0100
committerSteve Marion <steve.marion@sonarsource.com>2024-12-18 11:13:21 +0100
commitd639a965bce7acafb004906cd07a8f0b5f7af993 (patch)
tree647cd646abddb12dfeeef7e637aa33b4658f1049 /server/sonar-db-dao/src/it/java
parent451c1c2e4856ec3df87f86189fcdb25b31794027 (diff)
downloadsonarqube-d639a965bce7acafb004906cd07a8f0b5f7af993.tar.gz
sonarqube-d639a965bce7acafb004906cd07a8f0b5f7af993.zip
SONAR-22998 fetch active rules with a dedicated endpoint
Co-authored-by: Julien HENRY <julien.henry@sonarsource.com>
Diffstat (limited to 'server/sonar-db-dao/src/it/java')
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/ActiveRuleDaoIT.java74
1 files changed, 66 insertions, 8 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/ActiveRuleDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/ActiveRuleDaoIT.java
index b229d7895b6..eeebb9d5b9e 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/ActiveRuleDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/qualityprofile/ActiveRuleDaoIT.java
@@ -62,6 +62,7 @@ import static org.sonar.api.rule.Severity.MAJOR;
import static org.sonar.db.qualityprofile.ActiveRuleDto.INHERITED;
import static org.sonar.db.qualityprofile.ActiveRuleDto.OVERRIDES;
import static org.sonar.db.qualityprofile.ActiveRuleDto.createFor;
+import static org.sonar.db.rule.RuleDto.deserializeSecurityStandardsString;
class ActiveRuleDaoIT {
@@ -113,6 +114,19 @@ class ActiveRuleDaoIT {
}
@Test
+ void selectAllParamsByProfileUuids() {
+ ActiveRuleDto activeRule = createFor(profile1, rule1).setSeverity(BLOCKER);
+ underTest.insert(dbSession, activeRule);
+ ActiveRuleParamDto activeRuleParam1 = ActiveRuleParamDto.createFor(rule1Param1);
+ underTest.insertParam(dbSession, activeRule, activeRuleParam1);
+ ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(rule1Param2);
+ underTest.insertParam(dbSession, activeRule, activeRuleParam2);
+ dbSession.commit();
+
+ assertThat(underTest.selectAllParamsByProfileUuids(dbSession, List.of(profile1.getKee()))).hasSize(2);
+ }
+
+ @Test
void selectByKey() {
ActiveRuleDto activeRule = createFor(profile1, rule1).setSeverity(BLOCKER);
underTest.insert(dbSession, activeRule);
@@ -184,6 +198,50 @@ class ActiveRuleDaoIT {
}
@Test
+ void selectByProfileUuids_ignores_removed_rules() {
+ ActiveRuleDto activeRule = createFor(profile1, removedRule).setSeverity(BLOCKER);
+ underTest.insert(dbSession, activeRule);
+
+ assertThat(underTest.selectByProfileUuids(dbSession, List.of(profile1.getKee()))).isEmpty();
+ }
+
+ @Test
+ void selectByProfileUuids_exclude_other_profiles() {
+ ActiveRuleDto activeRule = createFor(profile1, rule1).setSeverity(BLOCKER);
+ underTest.insert(dbSession, activeRule);
+ ActiveRuleDto activeRule2 = createFor(profile2, rule2).setSeverity(BLOCKER);
+ underTest.insert(dbSession, activeRule2);
+
+ assertThat(underTest.selectByProfileUuids(dbSession, List.of(profile1.getKee()))).hasSize(1);
+ }
+
+ @Test
+ void selectByProfileUuids_returns_all_fields() {
+ ActiveRuleDto activeRule = createFor(profile1, rule1).setSeverity(BLOCKER);
+ underTest.insert(dbSession, activeRule);
+
+ List<OrgActiveRuleDto> actualActiveRule = underTest.selectByProfileUuids(dbSession, List.of(profile1.getKee()));
+ // verify data from the "rules" table
+ assertThat(actualActiveRule)
+ .extracting(OrgActiveRuleDto::getRuleKey, org -> deserializeSecurityStandardsString(org.getSecurityStandards()), OrgActiveRuleDto::isExternal, OrgActiveRuleDto::getName,
+ OrgActiveRuleDto::getConfigKey, OrgActiveRuleDto::getTemplateUuid, OrgActiveRuleDto::getLanguage)
+ .containsExactly(
+ tuple(rule1.getKey(), rule1.getSecurityStandards(), rule1.isExternal(), rule1.getName(), rule1.getConfigKey(), rule1.getTemplateUuid(), rule1.getLanguage()));
+
+ // verify data from "active_rules" table
+ assertThat(actualActiveRule)
+ .extracting(OrgActiveRuleDto::getUuid, OrgActiveRuleDto::getProfileUuid, OrgActiveRuleDto::getRuleUuid, OrgActiveRuleDto::getSeverity, OrgActiveRuleDto::getInheritance,
+ OrgActiveRuleDto::isPrioritizedRule, OrgActiveRuleDto::getCreatedAt, OrgActiveRuleDto::getUpdatedAt)
+ .containsExactly(tuple(activeRule.getUuid(), activeRule.getProfileUuid(), activeRule.getRuleUuid(), activeRule.getSeverity(), activeRule.getInheritance(),
+ activeRule.isPrioritizedRule(), activeRule.getCreatedAt(), activeRule.getUpdatedAt()));
+
+ // verify data from "rules_profiles" and "org_qprofiles"
+ assertThat(actualActiveRule)
+ .extracting(o -> o.getKey().getRuleProfileUuid(), OrgActiveRuleDto::getOrgProfileUuid)
+ .containsExactly(tuple(activeRule.getKey().getRuleProfileUuid(), profile1.getKee()));
+ }
+
+ @Test
void selectByTypeAndProfileUuids() {
RuleDto rule1 = db.rules().insert(r -> r.setType(RuleType.VULNERABILITY.getDbConstant()));
ActiveRuleDto activeRule1 = createFor(profile1, rule1).setSeverity(BLOCKER);
@@ -192,8 +250,8 @@ class ActiveRuleDaoIT {
assertThat(underTest.selectByTypeAndProfileUuids(dbSession, singletonList(RuleType.VULNERABILITY.getDbConstant()),
singletonList(profile1.getKee())))
- .extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getRuleUuid)
- .contains(tuple(profile1.getKee(), rule1.getUuid()));
+ .extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getRuleUuid)
+ .contains(tuple(profile1.getKee(), rule1.getUuid()));
}
@Test
@@ -205,7 +263,7 @@ class ActiveRuleDaoIT {
assertThat(underTest.selectByTypeAndProfileUuids(dbSession, singletonList(RuleType.VULNERABILITY.getDbConstant()),
singletonList(profile1.getKee())))
- .isEmpty();
+ .isEmpty();
}
@Test
@@ -219,14 +277,14 @@ class ActiveRuleDaoIT {
underTest.selectByTypeAndProfileUuids(dbSession,
singletonList(RuleType.VULNERABILITY.getDbConstant()),
singletonList(profile1.getKee())))
- .extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getRuleUuid)
- .contains(tuple(profile1.getKee(), rule1.getUuid()));
+ .extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getRuleUuid)
+ .contains(tuple(profile1.getKee(), rule1.getUuid()));
assertThat(
underTest.selectByTypeAndProfileUuids(dbSession,
asList(RuleType.CODE_SMELL.getDbConstant(), RuleType.SECURITY_HOTSPOT.getDbConstant(), RuleType.BUG.getDbConstant()),
singletonList(profile1.getKee())))
- .isEmpty();
+ .isEmpty();
}
@Test
@@ -684,10 +742,10 @@ class ActiveRuleDaoIT {
ActiveRuleCountQuery.Builder builder = ActiveRuleCountQuery.builder();
assertThat(underTest.countActiveRulesByQuery(dbSession,
builder.setProfiles(asList(profile1, profile2)).setInheritance(OVERRIDES).build()))
- .containsOnly(entry(profile1.getKee(), 1L), entry(profile2.getKee(), 1L));
+ .containsOnly(entry(profile1.getKee(), 1L), entry(profile2.getKee(), 1L));
assertThat(underTest.countActiveRulesByQuery(dbSession,
builder.setProfiles(asList(profile1, profile2)).setInheritance(INHERITED).build()))
- .containsOnly(entry(profile2.getKee(), 1L));
+ .containsOnly(entry(profile2.getKee(), 1L));
}
@Test