Search in sources :

Example 91 with Registration

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

the class AccountIT method create.

@Test
public void create() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        AccountInput input = new AccountInput();
        input.username = "foo";
        input.name = "Foo";
        input.email = "foo@example.com";
        AccountInfo accountInfo = gApi.accounts().create(input).get();
        assertThat(accountInfo._accountId).isNotNull();
        assertThat(accountInfo.username).isEqualTo(input.username);
        assertThat(accountInfo.name).isEqualTo(input.name);
        assertThat(accountInfo.email).isEqualTo(input.email);
        assertThat(accountInfo.status).isNull();
        assertThat(accountInfo.tags).isNull();
        Account.Id accountId = Account.id(accountInfo._accountId);
        accountIndexedCounter.assertReindexOf(accountId, 1);
        assertThat(externalIds.byAccount(accountId)).containsExactly(externalIdFactory.createUsername(input.username, accountId, null), externalIdFactory.createEmail(accountId, input.email));
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AccountInput(com.google.gerrit.extensions.api.accounts.AccountInput) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 92 with Registration

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

the class AccountIT method addEmailAndSetPreferred.

@Test
public void addEmailAndSetPreferred() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String email = "foo.bar@example.com";
        EmailInput input = new EmailInput();
        input.email = email;
        input.noConfirmation = true;
        input.preferred = true;
        gApi.accounts().self().addEmail(input);
        // Account is reindexed twice; once on adding the new email,
        // and then again on setting the email preferred.
        accountIndexedCounter.assertReindexOf(admin, 2);
        String preferred = gApi.accounts().self().get().email;
        assertThat(preferred).isEqualTo(email);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 93 with Registration

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

the class AccountIT method deleteEmailOfOtherUser.

@Test
public void deleteEmailOfOtherUser() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String email = "foo.bar@example.com";
        EmailInput input = new EmailInput();
        input.email = email;
        input.noConfirmation = true;
        gApi.accounts().id(user.id().get()).addEmail(input);
        accountIndexedCounter.assertReindexOf(user);
        requestScopeOperations.setApiUser(user.id());
        assertThat(getEmails()).contains(email);
        // admin can delete email of user
        requestScopeOperations.setApiUser(admin.id());
        gApi.accounts().id(user.id().get()).deleteEmail(email);
        accountIndexedCounter.assertReindexOf(user);
        requestScopeOperations.setApiUser(user.id());
        assertThat(getEmails()).doesNotContain(email);
        // user cannot delete email of admin
        AuthException thrown = assertThrows(AuthException.class, () -> gApi.accounts().id(admin.id().get()).deleteEmail(admin.email()));
        assertThat(thrown).hasMessageThat().contains("modify account not permitted");
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AuthException(com.google.gerrit.extensions.restapi.AuthException) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 94 with Registration

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

the class AbstractSubmit method submitWithValidation.

@Test
public void submitWithValidation() throws Throwable {
    AtomicBoolean called = new AtomicBoolean(false);
    OnSubmitValidationListener listener = new OnSubmitValidationListener() {

        @Override
        public void preBranchUpdate(Arguments args) throws ValidationException {
            called.set(true);
            HashSet<String> refs = Sets.newHashSet(args.getCommands().keySet());
            assertThat(refs).contains("refs/heads/master");
            refs.remove("refs/heads/master");
            if (!refs.isEmpty()) {
                // Some submit strategies need to insert new patchset.
                assertThat(refs).hasSize(1);
                assertThat(refs.iterator().next()).startsWith(RefNames.REFS_CHANGES);
            }
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(listener)) {
        PushOneCommit.Result change = createChange();
        approve(change.getChangeId());
        submit(change.getChangeId());
        assertThat(called.get()).isTrue();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OnSubmitValidationListener(com.google.gerrit.server.git.validators.OnSubmitValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 95 with Registration

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

the class AbstractSubmit method submitSchedulesOpenChangesOfSameBranchForReindexing.

@Test
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "API_REF_UPDATED_AND_CHANGE_REINDEX")
public void submitSchedulesOpenChangesOfSameBranchForReindexing() throws Throwable {
    // Create a merged change.
    PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "Merged Change", "foo.txt", "foo");
    PushOneCommit.Result mergedChange = push.to("refs/for/master");
    mergedChange.assertOkStatus();
    approve(mergedChange.getChangeId());
    submit(mergedChange.getChangeId());
    // Create some open changes.
    PushOneCommit.Result change1 = createChange();
    PushOneCommit.Result change2 = createChange();
    PushOneCommit.Result change3 = createChange();
    // Create a branch with one open change.
    BranchInput in = new BranchInput();
    in.revision = projectOperations.project(project).getHead("master").name();
    gApi.projects().name(project.get()).branch("dev").create(in);
    PushOneCommit.Result changeOtherBranch = createChange("refs/for/dev");
    ChangeIndexedListener changeIndexedListener = mock(ChangeIndexedListener.class);
    try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedListener)) {
        // submit a change, this should trigger asynchronous reindexing of the open changes on the
        // same branch
        approve(change1.getChangeId());
        submit(change1.getChangeId());
        assertThat(gApi.changes().id(change1.getChangeId()).get().status).isEqualTo(ChangeStatus.MERGED);
        // on submit the change that is submitted gets reindexed synchronously
        verify(changeIndexedListener, atLeast(1)).onChangeScheduledForIndexing(project.get(), change1.getChange().getId().get());
        verify(changeIndexedListener, atLeast(1)).onChangeIndexed(project.get(), change1.getChange().getId().get());
        // the open changes on the same branch get reindexed asynchronously
        verify(changeIndexedListener, times(1)).onChangeScheduledForIndexing(project.get(), change2.getChange().getId().get());
        verify(changeIndexedListener, times(1)).onChangeScheduledForIndexing(project.get(), change3.getChange().getId().get());
        // merged changes don't get reindexed
        verify(changeIndexedListener, times(0)).onChangeScheduledForIndexing(project.get(), mergedChange.getChange().getId().get());
        // open changes on other branches don't get reindexed
        verify(changeIndexedListener, times(0)).onChangeScheduledForIndexing(project.get(), changeOtherBranch.getChange().getId().get());
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeIndexedListener(com.google.gerrit.extensions.events.ChangeIndexedListener) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

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