Search in sources :

Example 1 with CandlepinRequestScope

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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CandlepinRequestScope(org.candlepin.guice.CandlepinRequestScope) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) TestingInterceptor(org.candlepin.TestingInterceptor) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule) ResourceLocatorMap(org.candlepin.resteasy.ResourceLocatorMap)

Aggregations

AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 TestingInterceptor (org.candlepin.TestingInterceptor)1 CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)1 CandlepinRequestScope (org.candlepin.guice.CandlepinRequestScope)1 ResourceLocatorMap (org.candlepin.resteasy.ResourceLocatorMap)1