Search in sources :

Example 21 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class SetTypeActionTest method newIssue.

private IssueDto newIssue() {
    RuleDto rule = db.rules().insertRule(newRuleDto());
    ComponentDto project = db.components().insertProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    return newDto(rule, file, project);
}
Also used : RuleTesting.newRuleDto(org.sonar.db.rule.RuleTesting.newRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 22 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class IssueFinderTest method insertIssue.

private IssueDto insertIssue() {
    RuleDto rule = ruleDbTester.insertRule(newRuleDto());
    ComponentDto project = componentDbTester.insertProject();
    ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
    return issueDbTester.insertIssue(newDto(rule, file, project));
}
Also used : RuleTesting.newRuleDto(org.sonar.db.rule.RuleTesting.newRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 23 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class IssueServiceMediumTest method assign.

@Test
public void assign() {
    RuleDto rule = newRule();
    ComponentDto project = newProject();
    ComponentDto file = newFile(project);
    userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
    IssueDto issue = saveIssue(IssueTesting.newDto(rule, file, project));
    UserDto user = new UserDto().setLogin("perceval").setName("Perceval");
    db.userDao().insert(session, user);
    session.commit();
    index();
    assertThat(getIssueByKey(issue.getKey()).assignee()).isNull();
    service.assign(issue.getKey(), user.getLogin());
    assertThat(getIssueByKey(issue.getKey()).assignee()).isEqualTo("perceval");
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 24 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class IssueServiceMediumTest method list_component_tags.

@Test
public void list_component_tags() {
    RuleDto rule = newRule();
    ComponentDto project = newProject();
    ComponentDto file = newFile(project);
    saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention", "java8", "bug")));
    saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention", "bug")));
    saveIssue(IssueTesting.newDto(rule, file, project));
    saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED));
    saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention")));
    assertThat(service.listTagsForComponent(projectQuery(project.uuid()), 5)).containsOnly(entry("convention", 3L), entry("bug", 2L), entry("java8", 1L));
    assertThat(service.listTagsForComponent(projectQuery(project.uuid()), 2)).contains(entry("convention", 3L), entry("bug", 2L)).doesNotContainEntry("java8", 1L);
    assertThat(service.listTagsForComponent(projectQuery("other"), 10)).isEmpty();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 25 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class IssueServiceMediumTest method set_tags.

@Test
public void set_tags() {
    RuleDto rule = newRule();
    ComponentDto project = newProject();
    ComponentDto file = newFile(project);
    userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
    IssueDto issue = saveIssue(IssueTesting.newDto(rule, file, project));
    assertThat(getIssueByKey(issue.getKey()).tags()).isEmpty();
    // Tags are lowercased
    service.setTags(issue.getKey(), ImmutableSet.of("bug", "Convention"));
    assertThat(getIssueByKey(issue.getKey()).tags()).containsOnly("bug", "convention");
    // nulls and empty tags are ignored
    service.setTags(issue.getKey(), Sets.newHashSet("security", null, "", "convention"));
    assertThat(getIssueByKey(issue.getKey()).tags()).containsOnly("security", "convention");
    // tag validation
    try {
        service.setTags(issue.getKey(), ImmutableSet.of("pol op"));
    } catch (Exception exception) {
        assertThat(exception).isInstanceOf(IllegalArgumentException.class);
    }
    assertThat(getIssueByKey(issue.getKey()).tags()).containsOnly("security", "convention");
    // unchanged tags
    service.setTags(issue.getKey(), ImmutableSet.of("convention", "security"));
    assertThat(getIssueByKey(issue.getKey()).tags()).containsOnly("security", "convention");
    service.setTags(issue.getKey(), ImmutableSet.<String>of());
    assertThat(getIssueByKey(issue.getKey()).tags()).isEmpty();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) Test(org.junit.Test)

Aggregations

RuleDto (org.sonar.db.rule.RuleDto)197 Test (org.junit.Test)140 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)80 ComponentDto (org.sonar.db.component.ComponentDto)47 WsTester (org.sonar.server.ws.WsTester)38 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)29 RuleParamDto (org.sonar.db.rule.RuleParamDto)29 IssueDto (org.sonar.db.issue.IssueDto)28 RuleKey (org.sonar.api.rule.RuleKey)24 SearchOptions (org.sonar.server.es.SearchOptions)16 RuleQuery (org.sonar.server.rule.index.RuleQuery)16 BadRequestException (org.sonar.server.exceptions.BadRequestException)15 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)12 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)10 Date (java.util.Date)9 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)8 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)8 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)7 ArrayList (java.util.ArrayList)6