Search in sources :

Example 1 with PARAM_FROM

use of org.sonar.server.developers.ws.SearchEventsAction.PARAM_FROM 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

String.format (java.lang.String.format)1 Date (java.util.Date)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 Test (org.junit.Test)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 Mockito.when (org.mockito.Mockito.when)1 Server (org.sonar.api.platform.Server)1 RuleType (org.sonar.api.rules.RuleType)1 WebService (org.sonar.api.server.ws.WebService)1