use of org.candlepin.guice.CandlepinRequestScope in project candlepin by candlepin.
the class DatabaseTestFixture method init.
public void init(boolean beginTransaction) throws Exception {
this.config = new CandlepinCommonTestConfig();
Module testingModule = new TestingModules.StandardTest(this.config);
this.injector = parentInjector.createChildInjector(Modules.override(testingModule).with(getGuiceOverrideModule()));
locatorMap = this.injector.getInstance(ResourceLocatorMap.class);
locatorMap.init();
securityInterceptor = this.injector.getInstance(TestingInterceptor.class);
cpRequestScope = injector.getInstance(CandlepinRequestScope.class);
// Because all candlepin operations are running in the CandlepinRequestScope
// we'll force the instance creations to be done inside the scope.
// Exit the scope to make sure that it is clean before starting the test.
cpRequestScope.exit();
cpRequestScope.enter();
this.injector.injectMembers(this);
dateSource = (DateSourceForTesting) injector.getInstance(DateSource.class);
dateSource.currentDate(TestDateUtil.date(2010, 1, 1));
HttpServletRequest req = parentInjector.getInstance(HttpServletRequest.class);
when(req.getAttribute("username")).thenReturn("mock_user");
this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
if (beginTransaction) {
this.beginTransaction();
}
}
Aggregations