Search in sources :

Example 6 with SearchEventsWsResponse

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

the class SearchEventsActionQualityGateTest method does_not_return_quality_gate_events_on_pull_request.

@Test
public void does_not_return_quality_gate_events_on_pull_request() {
    userSession.logIn().setRoot();
    when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
    SnapshotDto prAnalysis = insertSuccessfulActivity(pr, 1_500_000_000_000L);
    insertActivity(pr, prAnalysis, CeActivityDto.Status.SUCCESS);
    db.events().insertEvent(newQualityGateEvent(prAnalysis).setDate(prAnalysis.getCreatedAt()).setName("Failed"));
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(prAnalysis.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) Test(org.junit.Test)

Example 7 with SearchEventsWsResponse

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

the class SearchEventsActionQualityGateTest method filter_by_from_date_inclusive.

@Test
public void filter_by_from_date_inclusive() {
    userSession.logIn().setRoot();
    ComponentDto project1 = db.components().insertPrivateProject();
    ComponentDto project2 = db.components().insertPrivateProject();
    ComponentDto project3 = db.components().insertPrivateProject();
    long from1 = 1_500_000_000_000L;
    long from2 = 1_400_000_000_000L;
    long from3 = 1_300_000_000_000L;
    SnapshotDto a1 = insertSuccessfulActivity(project1, from1 - 1L);
    db.events().insertEvent(newQualityGateEvent(a1).setDate(a1.getCreatedAt()));
    SnapshotDto a2 = insertSuccessfulActivity(project2, from2);
    db.events().insertEvent(newQualityGateEvent(a2).setDate(from2));
    SnapshotDto a3 = insertSuccessfulActivity(project3, from3 + 1L);
    db.events().insertEvent(newQualityGateEvent(a3).setDate(from3 + 1L));
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, join(",", project1.getKey(), project2.getKey(), project3.getKey())).setParam(PARAM_FROM, join(",", formatDateTime(from1 - 1_000L), formatDateTime(from2 - 1_000L), formatDateTime(from3 - 1_000L))).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getProject).containsExactlyInAnyOrder(project2.getKey(), project3.getKey());
}
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 8 with SearchEventsWsResponse

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

the class SearchEventsActionQualityGateTest method branch_quality_gate_events.

@Test
public void branch_quality_gate_events() {
    userSession.logIn().setRoot();
    when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
    SnapshotDto projectAnalysis = insertSuccessfulActivity(project, 1_500_000_000_000L);
    SnapshotDto branchAnalysis = insertSuccessfulActivity(branch, 1_500_000_000_000L);
    insertActivity(branch, branchAnalysis, CeActivityDto.Status.SUCCESS);
    db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(branchAnalysis.getCreatedAt() - 1_000L)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getCategory, Event::getProject, Event::getMessage, Event::getLink).containsOnly(tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", project.name(), branch.getBranch()), format("https://sonarcloud.io/dashboard?id=%s&branch=%s", project.getKey(), branch.getBranch())));
}
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 9 with SearchEventsWsResponse

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

the class SearchEventsActionNewIssuesTest method return_link_to_issue_search_for_new_issues_event.

@Test
public void return_link_to_issue_search_for_new_issues_event() {
    userSession.logIn("my_login").setRoot();
    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("my_project"));
    SnapshotDto analysis = insertAnalysis(project, 1_400_000_000_000L);
    insertIssue(project, analysis);
    issueIndexer.indexAllIssues();
    when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(analysis.getCreatedAt() - 1_000L)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getLink).containsExactly("https://sonarcloud.io/project/issues?id=my_project&createdAfter=" + encode(formatDateTime(analysis.getCreatedAt())) + "&assignees=my_login&resolved=false");
}
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 10 with SearchEventsWsResponse

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

the class SearchEventsActionQualityGateTest method quality_gate_events.

@Test
public void quality_gate_events() {
    userSession.logIn().setRoot();
    when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
    ComponentDto project = db.components().insertPrivateProject();
    SnapshotDto projectAnalysis = insertSuccessfulActivity(project, 1_500_000_000_000L);
    db.events().insertEvent(newQualityGateEvent(projectAnalysis).setDate(projectAnalysis.getCreatedAt()).setName("Failed"));
    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("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' changed to 'Failed'", project.name()), format("https://sonarcloud.io/dashboard?id=%s", project.getKey()), formatDateTime(projectAnalysis.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