use of com.google.gerrit.server.account.AccountCache in project gerrit by GerritCodeReview.
the class AbstractChangeNotesTest method setUpTestEnvironment.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Before
public void setUpTestEnvironment() throws Exception {
setTimeForTesting();
serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", Date.from(TimeUtil.now()), TZ);
project = Project.nameKey("test-project");
repoManager = new InMemoryRepositoryManager();
repo = repoManager.createRepository(project);
tr = new TestRepository<>(repo);
rw = tr.getRevWalk();
accountCache = new FakeAccountCache();
Account.Builder co = Account.builder(Account.id(1), TimeUtil.now());
co.setFullName("Change Owner");
co.setPreferredEmail("change@owner.com");
accountCache.put(co.build());
Account.Builder ou = Account.builder(Account.id(2), TimeUtil.now());
ou.setFullName("Other Account");
ou.setPreferredEmail("other@account.com");
accountCache.put(ou.build());
assertableFanOutExecutor = new AssertableExecutorService();
injector = Guice.createInjector(new FactoryModule() {
@Override
public void configure() {
install(new GitModule());
install(new DefaultUrlFormatterModule());
install(NoteDbModule.forTest());
bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
bind(GitRepositoryManager.class).toInstance(repoManager);
bind(ProjectCache.class).to(NullProjectCache.class);
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(testConfig);
bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
bind(Boolean.class).annotatedWith(EnablePeerIPInReflogRecord.class).toInstance(Boolean.FALSE);
bind(Realm.class).to(FakeRealm.class);
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
bind(AccountCache.class).toInstance(accountCache);
bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toInstance(serverIdent);
bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
bind(MetricMaker.class).to(DisabledMetricMaker.class);
bind(ExecutorService.class).annotatedWith(FanOutExecutor.class).toInstance(assertableFanOutExecutor);
bind(ServiceUserClassifier.class).to(ServiceUserClassifier.NoOp.class);
bind(InternalChangeQuery.class).toProvider(() -> {
throw new UnsupportedOperationException();
});
bind(PatchSetApprovalUuidGenerator.class).to(TestPatchSetApprovalUuidGenerator.class);
}
});
injector.injectMembers(this);
repoManager.createRepository(allUsers);
changeOwner = userFactory.create(co.id());
otherUser = userFactory.create(ou.id());
otherUserId = otherUser.getAccountId();
internalUser = new InternalUser();
}
use of com.google.gerrit.server.account.AccountCache in project gerrit by GerritCodeReview.
the class AbstractChangeNotesTest method setUp.
@Before
public void setUp() throws Exception {
setTimeForTesting();
serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", TimeUtil.nowTs(), TZ);
project = new Project.NameKey("test-project");
repoManager = new InMemoryRepositoryManager();
repo = repoManager.createRepository(project);
tr = new TestRepository<>(repo);
rw = tr.getRevWalk();
accountCache = new FakeAccountCache();
Account co = new Account(new Account.Id(1), TimeUtil.nowTs());
co.setFullName("Change Owner");
co.setPreferredEmail("change@owner.com");
accountCache.put(co);
Account ou = new Account(new Account.Id(2), TimeUtil.nowTs());
ou.setFullName("Other Account");
ou.setPreferredEmail("other@account.com");
accountCache.put(ou);
injector = Guice.createInjector(new FactoryModule() {
@Override
public void configure() {
install(new GitModule());
install(NoteDbModule.forTest(testConfig));
bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
bind(NotesMigration.class).toInstance(MIGRATION);
bind(GitRepositoryManager.class).toInstance(repoManager);
bind(ProjectCache.class).toProvider(Providers.<ProjectCache>of(null));
bind(CapabilityControl.Factory.class).toProvider(Providers.<CapabilityControl.Factory>of(null));
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(testConfig);
bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class).toInstance(Boolean.FALSE);
bind(Realm.class).to(FakeRealm.class);
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
bind(AccountCache.class).toInstance(accountCache);
bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toInstance(serverIdent);
bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
bind(MetricMaker.class).to(DisabledMetricMaker.class);
bind(ReviewDb.class).toProvider(Providers.<ReviewDb>of(null));
}
});
injector.injectMembers(this);
repoManager.createRepository(allUsers);
changeOwner = userFactory.create(co.getId());
otherUser = userFactory.create(ou.getId());
otherUserId = otherUser.getAccountId();
internalUser = new InternalUser(null);
}
use of com.google.gerrit.server.account.AccountCache 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(EnablePeerIPInReflogRecord.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(Realm.class).toInstance(mockRealm);
}
};
Injector injector = Guice.createInjector(mod);
injector.injectMembers(this);
Account account = Account.builder(Account.id(1), TimeUtil.now()).setMetaId("1234567812345678123456781234567812345678").build();
Account.Id ownerId = account.id();
identifiedUser = identifiedUserFactory.create(ownerId);
/* Trigger identifiedUser to load the email addresses from mockRealm */
identifiedUser.getEmailAddresses();
}
use of com.google.gerrit.server.account.AccountCache in project gerrit by GerritCodeReview.
the class FromAddressGeneratorProviderTest method setUp.
@Before
public void setUp() throws Exception {
config = new Config();
ident = new PersonIdent("NAME", "e@email", 0, 0);
accountCache = mock(AccountCache.class);
}
Aggregations