use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method listGpgKeys.
@Test
public void listGpgKeys() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
List<TestKey> keys = allValidKeys();
List<String> toAdd = new ArrayList<>(keys.size());
for (TestKey key : keys) {
addExternalIdEmail(admin, PushCertificateIdent.parse(key.getFirstUserId()).getEmailAddress());
toAdd.add(key.getPublicKeyArmored());
}
accountIndexedCounter.clear();
gApi.accounts().self().putGpgKeys(toAdd, ImmutableList.of());
assertKeys(keys);
accountIndexedCounter.assertReindexOf(admin);
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method addAndRemoveGpgKeys.
@Test
public void addAndRemoveGpgKeys() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
for (TestKey key : allValidKeys()) {
addExternalIdEmail(admin, PushCertificateIdent.parse(key.getFirstUserId()).getEmailAddress());
}
accountIndexedCounter.clear();
TestKey key1 = validKeyWithoutExpiration();
TestKey key2 = validKeyWithExpiration();
TestKey key5 = validKeyWithSecondUserId();
Map<String, GpgKeyInfo> infos = gApi.accounts().self().putGpgKeys(ImmutableList.of(key1.getPublicKeyArmored(), key2.getPublicKeyArmored()), ImmutableList.of(key5.getKeyIdString()));
assertThat(infos.keySet()).containsExactly(key1.getKeyIdString(), key2.getKeyIdString());
assertKeys(key1, key2);
accountIndexedCounter.assertReindexOf(admin);
infos = gApi.accounts().self().putGpgKeys(ImmutableList.of(key5.getPublicKeyArmored()), ImmutableList.of(key1.getKeyIdString()));
assertThat(infos.keySet()).containsExactly(key1.getKeyIdString(), key5.getKeyIdString());
assertKeyMapContains(key5, infos);
assertThat(infos.get(key1.getKeyIdString()).key).isNull();
assertKeys(key2, key5);
accountIndexedCounter.assertReindexOf(admin);
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.accounts().self().putGpgKeys(ImmutableList.of(key2.getPublicKeyArmored()), ImmutableList.of(key2.getKeyIdString())));
assertThat(thrown).hasMessageThat().contains("Cannot both add and delete key: " + keyToString(key2.getPublicKey()));
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method get.
@Test
public void get() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
AccountInfo info = gApi.accounts().id("admin").get();
assertThat(info.name).isEqualTo("Administrator");
assertThat(info.email).isEqualTo("admin@example.com");
assertThat(info.username).isEqualTo("admin");
accountIndexedCounter.assertNoReindex();
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method addGpgKey.
private Map<String, GpgKeyInfo> addGpgKey(TestAccount account, String armored) throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
Map<String, GpgKeyInfo> gpgKeys = gApi.accounts().id(account.username()).putGpgKeys(ImmutableList.of(armored), ImmutableList.<String>of());
accountIndexedCounter.assertReindexOf(gApi.accounts().id(account.username()).get());
return gpgKeys;
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method createByAccountCreator.
private Account.Id createByAccountCreator(int expectedAccountReindexCalls) throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
String name = "foo";
TestAccount foo = accountCreator.create(name);
AccountInfo info = gApi.accounts().id(foo.id().get()).get();
assertThat(info.username).isEqualTo(name);
assertThat(info.name).isEqualTo(name);
accountIndexedCounter.assertReindexOf(foo, expectedAccountReindexCalls);
assertUserBranch(foo.id(), name, null);
return foo.id();
}
}
Aggregations