use of org.sonar.db.issue.IssueDto 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.issue.IssueDto in project sonarqube by SonarSource.
the class IssueIndexerTest method index_is_not_updated_when_updating_tags.
@Test
public void index_is_not_updated_when_updating_tags() {
// issue is inserted to verify that indexing of project is not triggered
IssueDto issue = db.issues().insert();
IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_TAGS_UPDATE);
assertThat(result.getTotal()).isZero();
assertThatIndexHasSize(0);
}
use of org.sonar.db.issue.IssueDto 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.issue.IssueDto 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);
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class IssueIndexerTest method index_is_not_updated_when_updating_project_key.
@Test
public void index_is_not_updated_when_updating_project_key() {
// issue is inserted to verify that indexing of project is not triggered
IssueDto issue = db.issues().insert();
IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE);
assertThat(result.getTotal()).isZero();
assertThatIndexHasSize(0);
}
Aggregations