use of keywhiz.test.ServiceContext in project keywhiz by square.
the class ServiceDataSourceModuleTest method dataSourcesAreSingletons.
@Test
public void dataSourcesAreSingletons() {
class Holder {
@Inject
ManagedDataSource readWrite;
@Inject
@Readonly
ManagedDataSource readonly;
}
Holder holder1 = new Holder();
Holder holder2 = new Holder();
ServiceContext context = ServiceContext.create();
Injector injector = Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment()), new ServiceDataSourceModule());
injector.injectMembers(holder1);
injector.injectMembers(holder2);
assertSame(holder1.readWrite, holder2.readWrite);
assertSame(holder1.readonly, holder2.readonly);
}
use of keywhiz.test.ServiceContext in project keywhiz by square.
the class KeywhizServiceTest method doesNotRecreateInjector.
@Test
public void doesNotRecreateInjector() {
ServiceContext context = ServiceContext.create();
KeywhizService service = context.getService();
service.ensureInjectorCreated(context.getConfig(), context.getEnvironment());
Injector first = service.getInjector();
service.ensureInjectorCreated(context.getConfig(), context.getEnvironment());
Injector second = service.getInjector();
assertSame(first, second);
}
use of keywhiz.test.ServiceContext in project keywhiz by square.
the class ContextModuleTest method injectsContext.
@Test
public void injectsContext() {
class Holder {
@Inject
KeywhizConfig keywhizConfig;
@Inject
Configuration config;
@Inject
Environment environment;
}
Holder holder = new Holder();
ServiceContext context = ServiceContext.create();
Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment())).injectMembers(holder);
assertSame(context.getConfig(), holder.keywhizConfig);
assertSame(context.getConfig(), holder.config);
assertSame(context.getEnvironment(), holder.environment);
}
Aggregations