Add test API to create/update accounts
The new API simplifies setting up account data for tests and makes the tests more readable. Only a few callers have been adapted to demonstrate the usage of the new API. Follow-up changes should adapt all tests to the new API and remove the AccountCreator and the old TestAccount class. Some methods in AbstractDaemonTest are duplicated for now. The old methods should be removed when all tests have been migrated to the new API. Ideally TestAccount shouldn't know about SSH specifics, but we didn’t find a good way to keep this concern separate yet. To execute account operations we directly use the internal API. One benefit of this is that we can also support operations like updates without index updates or deletions even though the REST or Java API don't allow them. Another benefit is that we bypass permissions. This means that tests need not adjust permissions just to create the correct test setup and thus hopefully will lead to simpler and more readable tests. Similar test APIs should be added to create/update groups, changes etc. As result of this the setup of test data will become more consistent. Change-Id: I8911660b027d09309879918543c063d51465b0bf Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
committed by
Dave Borowitz
parent
d391c0a9ff
commit
b0175a6335
@@ -1462,15 +1462,21 @@ public abstract class AbstractDaemonTest {
|
||||
}
|
||||
|
||||
protected void assertNotifyTo(TestAccount expected) {
|
||||
assertNotifyTo(expected.emailAddress);
|
||||
assertNotifyTo(expected.email, expected.fullName);
|
||||
}
|
||||
|
||||
protected void assertNotifyTo(Address expected) {
|
||||
protected void assertNotifyTo(
|
||||
com.google.gerrit.acceptance.testsuite.account.TestAccount expected) {
|
||||
assertNotifyTo(expected.preferredEmail().orElse(null), expected.fullname().orElse(null));
|
||||
}
|
||||
|
||||
private void assertNotifyTo(String expectedEmail, String expectedFullname) {
|
||||
Address expectedAddress = new Address(expectedFullname, expectedEmail);
|
||||
assertThat(sender.getMessages()).hasSize(1);
|
||||
Message m = sender.getMessages().get(0);
|
||||
assertThat(m.rcpt()).containsExactly(expected);
|
||||
assertThat(m.rcpt()).containsExactly(expectedAddress);
|
||||
assertThat(((EmailHeader.AddressList) m.headers().get("To")).getAddressList())
|
||||
.containsExactly(expected);
|
||||
.containsExactly(expectedAddress);
|
||||
assertThat(m.headers().get("Cc").isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@@ -1478,13 +1484,23 @@ public abstract class AbstractDaemonTest {
|
||||
assertNotifyCc(expected.emailAddress);
|
||||
}
|
||||
|
||||
protected void assertNotifyCc(Address expected) {
|
||||
protected void assertNotifyCc(
|
||||
com.google.gerrit.acceptance.testsuite.account.TestAccount expected) {
|
||||
assertNotifyCc(expected.preferredEmail().orElse(null), expected.fullname().orElse(null));
|
||||
}
|
||||
|
||||
protected void assertNotifyCc(String expectedEmail, String expectedFullname) {
|
||||
Address expectedAddress = new Address(expectedFullname, expectedEmail);
|
||||
assertNotifyCc(expectedAddress);
|
||||
}
|
||||
|
||||
protected void assertNotifyCc(Address expectedAddress) {
|
||||
assertThat(sender.getMessages()).hasSize(1);
|
||||
Message m = sender.getMessages().get(0);
|
||||
assertThat(m.rcpt()).containsExactly(expected);
|
||||
assertThat(m.rcpt()).containsExactly(expectedAddress);
|
||||
assertThat(m.headers().get("To").isEmpty()).isTrue();
|
||||
assertThat(((EmailHeader.AddressList) m.headers().get("Cc")).getAddressList())
|
||||
.containsExactly(expected);
|
||||
.containsExactly(expectedAddress);
|
||||
}
|
||||
|
||||
protected void assertNotifyBcc(TestAccount expected) {
|
||||
@@ -1495,6 +1511,17 @@ public abstract class AbstractDaemonTest {
|
||||
assertThat(m.headers().get("Cc").isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
protected void assertNotifyBcc(
|
||||
com.google.gerrit.acceptance.testsuite.account.TestAccount expected) {
|
||||
assertThat(sender.getMessages()).hasSize(1);
|
||||
Message m = sender.getMessages().get(0);
|
||||
assertThat(m.rcpt())
|
||||
.containsExactly(
|
||||
new Address(expected.fullname().orElse(null), expected.preferredEmail().orElse(null)));
|
||||
assertThat(m.headers().get("To").isEmpty()).isTrue();
|
||||
assertThat(m.headers().get("Cc").isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
protected interface ProjectWatchInfoConfiguration {
|
||||
void configure(ProjectWatchInfo pwi);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.acceptance.testsuite.account.AccountOperations;
|
||||
import com.google.gerrit.acceptance.testsuite.account.AccountOperationsImpl;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.config.FactoryModule;
|
||||
import com.google.gerrit.lucene.LuceneIndexModule;
|
||||
@@ -430,6 +432,7 @@ public class GerritServer implements AutoCloseable {
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(SshEnabled.class).to(daemon.getEnableSshd());
|
||||
bind(AccountCreator.class);
|
||||
bind(AccountOperations.class).to(AccountOperationsImpl.class);
|
||||
factory(PushOneCommit.Factory.class);
|
||||
install(InProcessProtocol.module());
|
||||
install(new NoSshModule());
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.testsuite;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ThrowingFunction<T, R> {
|
||||
|
||||
R apply(T value) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.testsuite.account;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
|
||||
/**
|
||||
* An aggregation of operations on accounts for test purposes.
|
||||
*
|
||||
* <p>To execute the operations, no Gerrit permissions are necessary.
|
||||
*
|
||||
* <p><strong>Note:</strong> This interface is not implemented using the REST or extension API.
|
||||
* Hence, it cannot be used for testing those APIs.
|
||||
*/
|
||||
public interface AccountOperations {
|
||||
|
||||
/**
|
||||
* Starts the fluent chain for a querying or modifying an account. Please see the methods of
|
||||
* {@link MoreAccountOperations} for details on possible operations.
|
||||
*
|
||||
* @return an aggregation of operations on a specific account
|
||||
*/
|
||||
MoreAccountOperations account(Account.Id accountId);
|
||||
|
||||
/**
|
||||
* Starts the fluent chain to create an account. The returned builder can be used to specify the
|
||||
* attributes of the new account. To create the account for real, {@link
|
||||
* TestAccountCreation.Builder#create()} must be called.
|
||||
*
|
||||
* <p>Example:
|
||||
*
|
||||
* <pre>
|
||||
* TestAccount createdAccount = accountOperations
|
||||
* .newAccount()
|
||||
* .username("janedoe")
|
||||
* .preferredEmail("janedoe@example.com")
|
||||
* .fullname("Jane Doe")
|
||||
* .create();
|
||||
* </pre>
|
||||
*
|
||||
* <p><strong>Note:</strong> If another account with the provided user name or preferred email
|
||||
* address already exists, the creation of the account will fail.
|
||||
*
|
||||
* @return a builder to create the new account
|
||||
*/
|
||||
TestAccountCreation.Builder newAccount();
|
||||
|
||||
/** An aggregation of methods on a specific account. */
|
||||
interface MoreAccountOperations {
|
||||
|
||||
/**
|
||||
* Checks whether the account exists.
|
||||
*
|
||||
* @return {@code true} if the account exists
|
||||
*/
|
||||
boolean exists() throws Exception;
|
||||
|
||||
/**
|
||||
* Retrieves the account.
|
||||
*
|
||||
* <p><strong>Note:</strong> This call will fail with an exception if the requested account
|
||||
* doesn't exist. If you want to check for the existence of an account, use {@link #exists()}
|
||||
* instead.
|
||||
*
|
||||
* @return the corresponding {@code TestAccount}
|
||||
*/
|
||||
TestAccount get() throws Exception;
|
||||
|
||||
/**
|
||||
* Starts the fluent chain to update an account. The returned builder can be used to specify how
|
||||
* the attributes of the account should be modified. To update the account for real, {@link
|
||||
* TestAccountUpdate.Builder#update()} must be called.
|
||||
*
|
||||
* <p>Example:
|
||||
*
|
||||
* <pre>
|
||||
* TestAccount updatedAccount = accountOperations.forUpdate().status("on vacation").update();
|
||||
* </pre>
|
||||
*
|
||||
* <p><strong>Note:</strong> The update will fail with an exception if the account to update
|
||||
* doesn't exist. If you want to check for the existence of an account, use {@link #exists()}.
|
||||
*
|
||||
* @return a builder to update the account
|
||||
*/
|
||||
TestAccountUpdate.Builder forUpdate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.testsuite.account;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static java.nio.charset.StandardCharsets.US_ASCII;
|
||||
|
||||
import com.google.gerrit.acceptance.SshEnabled;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.Sequences;
|
||||
import com.google.gerrit.server.ServerInitiated;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.account.Accounts;
|
||||
import com.google.gerrit.server.account.AccountsUpdate;
|
||||
import com.google.gerrit.server.account.InternalAccountUpdate;
|
||||
import com.google.gerrit.server.account.VersionedAuthorizedKeys;
|
||||
import com.google.gerrit.server.account.externalids.ExternalId;
|
||||
import com.google.gerrit.server.ssh.SshKeyCache;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.KeyPair;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
/**
|
||||
* The implementation of {@code AccountOperations}.
|
||||
*
|
||||
* <p>There is only one implementation of {@code AccountOperations}. Nevertheless, we keep the
|
||||
* separation between interface and implementation to enhance clarity.
|
||||
*/
|
||||
public class AccountOperationsImpl implements AccountOperations {
|
||||
private final Accounts accounts;
|
||||
private final AccountsUpdate accountsUpdate;
|
||||
private final Sequences seq;
|
||||
private final SshKeyCache sshKeyCache;
|
||||
private final VersionedAuthorizedKeys.Accessor authorizedKeys;
|
||||
private final boolean sshEnabled;
|
||||
|
||||
@Inject
|
||||
public AccountOperationsImpl(
|
||||
Accounts accounts,
|
||||
@ServerInitiated AccountsUpdate accountsUpdate,
|
||||
Sequences seq,
|
||||
SshKeyCache sshKeyCache,
|
||||
VersionedAuthorizedKeys.Accessor authorizedKeys,
|
||||
// TODO(ekempin,aliceks): Find a way not to use this config parameter here. Ideally,
|
||||
// completely factor out SSH from this class.
|
||||
@SshEnabled boolean sshEnabled) {
|
||||
this.accounts = accounts;
|
||||
this.accountsUpdate = accountsUpdate;
|
||||
this.seq = seq;
|
||||
this.sshKeyCache = sshKeyCache;
|
||||
this.authorizedKeys = authorizedKeys;
|
||||
this.sshEnabled = sshEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MoreAccountOperations account(Account.Id accountId) {
|
||||
return new MoreAccountOperationsImpl(accountId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestAccountCreation.Builder newAccount() {
|
||||
return TestAccountCreation.builder(this::createAccount);
|
||||
}
|
||||
|
||||
private TestAccount createAccount(TestAccountCreation accountCreation) throws Exception {
|
||||
AccountsUpdate.AccountUpdater accountUpdater =
|
||||
(account, updateBuilder) ->
|
||||
fillBuilder(updateBuilder, accountCreation, account.getAccount().getId());
|
||||
AccountState createdAccount = createAccount(accountUpdater);
|
||||
|
||||
TestAccount.Builder builder = toTestAccount(createdAccount);
|
||||
Optional<String> userName = createdAccount.getUserName();
|
||||
if (sshEnabled && userName.isPresent()) {
|
||||
addSshKeyPair(builder, createdAccount.getAccount(), userName.get());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private AccountState createAccount(AccountsUpdate.AccountUpdater accountUpdater)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
Account.Id accountId = new Account.Id(seq.nextAccountId());
|
||||
return accountsUpdate.insert("Create Test Account", accountId, accountUpdater);
|
||||
}
|
||||
|
||||
private static void fillBuilder(
|
||||
InternalAccountUpdate.Builder builder,
|
||||
TestAccountCreation accountCreation,
|
||||
Account.Id accountId) {
|
||||
accountCreation.fullname().ifPresent(builder::setFullName);
|
||||
accountCreation.preferredEmail().ifPresent(e -> setPreferredEmail(builder, accountId, e));
|
||||
String httpPassword = accountCreation.httpPassword().orElse(null);
|
||||
accountCreation.username().ifPresent(u -> setUsername(builder, accountId, u, httpPassword));
|
||||
accountCreation.status().ifPresent(builder::setStatus);
|
||||
}
|
||||
|
||||
private void addSshKeyPair(TestAccount.Builder builder, Account account, String username)
|
||||
throws Exception {
|
||||
KeyPair sshKey = genSshKey();
|
||||
authorizedKeys.addKey(account.getId(), publicKey(sshKey, account.getPreferredEmail()));
|
||||
sshKeyCache.evict(username);
|
||||
builder.sshKeyPair(sshKey);
|
||||
}
|
||||
|
||||
private static KeyPair genSshKey() throws JSchException {
|
||||
JSch jsch = new JSch();
|
||||
return KeyPair.genKeyPair(jsch, KeyPair.RSA);
|
||||
}
|
||||
|
||||
private static String publicKey(KeyPair sshKey, String comment)
|
||||
throws UnsupportedEncodingException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
sshKey.writePublicKey(out, comment);
|
||||
return out.toString(US_ASCII.name()).trim();
|
||||
}
|
||||
|
||||
private static TestAccount.Builder toTestAccount(AccountState accountState) {
|
||||
Account createdAccount = accountState.getAccount();
|
||||
return TestAccount.builder()
|
||||
.accountId(createdAccount.getId())
|
||||
.preferredEmail(Optional.ofNullable(createdAccount.getPreferredEmail()))
|
||||
.fullname(Optional.ofNullable(createdAccount.getFullName()))
|
||||
.username(accountState.getUserName());
|
||||
}
|
||||
|
||||
private static InternalAccountUpdate.Builder setPreferredEmail(
|
||||
InternalAccountUpdate.Builder builder, Account.Id accountId, String preferredEmail) {
|
||||
return builder
|
||||
.setPreferredEmail(preferredEmail)
|
||||
.addExternalId(ExternalId.createEmail(accountId, preferredEmail));
|
||||
}
|
||||
|
||||
private static InternalAccountUpdate.Builder setUsername(
|
||||
InternalAccountUpdate.Builder builder,
|
||||
Account.Id accountId,
|
||||
String username,
|
||||
String httpPassword) {
|
||||
return builder.addExternalId(ExternalId.createUsername(username, accountId, httpPassword));
|
||||
}
|
||||
|
||||
private class MoreAccountOperationsImpl implements MoreAccountOperations {
|
||||
private final Account.Id accountId;
|
||||
|
||||
MoreAccountOperationsImpl(Account.Id accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() throws Exception {
|
||||
return accounts.get(accountId).isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestAccount get() throws Exception {
|
||||
AccountState account =
|
||||
accounts
|
||||
.get(accountId)
|
||||
.orElseThrow(
|
||||
() -> new IllegalStateException("Tried to get non-existing test account"));
|
||||
return toTestAccount(account).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestAccountUpdate.Builder forUpdate() {
|
||||
return TestAccountUpdate.builder(this::updateAccount);
|
||||
}
|
||||
|
||||
private TestAccount updateAccount(TestAccountUpdate accountUpdate)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
AccountsUpdate.AccountUpdater accountUpdater =
|
||||
(account, updateBuilder) -> fillBuilder(updateBuilder, accountUpdate, accountId);
|
||||
Optional<AccountState> updatedAccount = updateAccount(accountUpdater);
|
||||
checkState(updatedAccount.isPresent(), "Tried to update non-existing test account");
|
||||
return toTestAccount(updatedAccount.get()).build();
|
||||
}
|
||||
|
||||
private Optional<AccountState> updateAccount(AccountsUpdate.AccountUpdater accountUpdater)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
return accountsUpdate.update("Update Test Account", accountId, accountUpdater);
|
||||
}
|
||||
|
||||
private void fillBuilder(
|
||||
InternalAccountUpdate.Builder builder,
|
||||
TestAccountUpdate accountUpdate,
|
||||
Account.Id accountId) {
|
||||
accountUpdate.fullname().ifPresent(builder::setFullName);
|
||||
accountUpdate.preferredEmail().ifPresent(e -> setPreferredEmail(builder, accountId, e));
|
||||
String httpPassword = accountUpdate.httpPassword().orElse(null);
|
||||
accountUpdate.username().ifPresent(u -> setUsername(builder, accountId, u, httpPassword));
|
||||
accountUpdate.status().ifPresent(builder::setStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.testsuite.account;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.jcraft.jsch.KeyPair;
|
||||
import java.util.Optional;
|
||||
|
||||
@AutoValue
|
||||
public abstract class TestAccount {
|
||||
public abstract Account.Id accountId();
|
||||
|
||||
public abstract Optional<String> fullname();
|
||||
|
||||
public abstract Optional<String> preferredEmail();
|
||||
|
||||
public abstract Optional<String> username();
|
||||
|
||||
// TODO(ekempin,aliceks): Factor out SSH key handling from the class.
|
||||
public abstract Optional<KeyPair> sshKeyPair();
|
||||
|
||||
static Builder builder() {
|
||||
return new AutoValue_TestAccount.Builder();
|
||||
}
|
||||
|
||||
@AutoValue.Builder
|
||||
abstract static class Builder {
|
||||
abstract Builder accountId(Account.Id accountId);
|
||||
|
||||
abstract Builder fullname(Optional<String> fullname);
|
||||
|
||||
abstract Builder preferredEmail(Optional<String> fullname);
|
||||
|
||||
abstract Builder username(Optional<String> username);
|
||||
|
||||
abstract Builder sshKeyPair(KeyPair keyPair);
|
||||
|
||||
abstract TestAccount build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.testsuite.account;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
|
||||
import java.util.Optional;
|
||||
|
||||
@AutoValue
|
||||
public abstract class TestAccountCreation {
|
||||
public abstract Optional<String> fullname();
|
||||
|
||||
public abstract Optional<String> httpPassword();
|
||||
|
||||
public abstract Optional<String> preferredEmail();
|
||||
|
||||
public abstract Optional<String> username();
|
||||
|
||||
public abstract Optional<String> status();
|
||||
|
||||
abstract ThrowingFunction<TestAccountCreation, TestAccount> accountCreator();
|
||||
|
||||
public static Builder builder(ThrowingFunction<TestAccountCreation, TestAccount> accountCreator) {
|
||||
return new AutoValue_TestAccountCreation.Builder()
|
||||
.accountCreator(accountCreator)
|
||||
.httpPassword("http-pass");
|
||||
}
|
||||
|
||||
@AutoValue.Builder
|
||||
public abstract static class Builder {
|
||||
public abstract Builder fullname(String fullname);
|
||||
|
||||
public Builder clearFullname() {
|
||||
return fullname("");
|
||||
}
|
||||
|
||||
public abstract Builder httpPassword(String httpPassword);
|
||||
|
||||
public Builder clearHttpPassword() {
|
||||
return httpPassword("");
|
||||
}
|
||||
|
||||
public abstract Builder preferredEmail(String preferredEmail);
|
||||
|
||||
public Builder clearPreferredEmail() {
|
||||
return preferredEmail("");
|
||||
}
|
||||
|
||||
public abstract Builder username(String username);
|
||||
|
||||
public Builder clearUsername() {
|
||||
return username("");
|
||||
}
|
||||
|
||||
public abstract Builder status(String status);
|
||||
|
||||
public Builder clearStatus() {
|
||||
return status("");
|
||||
}
|
||||
|
||||
abstract Builder accountCreator(
|
||||
ThrowingFunction<TestAccountCreation, TestAccount> accountCreator);
|
||||
|
||||
abstract TestAccountCreation autoBuild();
|
||||
|
||||
public TestAccount create() throws Exception {
|
||||
TestAccountCreation accountUpdate = autoBuild();
|
||||
return accountUpdate.accountCreator().apply(accountUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.testsuite.account;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
|
||||
import java.util.Optional;
|
||||
|
||||
@AutoValue
|
||||
public abstract class TestAccountUpdate {
|
||||
public abstract Optional<String> fullname();
|
||||
|
||||
public abstract Optional<String> httpPassword();
|
||||
|
||||
public abstract Optional<String> preferredEmail();
|
||||
|
||||
public abstract Optional<String> username();
|
||||
|
||||
public abstract Optional<String> status();
|
||||
|
||||
abstract ThrowingFunction<TestAccountUpdate, TestAccount> accountUpdater();
|
||||
|
||||
public static Builder builder(ThrowingFunction<TestAccountUpdate, TestAccount> accountUpdater) {
|
||||
return new AutoValue_TestAccountUpdate.Builder()
|
||||
.accountUpdater(accountUpdater)
|
||||
.httpPassword("http-pass");
|
||||
}
|
||||
|
||||
@AutoValue.Builder
|
||||
public abstract static class Builder {
|
||||
public abstract Builder fullname(String fullname);
|
||||
|
||||
public Builder clearFullname() {
|
||||
return fullname("");
|
||||
}
|
||||
|
||||
public abstract Builder httpPassword(String httpPassword);
|
||||
|
||||
public Builder clearHttpPassword() {
|
||||
return httpPassword("");
|
||||
}
|
||||
|
||||
public abstract Builder preferredEmail(String preferredEmail);
|
||||
|
||||
public Builder clearPreferredEmail() {
|
||||
return preferredEmail("");
|
||||
}
|
||||
|
||||
public abstract Builder username(String username);
|
||||
|
||||
public Builder clearUsername() {
|
||||
return username("");
|
||||
}
|
||||
|
||||
public abstract Builder status(String status);
|
||||
|
||||
public Builder clearStatus() {
|
||||
return status("");
|
||||
}
|
||||
|
||||
abstract Builder accountUpdater(
|
||||
ThrowingFunction<TestAccountUpdate, TestAccount> accountUpdater);
|
||||
|
||||
abstract TestAccountUpdate autoBuild();
|
||||
|
||||
public TestAccount update() throws Exception {
|
||||
TestAccountUpdate accountUpdate = autoBuild();
|
||||
return accountUpdate.accountUpdater().apply(accountUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user