use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class ChangeIT method checkLabelsForMergedChangeWithNonAuthorCodeReview.
@Test
public void checkLabelsForMergedChangeWithNonAuthorCodeReview() throws Exception {
// Configure Non-Author-Code-Review
RevCommit oldHead = getRemoteHead();
GitUtil.fetch(testRepo, RefNames.REFS_CONFIG + ":config");
testRepo.reset("config");
PushOneCommit push2 = pushFactory.create(db, admin.getIdent(), testRepo, "Configure Non-Author-Code-Review", "rules.pl", "submit_rule(S) :-\n" + " gerrit:default_submit(X),\n" + " X =.. [submit | Ls],\n" + " add_non_author_approval(Ls, R),\n" + " S =.. [submit | R].\n" + "\n" + "add_non_author_approval(S1, S2) :-\n" + " gerrit:commit_author(A),\n" + " gerrit:commit_label(label('Code-Review', 2), R),\n" + " R \\= A, !,\n" + " S2 = [label('Non-Author-Code-Review', ok(R)) | S1].\n" + "add_non_author_approval(S1," + " [label('Non-Author-Code-Review', need(_)) | S1]).");
push2.to(RefNames.REFS_CONFIG);
testRepo.reset(oldHead);
// Allow user to approve
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
AccountGroup.UUID registeredUsers = systemGroupBackend.getGroup(REGISTERED_USERS).getUUID();
String heads = RefNames.REFS_HEADS + "*";
Util.allow(cfg, Permission.forLabel(Util.codeReview().getName()), -2, 2, registeredUsers, heads);
saveProjectConfig(project, cfg);
PushOneCommit.Result r = createChange();
setApiUser(user);
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
setApiUser(admin);
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).submit();
ChangeInfo change = gApi.changes().id(r.getChangeId()).get();
assertThat(change.status).isEqualTo(ChangeStatus.MERGED);
assertThat(change.labels.keySet()).containsExactly("Code-Review", "Non-Author-Code-Review");
assertThat(change.permittedLabels.keySet()).containsExactly("Code-Review");
assertPermitted(change, "Code-Review", 0, 1, 2);
}
use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method rework.
private void rework(String changeId) throws Exception {
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, PushOneCommit.FILE_NAME, "new content " + System.nanoTime(), changeId);
push.to("refs/for/master").assertOkStatus();
assertThat(getChangeKind(changeId)).isEqualTo(REWORK);
}
use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method trivialRebase.
private void trivialRebase(String changeId) throws Exception {
setApiUser(admin);
testRepo.reset(getRemoteHead());
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "Other Change", "a" + System.nanoTime() + ".txt", PushOneCommit.FILE_CONTENT);
PushOneCommit.Result r = push.to("refs/for/master");
r.assertOkStatus();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = new ReviewInput().label("Code-Review", 2).label("Verified", 1);
revision.review(in);
revision.submit();
gApi.changes().id(changeId).current().rebase();
assertThat(getChangeKind(changeId)).isEqualTo(TRIVIAL_REBASE);
}
use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class ChangeIT method addReviewerThatCannotSeeChange.
@Test
public void addReviewerThatCannotSeeChange() throws Exception {
// create hidden project that is only visible to administrators
Project.NameKey p = createProject("p");
ProjectConfig cfg = projectCache.checkedGet(p).getConfig();
Util.allow(cfg, Permission.READ, groupCache.get(new AccountGroup.NameKey("Administrators")).getGroupUUID(), "refs/*");
Util.block(cfg, Permission.READ, REGISTERED_USERS, "refs/*");
saveProjectConfig(p, cfg);
// create change
TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
PushOneCommit push = pushFactory.create(db, admin.getIdent(), repo);
PushOneCommit.Result result = push.to("refs/for/master");
result.assertOkStatus();
// check the user cannot see the change
setApiUser(user);
try {
gApi.changes().id(result.getChangeId()).get();
fail("Expected ResourceNotFoundException");
} catch (ResourceNotFoundException e) {
// Expected.
}
// try to add user as reviewer
setApiUser(admin);
AddReviewerInput in = new AddReviewerInput();
in.reviewer = user.email;
AddReviewerResult r = gApi.changes().id(result.getChangeId()).addReviewer(in);
assertThat(r.input).isEqualTo(user.email);
assertThat(r.error).contains("does not have permission to see this change");
assertThat(r.reviewers).isNull();
}
use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class ChangeIT method getAmbiguous.
@Test
public void getAmbiguous() throws Exception {
PushOneCommit.Result r1 = createChange();
String changeId = r1.getChangeId();
gApi.changes().id(changeId).get();
BranchInput b = new BranchInput();
b.revision = repo().exactRef("HEAD").getObjectId().name();
gApi.projects().name(project.get()).branch("other").create(b);
PushOneCommit push2 = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, PushOneCommit.FILE_NAME, PushOneCommit.FILE_CONTENT, changeId);
PushOneCommit.Result r2 = push2.to("refs/for/other");
assertThat(r2.getChangeId()).isEqualTo(changeId);
exception.expect(ResourceNotFoundException.class);
exception.expectMessage("Multiple changes found for " + changeId);
gApi.changes().id(changeId).get();
}
Aggregations