Search in sources :

Example 1 with SearchEventsWsResponse

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

the class SearchEventsActionNewIssuesTest method encode_link.

@Test
public void encode_link() {
    userSession.logIn("rågnar").setRoot();
    long from = 1_500_000_000_000L;
    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("M&M's"));
    SnapshotDto analysis = insertAnalysis(project, from);
    insertIssue(project, analysis);
    issueIndexer.indexAllIssues();
    when(server.getPublicRootUrl()).thenReturn("http://sonarcloud.io");
    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::getLink).containsExactly("http://sonarcloud.io/project/issues?id=M%26M%27s&createdAfter=" + encode(formatDateTime(from)) + "&assignees=r%C3%A5gnar&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 2 with SearchEventsWsResponse

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

the class SearchEventsActionTest method does_not_return_events_of_project_for_which_the_current_user_has_no_browse_permission.

@Test
public void does_not_return_events_of_project_for_which_the_current_user_has_no_browse_permission() {
    userSession.logIn();
    ComponentDto project1 = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.CODEVIEWER, project1);
    userSession.addProjectPermission(UserRole.ISSUE_ADMIN, project1);
    ComponentDto project2 = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project2);
    SnapshotDto a1 = insertAnalysis(project1, 1_500_000_000_000L);
    EventDto e1 = db.events().insertEvent(newQualityGateEvent(a1).setDate(a1.getCreatedAt()));
    insertIssue(project1, a1);
    SnapshotDto a2 = insertAnalysis(project2, 1_500_000_000_000L);
    EventDto e2 = db.events().insertEvent(newQualityGateEvent(a2).setDate(a2.getCreatedAt()));
    insertIssue(project2, a2);
    issueIndexer.indexAllIssues();
    String stringFrom = formatDateTime(a1.getCreatedAt() - 1_000L);
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, String.join(",", project1.getKey(), project2.getKey())).setParam(PARAM_FROM, String.join(",", stringFrom, stringFrom)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getCategory, Event::getProject).containsOnly(tuple("NEW_ISSUES", project2.getKey()), tuple(EventCategory.QUALITY_GATE.name(), project2.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 3 with SearchEventsWsResponse

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

the class SearchEventsActionTest method empty_response_for_empty_list_of_projects.

@Test
public void empty_response_for_empty_list_of_projects() {
    userSession.logIn().setRoot();
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, "").setParam(PARAM_FROM, "").executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).isEmpty();
}
Also used : SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) Test(org.junit.Test)

Example 4 with SearchEventsWsResponse

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

the class SearchEventsActionTest method does_not_return_old_events.

@Test
public void does_not_return_old_events() {
    userSession.logIn().setRoot();
    ComponentDto project = db.components().insertPrivateProject();
    SnapshotDto analysis = insertAnalysis(project, 1_500_000_000_000L);
    insertIssue(project, analysis);
    db.events().insertEvent(newQualityGateEvent(analysis).setDate(analysis.getCreatedAt()).setName("Passed"));
    SnapshotDto oldAnalysis = insertAnalysis(project, 1_400_000_000_000L);
    insertIssue(project, oldAnalysis);
    db.events().insertEvent(newQualityGateEvent(oldAnalysis).setDate(oldAnalysis.getCreatedAt()).setName("Failed"));
    issueIndexer.indexAllIssues();
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(analysis.getCreatedAt() - 1450_000_000_000L)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getCategory, Event::getDate).containsOnly(tuple("NEW_ISSUES", formatDateTime(analysis.getCreatedAt())), tuple("QUALITY_GATE", formatDateTime(analysis.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 5 with SearchEventsWsResponse

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

the class SearchEventsActionTest method events.

@Test
public void events() {
    userSession.logIn().setRoot();
    when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto branch = db.components().insertProjectBranch(project);
    SnapshotDto projectAnalysis = insertAnalysis(project, 1_500_000_000_000L);
    db.events().insertEvent(newQualityGateEvent(projectAnalysis).setDate(projectAnalysis.getCreatedAt()).setName("Passed"));
    insertIssue(project, projectAnalysis);
    insertIssue(project, projectAnalysis);
    SnapshotDto branchAnalysis = insertAnalysis(branch, 1_501_000_000_000L);
    db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
    insertIssue(branch, branchAnalysis);
    issueIndexer.indexAllIssues();
    SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(1_499_000_000_000L)).executeProtobuf(SearchEventsWsResponse.class);
    assertThat(result.getEventsList()).extracting(Event::getCategory, Event::getProject, Event::getMessage).containsOnly(tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' changed to 'Passed'", project.name())), tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", project.name(), branch.getBranch())), tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s'", project.name())), tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", project.name(), branch.getBranch())));
    verify(issueIndexSyncProgressChecker).checkIfAnyComponentsNeedIssueSync(any(), argThat(arg -> arg.contains(project.getKey())));
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CeTaskTypes(org.sonar.db.ce.CeTaskTypes) EventCategory(org.sonar.server.projectanalysis.ws.EventCategory) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Date(java.util.Date) EsTester(org.sonar.server.es.EsTester) EventTesting.newEvent(org.sonar.db.event.EventTesting.newEvent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Server(org.sonar.api.platform.Server) RuleType(org.sonar.api.rules.RuleType) CeActivityDto(org.sonar.db.ce.CeActivityDto) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) RandomUtils.nextLong(org.apache.commons.lang.math.RandomUtils.nextLong) UserSessionRule(org.sonar.server.tester.UserSessionRule) PARAM_PROJECTS(org.sonar.server.developers.ws.SearchEventsAction.PARAM_PROJECTS) DbTester(org.sonar.db.DbTester) RandomUtils.nextInt(org.apache.commons.lang.math.RandomUtils.nextInt) Assertions.tuple(org.assertj.core.api.Assertions.tuple) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) KeyExamples(org.sonar.server.ws.KeyExamples) String.format(java.lang.String.format) Mockito.verify(org.mockito.Mockito.verify) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) UnauthorizedException(org.sonar.server.exceptions.UnauthorizedException) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) CeQueueDto(org.sonar.db.ce.CeQueueDto) PARAM_FROM(org.sonar.server.developers.ws.SearchEventsAction.PARAM_FROM) SnapshotDto(org.sonar.db.component.SnapshotDto) SearchEventsWsResponse(org.sonarqube.ws.Developers.SearchEventsWsResponse) EventDto(org.sonar.db.event.EventDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Event(org.sonarqube.ws.Developers.SearchEventsWsResponse.Event) Mockito.mock(org.mockito.Mockito.mock) 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