use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class NewIssuesNotificationTest method add_only_5_components_with_biggest_issue_counts.
@Test
public void add_only_5_components_with_biggest_issue_counts() {
ComponentDto project = db.components().insertPrivateProject();
RuleDefinitionDto rule = db.rules().insert();
NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true);
ComponentDto file1 = db.components().insertComponent(newFileDto(project));
IntStream.rangeClosed(1, 10).forEach(i -> stats.add(db.issues().insert(rule, project, file1).toDefaultIssue()));
ComponentDto file2 = db.components().insertComponent(newFileDto(project));
IntStream.rangeClosed(1, 9).forEach(i -> stats.add(db.issues().insert(rule, project, file2).toDefaultIssue()));
ComponentDto file3 = db.components().insertComponent(newFileDto(project));
IntStream.rangeClosed(1, 8).forEach(i -> stats.add(db.issues().insert(rule, project, file3).toDefaultIssue()));
ComponentDto file4 = db.components().insertComponent(newFileDto(project));
IntStream.rangeClosed(1, 7).forEach(i -> stats.add(db.issues().insert(rule, project, file4).toDefaultIssue()));
ComponentDto file5 = db.components().insertComponent(newFileDto(project));
IntStream.rangeClosed(1, 6).forEach(i -> stats.add(db.issues().insert(rule, project, file5).toDefaultIssue()));
ComponentDto file6 = db.components().insertComponent(newFileDto(project));
IntStream.rangeClosed(1, 5).forEach(i -> stats.add(db.issues().insert(rule, project, file6).toDefaultIssue()));
ComponentDto file7 = db.components().insertComponent(newFileDto(project));
IntStream.rangeClosed(1, 4).forEach(i -> stats.add(db.issues().insert(rule, project, file7).toDefaultIssue()));
ComponentDto file8 = db.components().insertComponent(newFileDto(project));
IntStream.rangeClosed(1, 3).forEach(i -> stats.add(db.issues().insert(rule, project, file8).toDefaultIssue()));
mockDetailsSupplierComponents(project, file1, file2, file3, file4, file5, file6, file7, file8);
mockDetailsSupplierRules(rule);
underTest.setStatistics(project.longName(), stats);
assertThat(underTest.getFieldValue(COMPONENT + ".1.label")).isEqualTo(file1.name());
assertThat(underTest.getFieldValue(COMPONENT + ".1.count")).isEqualTo("10");
assertThat(underTest.getFieldValue(COMPONENT + ".2.label")).isEqualTo(file2.name());
assertThat(underTest.getFieldValue(COMPONENT + ".2.count")).isEqualTo("9");
assertThat(underTest.getFieldValue(COMPONENT + ".3.label")).isEqualTo(file3.name());
assertThat(underTest.getFieldValue(COMPONENT + ".3.count")).isEqualTo("8");
assertThat(underTest.getFieldValue(COMPONENT + ".4.label")).isEqualTo(file4.name());
assertThat(underTest.getFieldValue(COMPONENT + ".4.count")).isEqualTo("7");
assertThat(underTest.getFieldValue(COMPONENT + ".5.label")).isEqualTo(file5.name());
assertThat(underTest.getFieldValue(COMPONENT + ".5.count")).isEqualTo("6");
assertThat(underTest.getFieldValue(COMPONENT + ".6.label")).isNull();
assertThat(underTest.getFieldValue(COMPONENT + ".6.count")).isNull();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class NewIssuesNotificationTest method set_statistics_when_no_issues_created_on_current_analysis.
@Test
public void set_statistics_when_no_issues_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 -> false);
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("0");
assertThat(underTest.getFieldValue(ASSIGNEE + ".1.label")).isNull();
assertThat(underTest.getFieldValue(ASSIGNEE + ".1.count")).isNull();
assertThat(underTest.getFieldValue(ASSIGNEE + ".2.label")).isNull();
assertThat(underTest.getFieldValue(ASSIGNEE + ".2.count")).isNull();
assertThat(underTest.getFieldValue(TAG + ".1.label")).isNull();
assertThat(underTest.getFieldValue(TAG + ".1.count")).isNull();
assertThat(underTest.getFieldValue(TAG + ".2.label")).isNull();
assertThat(underTest.getFieldValue(TAG + ".2.count")).isNull();
assertThat(underTest.getFieldValue(COMPONENT + ".1.label")).isNull();
assertThat(underTest.getFieldValue(COMPONENT + ".1.count")).isNull();
assertThat(underTest.getFieldValue(COMPONENT + ".2.label")).isNull();
assertThat(underTest.getFieldValue(COMPONENT + ".2.count")).isNull();
assertThat(underTest.getFieldValue(RULE + ".1.label")).isNull();
assertThat(underTest.getFieldValue(RULE + ".1.count")).isNull();
assertThat(underTest.getFieldValue(RULE + ".2.label")).isNull();
assertThat(underTest.getFieldValue(RULE + ".2.count")).isNull();
assertThat(underTest.getDefaultMessage()).startsWith("0 new issues on " + project.longName());
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class NewIssuesNotificationTest method set_statistics.
@Test
public void set_statistics() {
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 -> true);
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("5");
assertThat(underTest.getFieldValue(RULE_TYPE + ".CODE_SMELL.count")).isEqualTo("3");
assertThat(underTest.getFieldValue(ASSIGNEE + ".1.label")).isEqualTo(maynard.getName());
assertThat(underTest.getFieldValue(ASSIGNEE + ".1.count")).isEqualTo("5");
assertThat(underTest.getFieldValue(ASSIGNEE + ".2.label")).isEqualTo(keenan.getName());
assertThat(underTest.getFieldValue(ASSIGNEE + ".2.count")).isEqualTo("3");
assertThat(underTest.getFieldValue(TAG + ".1.label")).isEqualTo("owasp");
assertThat(underTest.getFieldValue(TAG + ".1.count")).isEqualTo("8");
assertThat(underTest.getFieldValue(TAG + ".2.label")).isEqualTo("bug");
assertThat(underTest.getFieldValue(TAG + ".2.count")).isEqualTo("5");
assertThat(underTest.getFieldValue(COMPONENT + ".1.label")).isEqualTo(file.name());
assertThat(underTest.getFieldValue(COMPONENT + ".1.count")).isEqualTo("5");
assertThat(underTest.getFieldValue(COMPONENT + ".2.label")).isEqualTo(directory.name());
assertThat(underTest.getFieldValue(COMPONENT + ".2.count")).isEqualTo("3");
assertThat(underTest.getFieldValue(RULE + ".1.label")).isEqualTo("Rule the World (Java)");
assertThat(underTest.getFieldValue(RULE + ".1.count")).isEqualTo("5");
assertThat(underTest.getFieldValue(RULE + ".2.label")).isEqualTo("Rule the Universe (Clojure)");
assertThat(underTest.getFieldValue(RULE + ".2.count")).isEqualTo("3");
assertThat(underTest.getDefaultMessage()).startsWith("8 new issues on " + project.longName());
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIndexerTest method index_issue_in_non_main_branch.
@Test
public void index_issue_in_non_main_branch() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo"));
ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(branch, "src/main/java/foo"));
ComponentDto file = db.components().insertComponent(newFileDto(branch, dir, "F1"));
IssueDto issue = db.issues().insert(rule, branch, file);
underTest.indexAllIssues();
IssueDoc doc = es.getDocuments(TYPE_ISSUE, IssueDoc.class).get(0);
assertThat(doc.getId()).isEqualTo(issue.getKey());
assertThat(doc.componentUuid()).isEqualTo(file.uuid());
assertThat(doc.projectUuid()).isEqualTo(branch.getMainBranchProjectUuid());
assertThat(doc.branchUuid()).isEqualTo(branch.uuid());
assertThat(doc.isMainBranch()).isFalse();
assertThat(doc.scope()).isEqualTo(IssueScope.MAIN);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIndexerTest method issue_on_directory_has_main_code_scope.
@Test
public void issue_on_directory_has_main_code_scope() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo"));
IssueDto issue = db.issues().insert(rule, project, dir);
underTest.indexAllIssues();
IssueDoc doc = es.getDocuments(TYPE_ISSUE, IssueDoc.class).get(0);
assertThat(doc.getId()).isEqualTo(issue.getKey());
assertThat(doc.componentUuid()).isEqualTo(dir.uuid());
assertThat(doc.scope()).isEqualTo(IssueScope.MAIN);
}
Aggregations