Search in sources :

Example 16 with SearchEventsWsResponse

use of org.sonarqube.ws.Developers.SearchEventsWsResponse in project sonarqube by SonarSource.

the class SearchEventsActionNewIssuesTest method pull_request_issues_events.

@Test
public void pull_request_issues_events() {
    userSession.logIn().setRoot();
    when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto nonMainBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("nonMain"));
    SnapshotDto nonMainBranchAnalysis = insertAnalysis(nonMainBranch, 1_500_000_000_000L);
    insertIssue(nonMainBranch, nonMainBranchAnalysis);
    insertIssue(nonMainBranch, nonMainBranchAnalysis);
    ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey("42"));
    SnapshotDto pullRequestAnalysis = insertAnalysis(pullRequest, 1_300_000_000_000L);
    insertIssue(pullRequest, pullRequestAnalysis);
    issueIndexer.indexAllIssues();
    long from = 1_000_000_000_000L;
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(from)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getCategory, Event::getProject, Event::getMessage, Event::getLink, Event::getDate).containsOnly(tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s' on branch '%s'", project.name(), nonMainBranch.getBranch()), format("https://sonarcloud.io/project/issues?id=%s&createdAfter=%s&assignees=%s&resolved=false&branch=%s", nonMainBranch.getKey(), encode(formatDateTime(from + 1_000L)), userSession.getLogin(), nonMainBranch.getBranch()), formatDateTime(nonMainBranchAnalysis.getCreatedAt())), tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on pull request '%s'", project.name(), pullRequest.getPullRequest()), format("https://sonarcloud.io/project/issues?id=%s&createdAfter=%s&assignees=%s&resolved=false&pullRequest=%s", pullRequest.getKey(), encode(formatDateTime(from + 1_000L)), userSession.getLogin(), pullRequest.getPullRequest()), formatDateTime(pullRequestAnalysis.getCreatedAt())));
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Test(org.junit.Test)

Example 17 with SearchEventsWsResponse

use of org.sonarqube.ws.Developers.SearchEventsWsResponse in project sonarqube by SonarSource.

the class SearchEventsActionNewIssuesTest method does_not_return_old_issue.

@Test
public void does_not_return_old_issue() {
    userSession.logIn().setRoot();
    ComponentDto project = db.components().insertPrivateProject();
    SnapshotDto analysis = insertAnalysis(project, 1_500_000_000_000L);
    db.issues().insert(db.rules().insert(), project, project, i -> i.setIssueCreationDate(new Date(analysis.getCreatedAt() - 10_000L)));
    issueIndexer.indexAllIssues();
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(analysis.getCreatedAt() - 1_000L)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).isEmpty();
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Date(java.util.Date) Test(org.junit.Test)

Example 18 with SearchEventsWsResponse

use of org.sonarqube.ws.Developers.SearchEventsWsResponse in project sonarqube by SonarSource.

the class SearchEventsActionTest method empty_response_if_project_key_is_unknown.

@Test
public void empty_response_if_project_key_is_unknown() {
    userSession.logIn().setRoot();
    long from = 1_500_000_000_000L;
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, "unknown").setParam(PARAM_FROM, formatDateTime(from - 1_000L)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).isEmpty();
}
Also used : SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Test(org.junit.Test)

Example 19 with SearchEventsWsResponse

use of org.sonarqube.ws.Developers.SearchEventsWsResponse in project sonarqube by SonarSource.

the class SearchEventsActionNewIssuesTest method many_issues_events.

@Test
public void many_issues_events() {
    userSession.logIn().setRoot();
    long from = 1_500_000_000_000L;
    ComponentDto project = db.components().insertPrivateProject(p -> p.setName("SonarQube"));
    SnapshotDto analysis = insertAnalysis(project, from);
    insertIssue(project, analysis);
    insertIssue(project, analysis);
    issueIndexer.indexAllIssues();
    String fromDate = formatDateTime(from - 1_000L);
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, fromDate).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getCategory, Event::getMessage, Event::getProject, Event::getDate).containsExactly(tuple("NEW_ISSUES", "You have 2 new issues on project 'SonarQube'", project.getKey(), formatDateTime(from)));
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Test(org.junit.Test)

Example 20 with SearchEventsWsResponse

use of org.sonarqube.ws.Developers.SearchEventsWsResponse in project sonarqube by SonarSource.

the class SearchEventsActionNewIssuesTest method branch_issues_events.

@Test
public void branch_issues_events() {
    userSession.logIn().setRoot();
    when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("branch1"));
    SnapshotDto branch1Analysis = insertAnalysis(branch1, 1_500_000_000_000L);
    insertIssue(branch1, branch1Analysis);
    insertIssue(branch1, branch1Analysis);
    ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setKey("branch"));
    SnapshotDto branch2Analysis = insertAnalysis(branch2, 1_300_000_000_000L);
    insertIssue(branch2, branch2Analysis);
    issueIndexer.indexAllIssues();
    long from = 1_000_000_000_000L;
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(from)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getCategory, Event::getProject, Event::getMessage, Event::getLink, Event::getDate).containsOnly(tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s' on branch '%s'", project.name(), branch1.getBranch()), format("https://sonarcloud.io/project/issues?id=%s&createdAfter=%s&assignees=%s&resolved=false&branch=%s", branch1.getKey(), encode(formatDateTime(from + 1_000L)), userSession.getLogin(), branch1.getBranch()), formatDateTime(branch1Analysis.getCreatedAt())), tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", project.name(), branch2.getBranch()), format("https://sonarcloud.io/project/issues?id=%s&createdAfter=%s&assignees=%s&resolved=false&branch=%s", branch2.getKey(), encode(formatDateTime(from + 1_000L)), userSession.getLogin(), branch2.getBranch()), formatDateTime(branch2Analysis.getCreatedAt())));
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 SearchEventsWsResponse (org.sonarqube.ws.Developers.SearchEventsWsResponse)21 ComponentDto (org.sonar.db.component.ComponentDto)19 SnapshotDto (org.sonar.db.component.SnapshotDto)19 EventDto (org.sonar.db.event.EventDto)7 Date (java.util.Date)2 String.format (java.lang.String.format)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)1 RandomUtils.nextInt (org.apache.commons.lang.math.RandomUtils.nextInt)1 RandomUtils.nextLong (org.apache.commons.lang.math.RandomUtils.nextLong)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Rule (org.junit.Rule)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1