use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueDbTester method insertHotspot.
/**
* Inserts a Security Hotspot.
*/
@SafeVarargs
public final IssueDto insertHotspot(Consumer<IssueDto>... populators) {
RuleDefinitionDto rule = db.rules().insertHotspotRule();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = newIssue(rule, project, file).setType(SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setResolution(null);
stream(populators).forEach(p -> p.accept(issue));
return insertHotspot(issue);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueDbTester method insertIssue.
/**
* Inserts an issue.
*
* @throws AssertionError if rule is not Security Hotspot
*/
@SafeVarargs
public final IssueDto insertIssue(Consumer<IssueDto>... populators) {
RuleDefinitionDto rule = db.rules().insertIssueRule();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = newIssue(rule, project, file).setType(RULE_TYPES_EXCEPT_HOTSPOTS[new Random().nextInt(RULE_TYPES_EXCEPT_HOTSPOTS.length)]);
stream(populators).forEach(p -> p.accept(issue));
return insertIssue(issue);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class DefaultRuleFinder method findAll.
@Override
public Collection<RuleDefinitionDto> findAll() {
try (DbSession dbSession = dbClient.openSession(false)) {
List<RuleDefinitionDto> list = new ArrayList<>();
ruleDao.selectEnabled(dbSession, r -> list.add(r.getResultObject()));
return list;
}
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class NewIssuesNotificationTest method add_only_5_rules_with_biggest_issue_counts.
@Test
public void add_only_5_rules_with_biggest_issue_counts() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true);
RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("Java"));
IntStream.rangeClosed(1, 10).forEach(i -> stats.add(db.issues().insert(rule1, project, file).toDefaultIssue()));
RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("Java"));
IntStream.rangeClosed(1, 9).forEach(i -> stats.add(db.issues().insert(rule2, project, file).toDefaultIssue()));
RuleDefinitionDto rule3 = db.rules().insert(r -> r.setLanguage("Java"));
IntStream.rangeClosed(1, 8).forEach(i -> stats.add(db.issues().insert(rule3, project, file).toDefaultIssue()));
RuleDefinitionDto rule4 = db.rules().insert(r -> r.setLanguage("Java"));
IntStream.rangeClosed(1, 7).forEach(i -> stats.add(db.issues().insert(rule4, project, file).toDefaultIssue()));
RuleDefinitionDto rule5 = db.rules().insert(r -> r.setLanguage("Java"));
IntStream.rangeClosed(1, 6).forEach(i -> stats.add(db.issues().insert(rule5, project, file).toDefaultIssue()));
RuleDefinitionDto rule6 = db.rules().insert(r -> r.setLanguage("Java"));
IntStream.rangeClosed(1, 5).forEach(i -> stats.add(db.issues().insert(rule6, project, file).toDefaultIssue()));
RuleDefinitionDto rule7 = db.rules().insert(r -> r.setLanguage("Java"));
IntStream.rangeClosed(1, 4).forEach(i -> stats.add(db.issues().insert(rule7, project, file).toDefaultIssue()));
RuleDefinitionDto rule8 = db.rules().insert(r -> r.setLanguage("Java"));
IntStream.rangeClosed(1, 3).forEach(i -> stats.add(db.issues().insert(rule8, project, file).toDefaultIssue()));
mockDetailsSupplierComponents(project, file);
mockDetailsSupplierRules(rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8);
underTest.setStatistics(project.longName(), stats);
String javaSuffix = " (Java)";
assertThat(underTest.getFieldValue(RULE + ".1.label")).isEqualTo(rule1.getName() + javaSuffix);
assertThat(underTest.getFieldValue(RULE + ".1.count")).isEqualTo("10");
assertThat(underTest.getFieldValue(RULE + ".2.label")).isEqualTo(rule2.getName() + javaSuffix);
assertThat(underTest.getFieldValue(RULE + ".2.count")).isEqualTo("9");
assertThat(underTest.getFieldValue(RULE + ".3.label")).isEqualTo(rule3.getName() + javaSuffix);
assertThat(underTest.getFieldValue(RULE + ".3.count")).isEqualTo("8");
assertThat(underTest.getFieldValue(RULE + ".4.label")).isEqualTo(rule4.getName() + javaSuffix);
assertThat(underTest.getFieldValue(RULE + ".4.count")).isEqualTo("7");
assertThat(underTest.getFieldValue(RULE + ".5.label")).isEqualTo(rule5.getName() + javaSuffix);
assertThat(underTest.getFieldValue(RULE + ".5.count")).isEqualTo("6");
assertThat(underTest.getFieldValue(RULE + ".6.label")).isNull();
assertThat(underTest.getFieldValue(RULE + ".6.count")).isNull();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class NewIssuesNotificationTest method set_statistics_when_some_issues_are_no_created_on_current_analysis.
@Test
public void set_statistics_when_some_issues_are_no_created_on_current_analysis() {
UserDto maynard = db.users().insertUser(u -> u.setLogin("maynard"));
UserDto keenan = db.users().insertUser(u -> u.setLogin("keenan"));
ComponentDto project = db.components().insertPrivateProject();
ComponentDto directory = db.components().insertComponent(newDirectory(project, "path"));
ComponentDto file = db.components().insertComponent(newFileDto(directory));
RuleDefinitionDto rule1 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-world").setName("Rule the World").setLanguage("Java"));
RuleDefinitionDto rule2 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-universe").setName("Rule the Universe").setLanguage("Clojure"));
IssueDto issue1 = db.issues().insert(rule1, project, file, i -> i.setType(BUG).setAssigneeUuid(maynard.getUuid()).setTags(asList("bug", "owasp")));
IssueDto issue2 = db.issues().insert(rule2, project, directory, i -> i.setType(CODE_SMELL).setAssigneeUuid(keenan.getUuid()).setTags(singletonList("owasp")));
NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> i.key().equals(issue2.getKey()));
IntStream.rangeClosed(1, 5).forEach(i -> stats.add(issue1.toDefaultIssue()));
IntStream.rangeClosed(1, 3).forEach(i -> stats.add(issue2.toDefaultIssue()));
mockDetailsSupplierComponents(project, directory, file);
mockDetailsSupplierRules(rule1, rule2);
mockDetailsSupplierAssignees(maynard, keenan);
underTest.setStatistics(project.longName(), stats);
assertThat(underTest.getFieldValue(RULE_TYPE + ".BUG.count")).isEqualTo("0");
assertThat(underTest.getFieldValue(RULE_TYPE + ".CODE_SMELL.count")).isEqualTo("3");
assertThat(underTest.getFieldValue(ASSIGNEE + ".1.label")).isEqualTo(keenan.getName());
assertThat(underTest.getFieldValue(ASSIGNEE + ".1.count")).isEqualTo("3");
assertThat(underTest.getFieldValue(ASSIGNEE + ".2.label")).isNull();
assertThat(underTest.getFieldValue(ASSIGNEE + ".2.count")).isNull();
assertThat(underTest.getFieldValue(TAG + ".1.label")).isEqualTo("owasp");
assertThat(underTest.getFieldValue(TAG + ".1.count")).isEqualTo("3");
assertThat(underTest.getFieldValue(TAG + ".2.label")).isNull();
assertThat(underTest.getFieldValue(TAG + ".2.count")).isNull();
assertThat(underTest.getFieldValue(COMPONENT + ".1.label")).isEqualTo(directory.name());
assertThat(underTest.getFieldValue(COMPONENT + ".1.count")).isEqualTo("3");
assertThat(underTest.getFieldValue(COMPONENT + ".2.label")).isNull();
assertThat(underTest.getFieldValue(COMPONENT + ".2.count")).isNull();
assertThat(underTest.getFieldValue(RULE + ".1.label")).isEqualTo("Rule the Universe (Clojure)");
assertThat(underTest.getFieldValue(RULE + ".1.count")).isEqualTo("3");
assertThat(underTest.getFieldValue(RULE + ".2.label")).isNull();
assertThat(underTest.getFieldValue(RULE + ".2.count")).isNull();
assertThat(underTest.getDefaultMessage()).startsWith("3 new issues on " + project.longName());
}
Aggregations