use of com.google.inject.AbstractModule in project eureka by Netflix.
the class EurekaModuleTest method setUp.
@Before
public void setUp() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("eureka.region", "default");
ConfigurationManager.getConfigInstance().setProperty("eureka.shouldFetchRegistry", "false");
ConfigurationManager.getConfigInstance().setProperty("eureka.registration.enabled", "false");
ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:8080/eureka/v2");
injector = InjectorBuilder.fromModule(new EurekaModule()).overrideWith(new AbstractModule() {
@Override
protected void configure() {
// the default impl of EurekaInstanceConfig is CloudInstanceConfig, which we only want in an AWS
// environment. Here we override that by binding MyDataCenterInstanceConfig to EurekaInstanceConfig.
bind(EurekaInstanceConfig.class).toProvider(MyDataCenterInstanceConfigProvider.class).in(Scopes.SINGLETON);
}
}).createInjector();
}
use of com.google.inject.AbstractModule in project ribbon by Netflix.
the class RxMovieProxyExampleTest method shouldBindCustomClientConfigFactory.
@Test
public void shouldBindCustomClientConfigFactory() {
ConfigurationManager.getConfigInstance().setProperty(MovieService.class.getSimpleName() + ".MyConfig.listOfServers", "localhost:" + port);
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(RibbonResourceFactory.class).to(DefaultResourceFactory.class).in(Scopes.SINGLETON);
bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON);
bind(AnnotationProcessorsProvider.class).to(DefaultAnnotationProcessorsProvider.class).in(Scopes.SINGLETON);
bind(ClientConfigFactory.class).to(MyClientConfigFactory.class).in(Scopes.SINGLETON);
}
}, new AbstractModule() {
@Override
protected void configure() {
bind(MovieService.class).toProvider(new RibbonResourceProvider<MovieService>(MovieService.class)).asEagerSingleton();
}
});
RxMovieProxyExample example = injector.getInstance(RxMovieProxyExample.class);
assertTrue(example.runExample());
}
use of com.google.inject.AbstractModule in project ninja by ninjaframework.
the class FileItemProviderImpl2 method init.
public void init(final Class<? extends FileItemProvider> fileItemProviderClass) throws IOException, ServletException {
//default setup for httpServlet request.
//According to servlet spec the following will be returned:
when(httpServletRequest.getContextPath()).thenReturn("");
when(httpServletRequest.getRequestURI()).thenReturn("/");
when(httpServletRequest.getContentType()).thenReturn("multipart/form-data");
when(httpServletRequest.getMethod()).thenReturn("POST");
NinjaPropertiesImpl properties = new NinjaPropertiesImpl(NinjaMode.test);
this.ninjaProperties = properties;
final FileItemIterator fileItemIterator = makeFileItemsIterator();
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(NinjaProperties.class).toInstance(ninjaProperties);
bind(FileItemProvider.class).to(fileItemProviderClass);
}
});
context = new NinjaServletContext(bodyParserEngineManager, flashCookie, ninjaProperties, resultHandler, sessionCookie, validation, injector, new ParamParsers(new HashSet<ParamParser>())) {
public FileItemIterator getFileItemIterator() {
return fileItemIterator;
}
;
};
}
use of com.google.inject.AbstractModule in project ninja by ninjaframework.
the class LifecycleSupportTest method serviceShouldBeStartedIfExplicitlyBoundAndSingleton.
@Test
public void serviceShouldBeStartedIfExplicitlyBoundAndSingleton() {
Injector injector = createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(MockSingletonService.class);
}
});
start(injector);
assertThat(MockSingletonService.started, equalTo(1));
}
use of com.google.inject.AbstractModule in project ninja by ninjaframework.
the class LifecycleSupportTest method providedSingletonDisposableShouldBeDisposed.
@Test
public void providedSingletonDisposableShouldBeDisposed() {
Injector injector = createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@Provides
@Singleton
public MockSingletonService provide() {
return new MockSingletonService();
}
});
start(injector);
stop(injector);
assertThat(MockSingletonService.disposed, equalTo(1));
}
Aggregations