use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOf.
@Test
public void voteOnBehalfOf() throws Exception {
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = ReviewInput.recommend();
in.onBehalfOf = user.id.toString();
in.message = "Message on behalf of";
revision.review(in);
PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
assertThat(psa.getPatchSetId().get()).isEqualTo(1);
assertThat(psa.getLabel()).isEqualTo("Code-Review");
assertThat(psa.getAccountId()).isEqualTo(user.id);
assertThat(psa.getValue()).isEqualTo(1);
assertThat(psa.getRealAccountId()).isEqualTo(admin.id);
ChangeData cd = r.getChange();
ChangeMessage m = Iterables.getLast(cmUtil.byChange(db, cd.notes()));
assertThat(m.getMessage()).endsWith(in.message);
assertThat(m.getAuthor()).isEqualTo(user.id);
assertThat(m.getRealAuthor()).isEqualTo(admin.id);
}
use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOfLabelNotPermitted.
@Test
public void voteOnBehalfOfLabelNotPermitted() throws Exception {
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
LabelType verified = Util.verified();
cfg.getLabelSections().put(verified.getName(), verified);
saveProjectConfig(project, cfg);
PushOneCommit.Result r = createChange();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id.toString();
in.label("Verified", 1);
exception.expect(AuthException.class);
exception.expectMessage("not permitted to modify label \"Verified\" on behalf of \"" + in.onBehalfOf + '"');
revision.review(in);
}
use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOfInvalidLabelIgnoredWithoutStrictLabels.
@Test
public void voteOnBehalfOfInvalidLabelIgnoredWithoutStrictLabels() throws Exception {
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id.toString();
in.strictLabels = false;
in.label("Code-Review", 1);
in.label("Not-A-Label", 5);
revision.review(in);
assertThat(gApi.changes().id(r.getChangeId()).get().labels).doesNotContainKey("Not-A-Label");
}
use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOfFailsWhenUserCannotSeeDestinationRef.
@Test
public void voteOnBehalfOfFailsWhenUserCannotSeeDestinationRef() throws Exception {
blockRead(newGroup);
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id.toString();
in.label("Code-Review", 1);
exception.expect(UnprocessableEntityException.class);
exception.expectMessage("on_behalf_of account " + user.id + " cannot see change");
revision.review(in);
}
use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class ChangeIT method rebaseNotAllowedForOwnerWithoutPushPermission.
@Test
public void rebaseNotAllowedForOwnerWithoutPushPermission() throws Exception {
// Create two changes both with the same parent
PushOneCommit.Result r = createChange();
testRepo.reset("HEAD~1");
PushOneCommit.Result r2 = createChange();
// Approve and submit the first change
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
revision.review(ReviewInput.approve());
revision.submit();
block("refs/for/*", Permission.PUSH, REGISTERED_USERS);
// Rebase the second
String changeId = r2.getChangeId();
exception.expect(AuthException.class);
exception.expectMessage("rebase not permitted");
gApi.changes().id(changeId).rebase();
}
Aggregations