use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class AccountIT method deleteAllDraftComments.
@Test
@UseClockStep
public void deleteAllDraftComments() throws Exception {
try {
Project.NameKey project2 = projectOperations.newProject().create();
PushOneCommit.Result r1 = createChange();
TestRepository<?> tr2 = cloneProject(project2);
PushOneCommit.Result r2 = createChange(tr2, "refs/heads/master", "Change in project2", PushOneCommit.FILE_NAME, "content2", null);
// Create 2 drafts each on both changes for user.
requestScopeOperations.setApiUser(user.id());
createDraft(r1, PushOneCommit.FILE_NAME, "draft 1a");
createDraft(r1, PushOneCommit.FILE_NAME, "draft 1b");
createDraft(r2, PushOneCommit.FILE_NAME, "draft 2a");
createDraft(r2, PushOneCommit.FILE_NAME, "draft 2b");
assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).hasSize(2);
assertThat(gApi.changes().id(r2.getChangeId()).current().draftsAsList()).hasSize(2);
// Create 1 draft on first change for admin.
requestScopeOperations.setApiUser(admin.id());
createDraft(r1, PushOneCommit.FILE_NAME, "admin draft");
assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).hasSize(1);
// Delete user's draft comments; leave admin's alone.
requestScopeOperations.setApiUser(user.id());
List<DeletedDraftCommentInfo> result = gApi.accounts().self().deleteDraftComments(new DeleteDraftCommentsInput());
// Results are ordered according to the change search, most recently updated first.
assertThat(result).hasSize(2);
DeletedDraftCommentInfo del2 = result.get(0);
assertThat(del2.change.changeId).isEqualTo(r2.getChangeId());
assertThat(del2.deleted.stream().map(c -> c.message)).containsExactly("draft 2a", "draft 2b");
DeletedDraftCommentInfo del1 = result.get(1);
assertThat(del1.change.changeId).isEqualTo(r1.getChangeId());
assertThat(del1.deleted.stream().map(c -> c.message)).containsExactly("draft 1a", "draft 1b");
assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).isEmpty();
assertThat(gApi.changes().id(r2.getChangeId()).current().draftsAsList()).isEmpty();
requestScopeOperations.setApiUser(admin.id());
assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).hasSize(1);
} finally {
cleanUpDrafts();
}
}
use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class AccountIT method createAtomically.
@Test
@UseClockStep
public void createAtomically() throws Exception {
Account.Id accountId = Account.id(seq.nextAccountId());
String fullName = "Foo";
ExternalId extId = externalIdFactory.createEmail(accountId, "foo@example.com");
AccountState accountState = accountsUpdateProvider.get().insert("Create Account Atomically", accountId, u -> u.setFullName(fullName).addExternalId(extId));
assertThat(accountState.account().fullName()).isEqualTo(fullName);
AccountInfo info = gApi.accounts().id(accountId.get()).get();
assertThat(info.name).isEqualTo(fullName);
List<EmailInfo> emails = gApi.accounts().id(accountId.get()).getEmails();
assertThat(emails.stream().map(e -> e.email).collect(toSet())).containsExactly(extId.email());
RevCommit commitUserBranch = projectOperations.project(allUsers).getHead(RefNames.refsUsers(accountId));
RevCommit commitRefsMetaExternalIds = projectOperations.project(allUsers).getHead(RefNames.REFS_EXTERNAL_IDS);
assertThat(commitUserBranch.getCommitTime()).isEqualTo(commitRefsMetaExternalIds.getCommitTime());
}
use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class ChangeIT method addSelfAsReviewer.
@Test
@UseClockStep
public void addSelfAsReviewer() throws Exception {
PushOneCommit.Result r = createChange();
ChangeResource rsrc = parseResource(r);
String oldETag = rsrc.getETag();
Instant oldTs = rsrc.getChange().getLastUpdatedOn();
ReviewerInput in = new ReviewerInput();
in.reviewer = user.email();
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).addReviewer(in);
// There should be no email notification when adding self
assertThat(sender.getMessages()).isEmpty();
// Adding a reviewer records that user as reviewer.
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
assertThat(reviewers).isNotNull();
assertThat(reviewers).hasSize(1);
assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.id().get());
// Ensure ETag and lastUpdatedOn are updated.
rsrc = parseResource(r);
assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class ChangeIT method addReviewerViaPostReview.
@Test
@UseClockStep
public void addReviewerViaPostReview() throws Exception {
testAddReviewerViaPostReview((changeId, reviewer) -> {
ReviewerInput reviewerInput = new ReviewerInput();
reviewerInput.reviewer = reviewer;
ReviewInput reviewInput = new ReviewInput();
reviewInput.reviewers = ImmutableList.of(reviewerInput);
gApi.changes().id(changeId).current().review(reviewInput);
});
}
use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class QueryChangesIT method withPagedResults.
@Test
@UseClockStep
@SuppressWarnings("unchecked")
public void withPagedResults() throws Exception {
// Create 4 visible changes.
createChange(testRepo).getChange().getId().get();
createChange(testRepo).getChange().getId().get();
int changeId3 = createChange(testRepo).getChange().getId().get();
int changeId4 = createChange(testRepo).getChange().getId().get();
// Create hidden project.
Project.NameKey hiddenProject = projectOperations.newProject().create();
TestRepository<InMemoryRepository> hiddenRepo = cloneProject(hiddenProject, admin);
// Create 2 hidden changes.
createChange(hiddenRepo);
createChange(hiddenRepo);
// Actually hide project
projectOperations.project(hiddenProject).forUpdate().add(block(Permission.READ).ref("refs/*").group(REGISTERED_USERS)).update();
// Create a change query that matches all changes (visible and hidden changes).
// The index returns the changes ordered by last updated timestamp:
// hiddenChange2, hiddenChange1, change4, change3, change2, change1
QueryChanges queryChanges = queryChangesProvider.get();
queryChanges.addQuery("branch:master");
// Set a limit on the query so that we need to paginate over the results from the index.
queryChanges.setLimit(2);
// Execute the query and verify the results.
// Since the limit is set to 2, at most 2 changes are returned to user, but the index query is
// executed with limit 3 (+1 so that we can populate the _more_changes field on the last
// result).
// This means the index query with limit 3 returns these changes:
// hiddenChange2, hiddenChange1, change4
// The 2 hidden changes are filtered out because they are not visible to the caller.
// This means we have only one matching result (change4) but the limit (3) is not exhausted
// yet. Hence the next page is loaded from the index (startIndex is 3 to skip the results
// that we already processed, limit is again 3). The results for the next page are:
// change3, change2, change1
// change2 and change1 are dropped because they are over the limit.
List<ChangeInfo> result = (List<ChangeInfo>) queryChanges.apply(TopLevelResource.INSTANCE).value();
assertThat(result.stream().map(i -> i._number).collect(toList())).containsExactly(changeId3, changeId4);
}
Aggregations