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));
}
Aggregations