use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class ChangeIT method votable.
@Test
public void votable() throws Exception {
PushOneCommit.Result r = createChange();
String triplet = project.get() + "~master~" + r.getChangeId();
gApi.changes().id(triplet).addReviewer(user.username);
ChangeInfo c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
LabelInfo codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1);
ApprovalInfo approval = codeReview.all.get(0);
assertThat(approval._accountId).isEqualTo(user.id.get());
assertThat(approval.value).isEqualTo(0);
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
blockLabel(cfg, "Code-Review", REGISTERED_USERS, "refs/heads/*");
saveProjectConfig(project, cfg);
c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1);
approval = codeReview.all.get(0);
assertThat(approval._accountId).isEqualTo(user.id.get());
assertThat(approval.value).isNull();
}
use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class ChangeIT method maxPermittedValueBlocked.
@Test
public void maxPermittedValueBlocked() throws Exception {
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
blockLabel(cfg, "Code-Review", REGISTERED_USERS, "refs/heads/*");
saveProjectConfig(project, cfg);
PushOneCommit.Result r = createChange();
String triplet = project.get() + "~master~" + r.getChangeId();
gApi.changes().id(triplet).addReviewer(user.username);
ChangeInfo c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
LabelInfo codeReview = c.labels.get("Code-Review");
assertThat(codeReview.all).hasSize(1);
ApprovalInfo approval = codeReview.all.get(0);
assertThat(approval._accountId).isEqualTo(user.id.get());
assertThat(approval.permittedVotingRange).isNull();
}
use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForMasterWithApprovals.
@Test
public void pushForMasterWithApprovals() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master/%l=Code-Review");
r.assertOkStatus();
ChangeInfo ci = get(r.getChangeId());
LabelInfo cr = ci.labels.get("Code-Review");
assertThat(cr.all).hasSize(1);
assertThat(cr.all.get(0).name).isEqualTo("Administrator");
assertThat(cr.all.get(0).value).isEqualTo(1);
assertThat(Iterables.getLast(ci.messages).message).isEqualTo("Uploaded patch set 1: Code-Review+1.");
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent", r.getChangeId());
r = push.to("refs/for/master/%l=Code-Review+2");
ci = get(r.getChangeId());
cr = ci.labels.get("Code-Review");
assertThat(Iterables.getLast(ci.messages).message).isEqualTo("Uploaded patch set 2: Code-Review+2.");
// Check that the user who pushed the change was added as a reviewer since they added a vote
assertThatUserIsOnlyReviewer(ci, admin);
assertThat(cr.all).hasSize(1);
assertThat(cr.all.get(0).name).isEqualTo("Administrator");
assertThat(cr.all.get(0).value).isEqualTo(2);
push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "c.txt", "moreContent", r.getChangeId());
r = push.to("refs/for/master/%l=Code-Review+2");
ci = get(r.getChangeId());
assertThat(Iterables.getLast(ci.messages).message).isEqualTo("Uploaded patch set 3.");
}
use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForMasterWithApprovalsForgeCommitterButNoForgeVote.
/**
* There was a bug that allowed a user with Forge Committer Identity access right to upload a
* commit and put *votes on behalf of another user* on it. This test checks that this is not
* possible, but that the votes that are specified on push are applied only on behalf of the
* uploader.
*
* <p>This particular bug only occurred when there was more than one label defined. However to
* test that the votes that are specified on push are applied on behalf of the uploader a single
* label is sufficient.
*/
@Test
public void pushForMasterWithApprovalsForgeCommitterButNoForgeVote() throws Exception {
// Create a commit with "User" as author and committer
RevCommit c = commitBuilder().author(user.getIdent()).committer(user.getIdent()).add(PushOneCommit.FILE_NAME, PushOneCommit.FILE_CONTENT).message(PushOneCommit.SUBJECT).create();
// Push this commit as "Administrator" (requires Forge Committer Identity)
pushHead(testRepo, "refs/for/master/%l=Code-Review+1", false);
// Expected Code-Review votes:
// 1. 0 from User (committer):
// When the committer is forged, the committer is automatically added as
// reviewer, hence we expect a dummy 0 vote for the committer.
// 2. +1 from Administrator (uploader):
// On push Code-Review+1 was specified, hence we expect a +1 vote from
// the uploader.
ChangeInfo ci = get(GitUtil.getChangeId(testRepo, c).get());
LabelInfo cr = ci.labels.get("Code-Review");
assertThat(cr.all).hasSize(2);
int indexAdmin = admin.fullName.equals(cr.all.get(0).name) ? 0 : 1;
int indexUser = indexAdmin == 0 ? 1 : 0;
assertThat(cr.all.get(indexAdmin).name).isEqualTo(admin.fullName);
assertThat(cr.all.get(indexAdmin).value.intValue()).isEqualTo(1);
assertThat(cr.all.get(indexUser).name).isEqualTo(user.fullName);
assertThat(cr.all.get(indexUser).value.intValue()).isEqualTo(0);
assertThat(Iterables.getLast(ci.messages).message).isEqualTo("Uploaded patch set 1: Code-Review+1.");
// Check that the user who pushed the change was added as a reviewer since they added a vote
assertThatUserIsOnlyReviewer(ci, admin);
}
use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class AbstractSubmit method assertApproved.
protected void assertApproved(String changeId, TestAccount user) throws Exception {
ChangeInfo c = get(changeId, DETAILED_LABELS);
LabelInfo cr = c.labels.get("Code-Review");
assertThat(cr.all).hasSize(1);
assertThat(cr.all.get(0).value).isEqualTo(2);
assertThat(new Account.Id(cr.all.get(0)._accountId)).isEqualTo(user.getId());
}
Aggregations