Search in sources :

Example 16 with Registration

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);
    }
}
Also used : WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) ResolveConflictsWebLink(com.google.gerrit.extensions.webui.ResolveConflictsWebLink) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PatchSetWebLink(com.google.gerrit.extensions.webui.PatchSetWebLink) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 17 with Registration

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());
    }
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushResult(org.eclipse.jgit.transport.PushResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 18 with Registration

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());
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 19 with Registration

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());
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 20 with Registration

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();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Config(org.eclipse.jgit.lib.Config) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)205 Test (org.junit.Test)200 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)194 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)90 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)47 RestResponse (com.google.gerrit.acceptance.RestResponse)39 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)38 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)31 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)23 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)22 TestAccount (com.google.gerrit.acceptance.TestAccount)19 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)19 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)16 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)15 Config (org.eclipse.jgit.lib.Config)14 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)12 CreateProjectArgs (com.google.gerrit.server.project.CreateProjectArgs)11 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 ImmutableList (com.google.common.collect.ImmutableList)10