Search in sources :

Example 1 with PullRequest

use of org.sonarqube.ws.ProjectPullRequests.PullRequest in project sonarqube by SonarSource.

the class ListActionTest method response_contains_date_of_last_analysis.

@Test
public void response_contains_date_of_last_analysis() {
    Long lastAnalysisNonMainBranch = dateToLong(parseDateTime("2017-04-01T00:00:00+0100"));
    Long previousAnalysisPullRequest = dateToLong(parseDateTime("2017-04-02T00:00:00+0100"));
    Long lastAnalysisPullRequest = dateToLong(parseDateTime("2017-04-03T00:00:00+0100"));
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().addProjectPermission(UserRole.USER, project);
    ComponentDto pullRequest1 = db.components().insertProjectBranch(project, b -> b.setKey("pr1").setBranchType(PULL_REQUEST).setMergeBranchUuid(project.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/pr1").build()));
    ComponentDto nonMainBranch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
    ComponentDto pullRequest2 = db.components().insertProjectBranch(project, b -> b.setKey("pr2").setBranchType(PULL_REQUEST).setMergeBranchUuid(nonMainBranch2.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/pr2").build()));
    db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(nonMainBranch2).setCreatedAt(lastAnalysisNonMainBranch));
    db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(pullRequest2).setCreatedAt(previousAnalysisPullRequest).setLast(false));
    db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(pullRequest2).setCreatedAt(lastAnalysisPullRequest));
    db.commit();
    indexIssues();
    permissionIndexerTester.allowOnlyAnyone(project);
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getPullRequestsList()).extracting(PullRequest::hasAnalysisDate, b -> "".equals(b.getAnalysisDate()) ? null : dateToLong(parseDateTime(b.getAnalysisDate()))).containsExactlyInAnyOrder(tuple(false, null), tuple(true, lastAnalysisPullRequest));
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) GlobalPermission(org.sonar.db.permission.GlobalPermission) PullRequest(org.sonarqube.ws.ProjectPullRequests.PullRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CODEVIEWER(org.sonar.api.web.UserRole.CODEVIEWER) BUG(org.sonar.api.rules.RuleType.BUG) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) WebService(org.sonar.api.server.ws.WebService) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) ComponentTesting(org.sonar.db.component.ComponentTesting) ResourceTypesRule(org.sonar.db.component.ResourceTypesRule) ResourceTypes(org.sonar.api.resources.ResourceTypes) DbTester(org.sonar.db.DbTester) PARAM_PROJECT(org.sonar.server.branch.pr.ws.PullRequestsWsParameters.PARAM_PROJECT) System2(org.sonar.api.utils.System2) VULNERABILITY(org.sonar.api.rules.RuleType.VULNERABILITY) ListWsResponse(org.sonarqube.ws.ProjectPullRequests.ListWsResponse) Status(org.sonarqube.ws.ProjectPullRequests.Status) BRANCH(org.sonar.db.component.BranchType.BRANCH) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) CODE_SMELL(org.sonar.api.rules.RuleType.CODE_SMELL) SCAN_EXECUTION(org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) EsTester(org.sonar.server.es.EsTester) PROJECT(org.sonar.api.resources.Qualifiers.PROJECT) DbProjectBranches(org.sonar.db.protobuf.DbProjectBranches) DateUtils.dateToLong(org.sonar.api.utils.DateUtils.dateToLong) DateUtils(org.sonar.api.utils.DateUtils) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RESOLUTION_FALSE_POSITIVE(org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE) MediaTypes(org.sonarqube.ws.MediaTypes) RESOLUTION_FIXED(org.sonar.api.issue.Issue.RESOLUTION_FIXED) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) BranchType(org.sonar.db.component.BranchType) Assertions.tuple(org.assertj.core.api.Assertions.tuple) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) MetricDto(org.sonar.db.metric.MetricDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) Change(org.sonar.api.server.ws.Change) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) ListWsResponse(org.sonarqube.ws.ProjectPullRequests.ListWsResponse) DateUtils.dateToLong(org.sonar.api.utils.DateUtils.dateToLong) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

String.format (java.lang.String.format)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 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 RESOLUTION_FALSE_POSITIVE (org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE)1 RESOLUTION_FIXED (org.sonar.api.issue.Issue.RESOLUTION_FIXED)1 ALERT_STATUS_KEY (org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY)1 PROJECT (org.sonar.api.resources.Qualifiers.PROJECT)1 ResourceTypes (org.sonar.api.resources.ResourceTypes)1 BUG (org.sonar.api.rules.RuleType.BUG)1 CODE_SMELL (org.sonar.api.rules.RuleType.CODE_SMELL)1 VULNERABILITY (org.sonar.api.rules.RuleType.VULNERABILITY)1 Change (org.sonar.api.server.ws.Change)1 WebService (org.sonar.api.server.ws.WebService)1 DateUtils (org.sonar.api.utils.DateUtils)1 DateUtils.dateToLong (org.sonar.api.utils.DateUtils.dateToLong)1 DateUtils.parseDateTime (org.sonar.api.utils.DateUtils.parseDateTime)1