Search in sources :

Example 1 with FakeRealm

use of com.google.gerrit.server.account.FakeRealm 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();
}
Also used : EnablePeerIPInReflogRecord(com.google.gerrit.server.config.EnablePeerIPInReflogRecord) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) Account(com.google.gerrit.entities.Account) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) CanonicalWebUrl(com.google.gerrit.server.config.CanonicalWebUrl) AbstractModule(com.google.inject.AbstractModule) AccountCache(com.google.gerrit.server.account.AccountCache) FakeAccountCache(com.google.gerrit.testing.FakeAccountCache) FakeRealm(com.google.gerrit.server.account.FakeRealm) Injector(com.google.inject.Injector) FakeAccountCache(com.google.gerrit.testing.FakeAccountCache) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) FakeRealm(com.google.gerrit.server.account.FakeRealm) Realm(com.google.gerrit.server.account.Realm) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

Account (com.google.gerrit.entities.Account)1 AccountCache (com.google.gerrit.server.account.AccountCache)1 FakeRealm (com.google.gerrit.server.account.FakeRealm)1 Realm (com.google.gerrit.server.account.Realm)1 AnonymousCowardName (com.google.gerrit.server.config.AnonymousCowardName)1 CanonicalWebUrl (com.google.gerrit.server.config.CanonicalWebUrl)1 EnablePeerIPInReflogRecord (com.google.gerrit.server.config.EnablePeerIPInReflogRecord)1 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)1 SystemGroupBackend (com.google.gerrit.server.group.SystemGroupBackend)1 FakeAccountCache (com.google.gerrit.testing.FakeAccountCache)1 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1