use of ninja.utils.NinjaPropertiesImpl in project ninja by ninjaframework.
the class NinjaRouterTest method startServer.
/**
* Start the server and load the routes.
*/
public void startServer(NinjaMode ninjaMode) {
if (ninjaMode == null) {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaModeHelper.determineModeFromSystemPropertiesOrProdIfNotSet());
ninjaBootup = new Bootstrap(ninjaProperties);
} else {
// in this case servletContext can be null
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(ninjaMode);
ninjaBootup = new Bootstrap(ninjaProperties);
}
ninjaBootup.boot();
router = ninjaBootup.getInjector().getInstance(Router.class);
}
use of ninja.utils.NinjaPropertiesImpl 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.utils.NinjaPropertiesImpl in project ninja by ninjaframework.
the class FileItemProviderImpl2 method init.
public void init(final Class<? extends FileItemProvider> fileItemProviderClass) throws IOException, ServletException {
//default setup for httpServlet request.
//According to servlet spec the following will be returned:
when(httpServletRequest.getContextPath()).thenReturn("");
when(httpServletRequest.getRequestURI()).thenReturn("/");
when(httpServletRequest.getContentType()).thenReturn("multipart/form-data");
when(httpServletRequest.getMethod()).thenReturn("POST");
NinjaPropertiesImpl properties = new NinjaPropertiesImpl(NinjaMode.test);
this.ninjaProperties = properties;
final FileItemIterator fileItemIterator = makeFileItemsIterator();
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(NinjaProperties.class).toInstance(ninjaProperties);
bind(FileItemProvider.class).to(fileItemProviderClass);
}
});
context = new NinjaServletContext(bodyParserEngineManager, flashCookie, ninjaProperties, resultHandler, sessionCookie, validation, injector, new ParamParsers(new HashSet<ParamParser>())) {
public FileItemIterator getFileItemIterator() {
return fileItemIterator;
}
;
};
}
use of ninja.utils.NinjaPropertiesImpl 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.utils.NinjaPropertiesImpl 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())));
}
Aggregations