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));
}
}
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);
}
}
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");
}
}
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();
}
}
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());
}
}
Aggregations