Search in sources :

Example 1 with ArchaiusModule

use of com.netflix.archaius.guice.ArchaiusModule in project eureka by Netflix.

the class EurekaClientModuleConfigurationTest method testBindEurekaInstanceConfigFactory.

@Test
public void testBindEurekaInstanceConfigFactory() {
    final EurekaInstanceConfigFactory mockFactory = Mockito.mock(EurekaInstanceConfigFactory.class);
    final EurekaInstanceConfig mockConfig = Mockito.mock(EurekaInstanceConfig.class);
    final ApplicationInfoManager mockInfoManager = Mockito.mock(ApplicationInfoManager.class);
    Mockito.when(mockFactory.get()).thenReturn(mockConfig);
    LifecycleInjector injector = InjectorBuilder.fromModules(new ArchaiusModule(), new EurekaClientModule() {

        @Override
        protected void configureEureka() {
            bindEurekaInstanceConfigFactory().toInstance(mockFactory);
        }
    }).overrideWith(new AbstractModule() {

        @Override
        protected void configure() {
            // this is usually bound as an eager singleton that can trigger other parts to
            // initialize, so do an override to a mock here to prevent that.
            bind(ApplicationInfoManager.class).toInstance(mockInfoManager);
        }
    }).createInjector();
    EurekaInstanceConfig config = injector.getInstance(EurekaInstanceConfig.class);
    Assert.assertEquals(mockConfig, config);
}
Also used : EurekaInstanceConfigFactory(com.netflix.appinfo.providers.EurekaInstanceConfigFactory) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) ArchaiusModule(com.netflix.archaius.guice.ArchaiusModule) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) LifecycleInjector(com.netflix.governator.LifecycleInjector) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Aggregations

AbstractModule (com.google.inject.AbstractModule)1 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)1 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)1 EurekaInstanceConfigFactory (com.netflix.appinfo.providers.EurekaInstanceConfigFactory)1 ArchaiusModule (com.netflix.archaius.guice.ArchaiusModule)1 LifecycleInjector (com.netflix.governator.LifecycleInjector)1 Test (org.junit.Test)1