Search in sources :

Example 26 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class PushAccountIT method pushAccountConfigToUserBranchForReviewIsRejectedOnSubmitIfConfigIsInvalid.

@Test
public void pushAccountConfigToUserBranchForReviewIsRejectedOnSubmitIfConfigIsInvalid() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String userRef = RefNames.refsUsers(admin.id());
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
        fetch(allUsersRepo, userRef + ":userRef");
        allUsersRepo.reset("userRef");
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, "invalid config").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());
        ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(r.getChangeId()).current().submit());
        assertThat(thrown).hasMessageThat().contains(String.format("invalid account configuration: commit '%s' has an invalid '%s' file for account" + " '%s': Invalid config file %s in project %s in branch %s in commit %s", r.getCommit().name(), AccountProperties.ACCOUNT_CONFIG, admin.id(), AccountProperties.ACCOUNT_CONFIG, allUsers.get(), userRef, r.getCommit().name()));
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 27 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class PushAccountIT method pushToUserBranchForReview.

@Test
public void pushToUserBranchForReview() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String userRefName = RefNames.refsUsers(admin.id());
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
        fetch(allUsersRepo, userRefName + ":userRef");
        allUsersRepo.reset("userRef");
        PushOneCommit push = pushFactory.create(admin.newIdent(), allUsersRepo);
        PushOneCommit.Result r = push.to(MagicBranch.NEW_CHANGE + userRefName);
        r.assertOkStatus();
        accountIndexedCounter.assertNoReindex();
        assertThat(r.getChange().change().getDest().branch()).isEqualTo(userRefName);
        gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
        gApi.changes().id(r.getChangeId()).current().submit();
        accountIndexedCounter.assertReindexOf(admin);
        push = pushFactory.create(admin.newIdent(), allUsersRepo);
        r = push.to(MagicBranch.NEW_CHANGE + RefNames.REFS_USERS_SELF);
        r.assertOkStatus();
        accountIndexedCounter.assertNoReindex();
        assertThat(r.getChange().change().getDest().branch()).isEqualTo(userRefName);
        gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
        gApi.changes().id(r.getChangeId()).current().submit();
        accountIndexedCounter.assertReindexOf(admin);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 28 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class PushAccountIT method pushAccountConfigWithPrefEmailThatDoesNotExistAsExtIdToUserBranchForReviewAndSubmit.

@Test
public void pushAccountConfigWithPrefEmailThatDoesNotExistAsExtIdToUserBranchForReviewAndSubmit() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        TestAccount foo = accountCreator.create(name("foo"), name("foo") + "@example.com", "Foo", null);
        String userRef = RefNames.refsUsers(foo.id());
        accountIndexedCounter.clear();
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers, foo);
        fetch(allUsersRepo, userRef + ":userRef");
        allUsersRepo.reset("userRef");
        String email = "some.email@example.com";
        Config ac = getAccountConfig(allUsersRepo);
        ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_PREFERRED_EMAIL, email);
        PushOneCommit.Result r = pushFactory.create(foo.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);
        requestScopeOperations.setApiUser(foo.id());
        gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
        gApi.changes().id(r.getChangeId()).current().submit();
        accountIndexedCounter.assertReindexOf(foo);
        AccountInfo info = gApi.accounts().self().get();
        assertThat(info.email).isEqualTo(email);
        assertThat(info.name).isEqualTo(foo.fullName());
    }
}
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) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 29 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class PushAccountIT method pushAccountConfigToUserBranchInvalidPreferredEmailButNotChanged.

@Test
public void pushAccountConfigToUserBranchInvalidPreferredEmailButNotChanged() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        TestAccount foo = accountCreator.create(name("foo"), name("foo") + "@example.com", "Foo", null);
        String userRef = RefNames.refsUsers(foo.id());
        String noEmail = "no.email";
        accountsUpdateProvider.get().update("Set Preferred Email", foo.id(), u -> u.setPreferredEmail(noEmail));
        accountIndexedCounter.clear();
        projectOperations.project(allUsers).forUpdate().add(allow(Permission.PUSH).ref(userRef).group(REGISTERED_USERS)).update();
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers, foo);
        fetch(allUsersRepo, userRef + ":userRef");
        allUsersRepo.reset("userRef");
        String status = "in vacation";
        Config ac = getAccountConfig(allUsersRepo);
        ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_STATUS, status);
        pushFactory.create(foo.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, ac.toText()).to(userRef).assertOkStatus();
        accountIndexedCounter.assertReindexOf(foo);
        AccountInfo info = gApi.accounts().id(foo.id().get()).get();
        assertThat(info.email).isEqualTo(noEmail);
        assertThat(info.name).isEqualTo(foo.fullName());
        assertThat(info.status).isEqualTo(status);
    }
}
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) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 30 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class IndexChangesIT method indexNonVisibleChange.

@Test
public void indexNonVisibleChange() throws Exception {
    ChangeIndexedCounter changeIndexedCounter = new ChangeIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedCounter)) {
        String changeId = createChange().getChangeId();
        ChangeInfo changeInfo = info(changeId);
        projectOperations.project(project).forUpdate().add(block(Permission.READ).ref("refs/heads/master").group(REGISTERED_USERS)).update();
        IndexChanges.Input in = new IndexChanges.Input();
        changeIndexedCounter.clear();
        in.changes = ImmutableSet.of(changeId);
        adminRestSession.post("/config/server/index.changes", in).assertOK();
        assertThat(changeIndexedCounter.getCount(changeInfo)).isEqualTo(1);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) IndexChanges(com.google.gerrit.server.restapi.config.IndexChanges) ChangeIndexedCounter(com.google.gerrit.acceptance.ChangeIndexedCounter) 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