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();
}
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())));
}
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())));
}