Search in sources :

Example 11 with SearchEventsWsResponse

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

the class SearchEventsActionQualityGateTest method encode_link.

@Test
public void encode_link() {
    userSession.logIn().setRoot();
    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("M&M's"));
    SnapshotDto analysis = insertSuccessfulActivity(project, 1_500_000_000_000L);
    EventDto event = db.events().insertEvent(newQualityGateEvent(analysis).setName("Failed").setDate(analysis.getCreatedAt()));
    when(server.getPublicRootUrl()).thenReturn("http://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("http://sonarcloud.io/dashboard?id=M%26M%27s");
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Test(org.junit.Test)

Example 12 with SearchEventsWsResponse

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

the class SearchEventsActionQualityGateTest method return_link_to_dashboard_for_quality_gate_event.

@Test
public void return_link_to_dashboard_for_quality_gate_event() {
    userSession.logIn().setRoot();
    ComponentDto project = db.components().insertPrivateProject();
    SnapshotDto analysis = insertSuccessfulActivity(project, 1_500_000_000_000L);
    EventDto e1 = db.events().insertEvent(newQualityGateEvent(analysis).setName("Failed").setDate(analysis.getCreatedAt()));
    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/dashboard?id=" + project.getKey());
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Test(org.junit.Test)

Example 13 with SearchEventsWsResponse

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

the class SearchEventsActionQualityGateTest method return_one_quality_gate_change_per_project.

@Test
public void return_one_quality_gate_change_per_project() {
    userSession.logIn().setRoot();
    ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("p1"));
    ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("p2"));
    long from = 1_500_000_000_000L;
    SnapshotDto a11 = insertSuccessfulActivity(project1, from);
    SnapshotDto a12 = insertSuccessfulActivity(project1, from + 1L);
    SnapshotDto a21 = insertSuccessfulActivity(project2, from);
    SnapshotDto a22 = insertSuccessfulActivity(project2, from + 1L);
    EventDto e11 = db.events().insertEvent(newQualityGateEvent(a11).setName("e11").setDate(from));
    EventDto e12 = db.events().insertEvent(newQualityGateEvent(a12).setName("e12").setDate(from + 1L));
    EventDto e21 = db.events().insertEvent(newQualityGateEvent(a21).setName("e21").setDate(from));
    EventDto e22 = db.events().insertEvent(newQualityGateEvent(a22).setName("e22").setDate(from + 1L));
    String fromDate = formatDateTime(from - 1_000L);
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, join(",", project1.getKey(), project2.getKey())).setParam(PARAM_FROM, join(",", fromDate, fromDate)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getProject, Event::getMessage).containsExactlyInAnyOrder(tuple(project1.getKey(), "Quality Gate status of project 'p1' changed to 'e12'"), tuple(project2.getKey(), "Quality Gate status of project 'p2' changed to 'e22'"));
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Test(org.junit.Test)

Example 14 with SearchEventsWsResponse

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

the class SearchEventsActionQualityGateTest method return_only_latest_quality_gate_event.

@Test
public void return_only_latest_quality_gate_event() {
    userSession.logIn().setRoot();
    ComponentDto project = db.components().insertPrivateProject(p -> p.setName("My Project"));
    SnapshotDto a1 = insertSuccessfulActivity(project, 1_500_000_000_000L);
    EventDto e1 = db.events().insertEvent(newQualityGateEvent(a1).setName("Failed").setDate(a1.getCreatedAt()));
    SnapshotDto a2 = insertSuccessfulActivity(project, 1_500_000_000_001L);
    EventDto e2 = db.events().insertEvent(newQualityGateEvent(a2).setName("Passed").setDate(a2.getCreatedAt() + 1L));
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(a1.getCreatedAt() - 1_000L)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getMessage).containsExactly("Quality Gate status of project 'My Project' changed to 'Passed'");
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Test(org.junit.Test)

Example 15 with SearchEventsWsResponse

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

the class SearchEventsActionQualityGateTest method filter_quality_gate_event.

@Test
public void filter_quality_gate_event() {
    userSession.logIn().setRoot();
    ComponentDto project = db.components().insertPrivateProject();
    SnapshotDto analysis = insertSuccessfulActivity(project, 1_500_000_000_000L);
    EventDto qualityGateEvent = db.events().insertEvent(newQualityGateEvent(analysis).setDate(analysis.getCreatedAt()));
    EventDto versionEvent = db.events().insertEvent(newEvent(analysis).setCategory(EventCategory.VERSION.getLabel()).setDate(analysis.getCreatedAt()));
    EventDto qualityProfileEvent = db.events().insertEvent(newEvent(analysis).setCategory(EventCategory.QUALITY_PROFILE.getLabel()).setDate(analysis.getCreatedAt()));
    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::getCategory).containsExactly("QUALITY_GATE");
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) 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