Search in sources :

Example 1 with CheckAccountsInput

use of com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountsInput in project gerrit by GerritCodeReview.

the class AccountIT method checkConsistency.

@Test
public void checkConsistency() throws Exception {
    projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
    requestScopeOperations.resetCurrentApiUser();
    // Create an account with a preferred email.
    String username = name("foo");
    String email = username + "@example.com";
    TestAccount account = accountCreator.create(username, email, "Foo Bar", null);
    ConsistencyCheckInput input = new ConsistencyCheckInput();
    input.checkAccounts = new CheckAccountsInput();
    ConsistencyCheckInfo checkInfo = gApi.config().server().checkConsistency(input);
    assertThat(checkInfo.checkAccountsResult.problems).isEmpty();
    Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
    // Delete the external ID for the preferred email. This makes the account inconsistent since it
    // now doesn't have an external ID for its preferred email.
    accountsUpdateProvider.get().update("Delete External ID", account.id(), u -> u.deleteExternalId(externalIdFactory.createEmail(account.id(), email)));
    expectedProblems.add(new ConsistencyProblemInfo(ConsistencyProblemInfo.Status.ERROR, "Account '" + account.id().get() + "' has no external ID for its preferred email '" + email + "'"));
    checkInfo = gApi.config().server().checkConsistency(input);
    assertThat(checkInfo.checkAccountsResult.problems).hasSize(expectedProblems.size());
    assertThat(checkInfo.checkAccountsResult.problems).containsExactlyElementsIn(expectedProblems);
}
Also used : ConsistencyCheckInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) CheckAccountsInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountsInput) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TestAccount(com.google.gerrit.acceptance.TestAccount) HashSet(java.util.HashSet) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 TestAccount (com.google.gerrit.acceptance.TestAccount)1 ConsistencyCheckInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo)1 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)1 ConsistencyCheckInput (com.google.gerrit.extensions.api.config.ConsistencyCheckInput)1 CheckAccountsInput (com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountsInput)1 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1