Search in sources :

Example 56 with IssueDto

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());
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 57 with IssueDto

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);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 58 with IssueDto

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);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 59 with IssueDto

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);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 60 with IssueDto

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);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Aggregations

IssueDto (org.sonar.db.issue.IssueDto)478 Test (org.junit.Test)425 ComponentDto (org.sonar.db.component.ComponentDto)324 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)213 UserDto (org.sonar.db.user.UserDto)136 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)77 TestRequest (org.sonar.server.ws.TestRequest)66 Date (java.util.Date)60 Hotspots (org.sonarqube.ws.Hotspots)57 DefaultIssue (org.sonar.core.issue.DefaultIssue)55 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)53 NotFoundException (org.sonar.server.exceptions.NotFoundException)51 DbClient (org.sonar.db.DbClient)50 List (java.util.List)49 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)49 Rule (org.junit.Rule)49 System2 (org.sonar.api.utils.System2)49 DbTester (org.sonar.db.DbTester)49 RuleDto (org.sonar.db.rule.RuleDto)49 IntStream (java.util.stream.IntStream)48