Search in sources :

Example 21 with IssueDto

use of org.sonar.db.issue.IssueDto 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 22 with IssueDto

use of org.sonar.db.issue.IssueDto 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)

Example 23 with IssueDto

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

the class TransitionServiceTest method list_transitions.

@Test
public void list_transitions() throws Exception {
    IssueDto issue = newIssue().setStatus(STATUS_OPEN).setResolution(null);
    userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.getProjectUuid());
    List<Transition> result = underTest.listTransitions(issue.toDefaultIssue());
    assertThat(result).extracting(Transition::key).containsOnly("confirm", "resolve", "falsepositive", "wontfix");
}
Also used : Transition(org.sonar.server.issue.workflow.Transition) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 24 with IssueDto

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

the class SearchActionComponentsMediumTest method search_by_directory_path.

@Test
public void search_by_directory_path() throws Exception {
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
    setDefaultProjectPermission(project);
    ComponentDto directory = insertComponent(ComponentTesting.newDirectory(project, "D1", "src/main/java/dir"));
    ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1").setPath(directory.path() + "/MyComponent.java"));
    IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
    db.issueDao().insert(session, issue);
    session.commit();
    indexIssues();
    wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, directory.uuid()).execute().assertJson(this.getClass(), "search_by_file_uuid.json");
    wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, "unknown").execute().assertJson(this.getClass(), "no_issue.json");
    wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam(IssuesWsParameters.PARAM_DIRECTORIES, "src/main/java/dir").execute().assertJson(this.getClass(), "search_by_file_uuid.json");
    wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam(IssuesWsParameters.PARAM_DIRECTORIES, "src/main/java").execute().assertJson(this.getClass(), "no_issue.json");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 25 with IssueDto

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

the class SearchActionComponentsMediumTest method search_by_developer.

@Test
public void search_by_developer() throws Exception {
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
    setDefaultProjectPermission(project);
    ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
    ComponentDto developer = insertComponent(ComponentTesting.newDeveloper(otherOrganization1, "Anakin Skywalker"));
    db.authorDao().insertAuthor(session, "vader", developer.getId());
    db.authorDao().insertAuthor(session, "anakin@skywalker.name", developer.getId());
    RuleDto newRule = newRule();
    IssueDto issue1 = IssueTesting.newDto(newRule, file, project).setAuthorLogin("vader").setKee("2bd4eac2-b650-4037-80bc-7b112bd4eac2");
    IssueDto issue2 = IssueTesting.newDto(newRule, file, project).setAuthorLogin("anakin@skywalker.name").setKee("82fd47d4-b650-4037-80bc-7b1182fd47d4");
    db.issueDao().insert(session, issue1, issue2);
    session.commit();
    indexIssues();
    wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, developer.uuid()).execute().assertJson(this.getClass(), "search_by_developer.json");
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Aggregations

IssueDto (org.sonar.db.issue.IssueDto)134 Test (org.junit.Test)117 ComponentDto (org.sonar.db.component.ComponentDto)48 RuleDto (org.sonar.db.rule.RuleDto)28 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)19 UserDto (org.sonar.db.user.UserDto)18 WsTester (org.sonar.server.ws.WsTester)18 IssueChangeDto (org.sonar.db.issue.IssueChangeDto)15 FieldDiffs (org.sonar.core.issue.FieldDiffs)14 BulkChangeWsResponse (org.sonarqube.ws.Issues.BulkChangeWsResponse)14 ChangelogWsResponse (org.sonarqube.ws.Issues.ChangelogWsResponse)12 TestResponse (org.sonar.server.ws.TestResponse)9 Request (org.sonar.api.server.ws.Request)8 Response (org.sonar.api.server.ws.Response)8 DefaultIssue (org.sonar.core.issue.DefaultIssue)8 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)8 TestRequest (org.sonar.server.ws.TestRequest)8 Date (java.util.Date)6 DbSession (org.sonar.db.DbSession)5 IssueDao (org.sonar.db.issue.IssueDao)4