use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class RevisionIT method commit.
@Test
public void commit() throws Exception {
WebLinkInfo expectedPatchSetLinkInfo = new WebLinkInfo("foo", "imageUrl", "url");
PatchSetWebLink patchSetLink = new PatchSetWebLink() {
@Override
public WebLinkInfo getPatchSetWebLink(String projectName, String commit, String commitMessage, String branchName) {
return expectedPatchSetLinkInfo;
}
};
WebLinkInfo expectedResolveConflictsLinkInfo = new WebLinkInfo("bar", "img", "resolve");
ResolveConflictsWebLink resolveConflictsLink = new ResolveConflictsWebLink() {
@Override
public WebLinkInfo getResolveConflictsWebLink(String projectName, String commit, String commitMessage, String branchName) {
return expectedResolveConflictsLinkInfo;
}
};
try (Registration registration = extensionRegistry.newRegistration().add(patchSetLink).add(resolveConflictsLink)) {
PushOneCommit.Result r = createChange();
RevCommit c = r.getCommit();
CommitInfo commitInfo = gApi.changes().id(r.getChangeId()).current().commit(false);
assertThat(commitInfo.commit).isEqualTo(c.name());
assertPersonIdent(commitInfo.author, c.getAuthorIdent());
assertPersonIdent(commitInfo.committer, c.getCommitterIdent());
assertThat(commitInfo.message).isEqualTo(c.getFullMessage());
assertThat(commitInfo.subject).isEqualTo(c.getShortMessage());
assertThat(commitInfo.parents).hasSize(1);
assertThat(Iterables.getOnlyElement(commitInfo.parents).commit).isEqualTo(c.getParent(0).name());
assertThat(commitInfo.webLinks).isNull();
commitInfo = gApi.changes().id(r.getChangeId()).current().commit(true);
assertThat(commitInfo.webLinks).hasSize(1);
WebLinkInfo patchSetLinkInfo = Iterables.getOnlyElement(commitInfo.webLinks);
assertThat(patchSetLinkInfo.name).isEqualTo(expectedPatchSetLinkInfo.name);
assertThat(patchSetLinkInfo.imageUrl).isEqualTo(expectedPatchSetLinkInfo.imageUrl);
assertThat(patchSetLinkInfo.url).isEqualTo(expectedPatchSetLinkInfo.url);
assertThat(patchSetLinkInfo.target).isEqualTo(expectedPatchSetLinkInfo.target);
assertThat(commitInfo.resolveConflictsWebLinks).hasSize(1);
WebLinkInfo resolveCommentsLinkInfo = Iterables.getOnlyElement(commitInfo.resolveConflictsWebLinks);
assertThat(resolveCommentsLinkInfo.name).isEqualTo(expectedResolveConflictsLinkInfo.name);
assertThat(resolveCommentsLinkInfo.imageUrl).isEqualTo(expectedResolveConflictsLinkInfo.imageUrl);
assertThat(resolveCommentsLinkInfo.url).isEqualTo(expectedResolveConflictsLinkInfo.url);
assertThat(resolveCommentsLinkInfo.target).isEqualTo(expectedResolveConflictsLinkInfo.target);
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class RefOperationValidationIT method rejectRefDeletionByPush.
@Test
public void rejectRefDeletionByPush() throws Exception {
gApi.projects().name(project.get()).branch(TEST_REF).create(new BranchInput());
grant(Permission.DELETE);
try (Registration registration = testValidator(DELETE)) {
PushResult result = deleteRef(testRepo, TEST_REF);
RemoteRefUpdate refUpdate = result.getRemoteUpdate(TEST_REF);
assertThat(refUpdate.getMessage()).contains(DELETE.name());
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class RefOperationValidationIT method rejectRefDeletion.
@Test
public void rejectRefDeletion() throws Exception {
gApi.projects().name(project.get()).branch(TEST_REF).create(new BranchInput());
try (Registration registration = testValidator(DELETE)) {
RestApiException expected = assertThrows(RestApiException.class, () -> gApi.projects().name(project.get()).branch(TEST_REF).delete());
assertThat(expected).hasMessageThat().contains(DELETE.name());
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class RefOperationValidationIT method rejectRefCreationByPush.
@Test
public void rejectRefCreationByPush() throws Exception {
try (Registration registration = testValidator(CREATE)) {
grant(Permission.PUSH);
PushOneCommit push1 = pushFactory.create(admin.newIdent(), testRepo, "change1", "a.txt", "content");
PushOneCommit.Result r1 = push1.to("refs/heads/master");
r1.assertOkStatus();
PushOneCommit.Result r2 = push1.to(TEST_REF);
r2.assertErrorStatus(CREATE.name());
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class PushAccountIT method pushAccountConfigToUserBranchForReviewDeactivateOtherAccount.
@Test
public void pushAccountConfigToUserBranchForReviewDeactivateOtherAccount() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
TestAccount foo = accountCreator.create(name("foo"));
assertThat(gApi.accounts().id(foo.id().get()).getActive()).isTrue();
String userRef = RefNames.refsUsers(foo.id());
accountIndexedCounter.clear();
projectOperations.project(allUsers).forUpdate().add(allow(Permission.PUSH).ref(userRef).group(adminGroupUuid())).add(allowLabel("Code-Review").ref(userRef).group(adminGroupUuid()).range(-2, 2)).add(allow(Permission.SUBMIT).ref(userRef).group(adminGroupUuid())).update();
TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
fetch(allUsersRepo, userRef + ":userRef");
allUsersRepo.reset("userRef");
Config ac = getAccountConfig(allUsersRepo);
ac.setBoolean(AccountProperties.ACCOUNT, null, AccountProperties.KEY_ACTIVE, false);
PushOneCommit.Result r = pushFactory.create(admin.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, ac.toText()).to(MagicBranch.NEW_CHANGE + userRef);
r.assertOkStatus();
accountIndexedCounter.assertNoReindex();
assertThat(r.getChange().change().getDest().branch()).isEqualTo(userRef);
gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
gApi.changes().id(r.getChangeId()).current().submit();
accountIndexedCounter.assertReindexOf(foo);
assertThat(gApi.accounts().id(foo.id().get()).getActive()).isFalse();
}
}
Aggregations