Search in sources :

Example 1 with Bootstrap

use of ninja.Bootstrap in project ninja by ninjaframework.

the class NinjaServletListener method getInjector.

/**
     * Getting the injector is done via double locking in conjuction
     * with volatile keyword for thread safety.
     * See also: http://en.wikipedia.org/wiki/Double-checked_locking
     * 
     * @return The injector for this application.
     */
@Override
public Injector getInjector() {
    // fetch instance variable into method, so that we access the volatile
    // global variable only once - that's better performance wise.
    Bootstrap ninjaBootstrapLocal = ninjaBootstrap;
    if (ninjaBootstrapLocal == null) {
        synchronized (this) {
            ninjaBootstrapLocal = ninjaBootstrap;
            if (ninjaBootstrapLocal == null) {
                // if properties 
                if (ninjaProperties == null) {
                    ninjaProperties = new NinjaPropertiesImpl(NinjaModeHelper.determineModeFromSystemPropertiesOrProdIfNotSet());
                }
                ninjaBootstrap = createNinjaBootstrap(ninjaProperties, contextPath);
                ninjaBootstrapLocal = ninjaBootstrap;
            }
        }
    }
    return ninjaBootstrapLocal.getInjector();
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Bootstrap(ninja.Bootstrap)

Example 2 with Bootstrap

use of ninja.Bootstrap in project ninja by ninjaframework.

the class NinjaServletBootstrapTest method userSuppliedServletModuleInShiftedConfDirectory.

@Test
public void userSuppliedServletModuleInShiftedConfDirectory() {
    ninjaPropertiesImpl = Mockito.spy(new NinjaPropertiesImpl(NinjaMode.test));
    Mockito.when(ninjaPropertiesImpl.get(NinjaConstant.APPLICATION_MODULES_BASE_PACKAGE)).thenReturn("custom_base_package");
    Bootstrap bootstrap = new NinjaServletBootstrap(ninjaPropertiesImpl);
    bootstrap.boot();
    assertThat("Ninja Boostrap process picks up user supplied Guice servlet module in custom_base_package.conf.ServletModule", bootstrap.getInjector().getInstance(custom_base_package.conf.ServletModule.DummyInterfaceForTesting.class), is(instanceOf(custom_base_package.conf.ServletModule.DummyClassForTesting.class)));
    Router router = bootstrap.getInjector().getInstance(Router.class);
    Route route = router.getRouteFor("GET", "/custom_base_package");
    assertThat("custom_base_package.conf.Routes initialized properly. We get back the class we defined by the route.", route.getControllerClass(), is(instanceOf(controller.DummyControllerForTesting.class.getClass())));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Bootstrap(ninja.Bootstrap) Router(ninja.Router) Route(ninja.Route) Test(org.junit.Test)

Example 3 with Bootstrap

use of ninja.Bootstrap in project ninja by ninjaframework.

the class NinjaServletBootstrapTest method userSuppliedServletModuleInConfDirectory.

@Test
public void userSuppliedServletModuleInConfDirectory() {
    ninjaPropertiesImpl = new NinjaPropertiesImpl(NinjaMode.test);
    Bootstrap bootstrap = new NinjaServletBootstrap(ninjaPropertiesImpl);
    bootstrap.boot();
    assertThat(bootstrap.getInjector().getInstance(Context.class), is(instanceOf(NinjaServletContext.class)));
    assertThat("Ninja Boostrap process picks up user supplied Guice servlet module in conf.ServletModule", bootstrap.getInjector().getInstance(conf.ServletModule.DummyInterfaceForTesting.class), is(instanceOf(conf.ServletModule.DummyClassForTesting.class)));
    Router router = bootstrap.getInjector().getInstance(Router.class);
    Route route = router.getRouteFor("GET", "/");
    assertThat("conf.Routes initialized properly. We get back the class we defined by the route.", route.getControllerClass(), is(instanceOf(controller.DummyControllerForTesting.class.getClass())));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Context(ninja.Context) Bootstrap(ninja.Bootstrap) Router(ninja.Router) Route(ninja.Route) Test(org.junit.Test)

Aggregations

Bootstrap (ninja.Bootstrap)3 NinjaPropertiesImpl (ninja.utils.NinjaPropertiesImpl)3 Route (ninja.Route)2 Router (ninja.Router)2 Test (org.junit.Test)2 Context (ninja.Context)1