use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class ComponentDaoTest method selectComponentsFromBranchesThatHaveOpenIssues_returns_nothing_if_no_open_issues_in_sibling_branches.
@Test
public void selectComponentsFromBranchesThatHaveOpenIssues_returns_nothing_if_no_open_issues_in_sibling_branches() {
final ProjectDto project = db.components().insertPrivateProjectDto(b -> b.setName("foo"));
ComponentDto branch1 = db.components().insertProjectBranch(project, ComponentTesting.newBranchDto(project.getUuid(), BRANCH).setKey("branch1"));
ComponentDto fileBranch1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1));
RuleDefinitionDto rule = db.rules().insert();
db.issues().insert(new IssueDto().setKee("i").setComponent(fileBranch1).setProject(branch1).setRule(rule).setStatus(STATUS_CLOSED));
List<KeyWithUuidDto> result = underTest.selectComponentsFromBranchesThatHaveOpenIssues(db.getSession(), singleton(branch1.uuid()));
assertThat(result).isEmpty();
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class PurgeCommandsTest method deleteIssues_deletes_issue_changes.
@Test
@UseDataProvider("projectsAndViews")
public void deleteIssues_deletes_issue_changes(ComponentDto projectOrView) {
RuleDefinitionDto rule = dbTester.rules().insert();
dbTester.components().insertComponent(projectOrView);
ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView));
int count = 5;
IntStream.range(0, count).forEach(i -> {
IssueDto issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(projectOrView));
dbTester.issues().insertChange(issue);
issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(file));
dbTester.issues().insertChange(issue);
});
underTest.deleteIssues(projectOrView.uuid());
assertThat(dbTester.countRowsOfTable("ISSUE_CHANGES")).isZero();
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class PurgeCommandsTest method deleteIssues_deletes_new_code_reference_issues.
@Test
@UseDataProvider("projectsAndViews")
public void deleteIssues_deletes_new_code_reference_issues(ComponentDto projectOrView) {
RuleDefinitionDto rule = dbTester.rules().insert();
dbTester.components().insertComponent(projectOrView);
ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView));
List<String> issueKeys = new ArrayList<>();
int count = 5;
IntStream.range(0, count).forEach(i -> {
IssueDto issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(projectOrView));
dbTester.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue));
issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(file));
dbTester.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue));
issueKeys.add("'" + issue.getKey() + "'");
});
underTest.deleteIssues(projectOrView.uuid());
assertThat(dbTester.countSql("select count(uuid) from new_code_reference_issues where issue_key in (" + String.join(", ", issueKeys) + ")")).isZero();
}
use of org.sonar.db.issue.IssueDto 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());
}
use of org.sonar.db.issue.IssueDto 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());
}
Aggregations