Search in sources :

Example 91 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class IssuesActionTest method return_issues_of_file.

@Test
public void return_issues_of_file() {
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto module = db.components().insertComponent(newModuleDto(project));
    ComponentDto file = db.components().insertComponent(newFileDto(module, null));
    IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setType(randomRuleTypeExceptHotspot()));
    IssueDto issueOnModule = db.issues().insert(rule, project, module, i -> i.setType(randomRuleTypeExceptHotspot()));
    IssueDto issueOnProject = db.issues().insert(rule, project, project, i -> i.setType(randomRuleTypeExceptHotspot()));
    addPermissionTo(project);
    try (CloseableIterator<ServerIssue> result = callStream(file.getKey(), null)) {
        assertThat(result).toIterable().extracting(ServerIssue::getKey, ServerIssue::getModuleKey).containsExactlyInAnyOrder(tuple(issueOnFile.getKey(), module.getKey()));
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue) Test(org.junit.Test)

Example 92 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class IssuesActionTest method does_not_return_issues_from_external_rules.

@Test
public void does_not_return_issues_from_external_rules() {
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto module = db.components().insertComponent(newModuleDto(project));
    ComponentDto file = db.components().insertComponent(newFileDto(module, null));
    IssueDto issueOnProject = db.issues().insert(rule, project, project, i -> i.setKee("ON_PROJECT").setType(randomRuleTypeExceptHotspot()));
    IssueDto issueOnModule = db.issues().insert(rule, project, module, i -> i.setKee("ON_MODULE").setType(randomRuleTypeExceptHotspot()));
    IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setKee("ON_FILE").setType(randomRuleTypeExceptHotspot()));
    RuleDefinitionDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true));
    IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL").setType(randomRuleTypeExceptHotspot()));
    RuleDefinitionDto migrated = db.rules().insert();
    db.executeUpdateSql("update rules set is_external=? where rules.uuid = ?", false, migrated.getUuid());
    IssueDto issueFromMigratedRule = db.issues().insert(migrated, project, file, i -> i.setKee("MIGRATED").setType(randomRuleTypeExceptHotspot()));
    addPermissionTo(project);
    try (CloseableIterator<ServerIssue> result = callStream(project.getKey(), null)) {
        assertThat(result).toIterable().extracting(ServerIssue::getKey, ServerIssue::getModuleKey).containsExactlyInAnyOrder(tuple(issueOnFile.getKey(), module.getKey()), tuple(issueOnModule.getKey(), module.getKey()), tuple(issueOnProject.getKey(), project.getKey()), tuple(issueFromMigratedRule.getKey(), module.getKey()));
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue) Test(org.junit.Test)

Example 93 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class IssuesActionTest method return_issues_by_module_and_branch.

@Test
public void return_issues_by_module_and_branch() {
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPrivateProject();
    addPermissionTo(project);
    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
    ComponentDto module = db.components().insertComponent(newModuleDto(branch));
    ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
    ComponentDto file = db.components().insertComponent(newFileDto(subModule));
    IssueDto issueOnFile = db.issues().insert(rule, branch, file, i -> i.setType(randomRuleTypeExceptHotspot()));
    IssueDto issueOnSubModule = db.issues().insert(rule, branch, subModule, i -> i.setType(randomRuleTypeExceptHotspot()));
    IssueDto issueOnModule = db.issues().insert(rule, branch, module, i -> i.setType(randomRuleTypeExceptHotspot()));
    assertResult(module.getKey(), "my_branch", tuple(issueOnFile.getKey(), subModule.getKey()), tuple(issueOnSubModule.getKey(), subModule.getKey()), tuple(issueOnModule.getKey(), module.getKey()));
}
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 94 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class IssuesActionTest method test_nullable_fields.

@Test
public void test_nullable_fields() throws Exception {
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto module = db.components().insertComponent(newModuleDto(project));
    ComponentDto file = db.components().insertComponent(newFileDto(module, null).setPath(null));
    IssueDto issue = db.issues().insert(rule, project, file, i -> i.setSeverity("BLOCKER").setStatus("OPEN").setType(BUG).setManualSeverity(true).setResolution(null).setMessage(null).setLine(null).setChecksum(null).setAssigneeUuid(null));
    addPermissionTo(project);
    ServerIssue serverIssue = call(project.getKey());
    assertThat(serverIssue.getKey()).isEqualTo(issue.getKey());
    assertThat(serverIssue.getModuleKey()).isEqualTo(module.getKey());
    assertThat(serverIssue.getRuleRepository()).isEqualTo(rule.getRepositoryKey());
    assertThat(serverIssue.getRuleKey()).isEqualTo(rule.getRuleKey());
    assertThat(serverIssue.getStatus()).isEqualTo("OPEN");
    assertThat(serverIssue.getSeverity()).isEqualTo(Severity.BLOCKER);
    assertThat(serverIssue.getType()).isEqualTo(BUG.name());
    assertThat(serverIssue.getManualSeverity()).isTrue();
    assertThat(serverIssue.hasPath()).isFalse();
    assertThat(serverIssue.hasLine()).isFalse();
    assertThat(serverIssue.hasMsg()).isFalse();
    assertThat(serverIssue.hasResolution()).isFalse();
    assertThat(serverIssue.hasChecksum()).isFalse();
    assertThat(serverIssue.hasAssigneeLogin()).isFalse();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue) Test(org.junit.Test)

Example 95 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class IssuesActionTest method return_issues_of_project.

@Test
public void return_issues_of_project() {
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto module = db.components().insertComponent(newModuleDto(project));
    ComponentDto file = db.components().insertComponent(newFileDto(module, null));
    IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setKee("ON_FILE").setType(randomRuleTypeExceptHotspot()));
    IssueDto issueOnModule = db.issues().insert(rule, project, module, i -> i.setKee("ON_MODULE").setType(randomRuleTypeExceptHotspot()));
    IssueDto issueOnProject = db.issues().insert(rule, project, project, i -> i.setKee("ON_PROJECT").setType(randomRuleTypeExceptHotspot()));
    addPermissionTo(project);
    try (CloseableIterator<ServerIssue> result = callStream(project.getKey(), null)) {
        assertThat(result).toIterable().extracting(ServerIssue::getKey, ServerIssue::getModuleKey).containsExactlyInAnyOrder(tuple(issueOnFile.getKey(), module.getKey()), tuple(issueOnModule.getKey(), module.getKey()), tuple(issueOnProject.getKey(), project.getKey()));
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue) 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