use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class OutgoingEmail method getFromLine.
protected String getFromLine() {
final Account account = args.accountCache.get(fromId).getAccount();
final String name = account.getFullName();
final String email = account.getPreferredEmail();
StringBuilder f = new StringBuilder();
if ((name != null && !name.isEmpty()) || (email != null && !email.isEmpty())) {
f.append("From");
if (name != null && !name.isEmpty()) {
f.append(" ").append(name);
}
if (email != null && !email.isEmpty()) {
f.append(" <").append(email).append(">");
}
f.append(":\n\n");
}
return f.toString();
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class IdentifiedUserTest method setUp.
@Before
public void setUp() throws Exception {
final FakeAccountCache accountCache = new FakeAccountCache();
final Realm mockRealm = new FakeRealm() {
HashSet<String> emails = new HashSet<>(Arrays.asList(TEST_CASES));
@Override
public boolean hasEmailAddress(IdentifiedUser who, String email) {
return emails.contains(email);
}
@Override
public Set<String> getEmailAddresses(IdentifiedUser who) {
return emails;
}
};
AbstractModule mod = new AbstractModule() {
@Override
protected void configure() {
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class).toInstance(Boolean.FALSE);
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(config);
bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
bind(AccountCache.class).toInstance(accountCache);
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
bind(CapabilityControl.Factory.class).toProvider(Providers.<CapabilityControl.Factory>of(null));
bind(Realm.class).toInstance(mockRealm);
}
};
Injector injector = Guice.createInjector(mod);
injector.injectMembers(this);
Account account = new Account(new Account.Id(1), TimeUtil.nowTs());
Account.Id ownerId = account.getId();
identifiedUser = identifiedUserFactory.create(ownerId);
/* Trigger identifiedUser to load the email addresses from mockRealm */
identifiedUser.getEmailAddresses();
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class WatchConfigTest method parseInvalidWatchConfig.
@Test
public void parseInvalidWatchConfig() throws Exception {
Config cfg = new Config();
cfg.fromText("[project \"myProject\"]\n" + " notify = * [ALL_COMMENTS, NEW_PATCHSETS]\n" + " notify = branch:master [INVALID, NEW_CHANGES]\n" + "[project \"otherProject\"]\n" + " notify = [NEW_PATCHSETS]\n");
WatchConfig.parse(new Account.Id(1000000), cfg, this);
assertThat(validationErrors).hasSize(1);
assertThat(validationErrors.get(0).getMessage()).isEqualTo("watch.config: Invalid notify type INVALID in project watch of" + " account 1000000 for project myProject: branch:master" + " [INVALID, NEW_CHANGES]");
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method createAccount.
private Account.Id createAccount(String username, String fullName, String email, boolean active) throws Exception {
try (ManualRequestContext ctx = oneOffRequestContext.open()) {
Account.Id id = accountManager.authenticate(AuthRequest.forUser(username)).getAccountId();
if (email != null) {
accountManager.link(id, AuthRequest.forEmail(email));
}
Account a = db.accounts().get(id);
a.setFullName(fullName);
a.setPreferredEmail(email);
a.setActive(active);
db.accounts().update(ImmutableList.of(a));
accountCache.evict(id);
return id;
}
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method setUpDatabase.
protected void setUpDatabase() throws Exception {
try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
schemaCreator.create(underlyingDb);
}
db = schemaFactory.open();
userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
Account userAccount = db.accounts().get(userId);
String email = "user@example.com";
externalIdsUpdate.create().insert(ExternalId.createEmail(userId, email));
userAccount.setPreferredEmail(email);
db.accounts().update(ImmutableList.of(userAccount));
user = userFactory.create(userId);
requestContext.setContext(newRequestContext(userAccount.getId()));
}
Aggregations