Search in sources :

Example 1 with NinjaPropertiesImpl

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);
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl)

Example 2 with NinjaPropertiesImpl

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();
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Bootstrap(ninja.Bootstrap)

Example 3 with NinjaPropertiesImpl

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

        ;
    };
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) ParamParser(ninja.params.ParamParser) ParamParsers(ninja.params.ParamParsers) Injector(com.google.inject.Injector) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) AbstractModule(com.google.inject.AbstractModule)

Example 4 with NinjaPropertiesImpl

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())));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Bootstrap(ninja.Bootstrap) Router(ninja.Router) Route(ninja.Route) Test(org.junit.Test)

Example 5 with NinjaPropertiesImpl

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())));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Context(ninja.Context) Bootstrap(ninja.Bootstrap) Router(ninja.Router) Route(ninja.Route) Test(org.junit.Test)

Aggregations

NinjaPropertiesImpl (ninja.utils.NinjaPropertiesImpl)27 Test (org.junit.Test)19 Injector (com.google.inject.Injector)13 BaseAndClassicModules (ninja.BaseAndClassicModules)9 Before (org.junit.Before)4 Bootstrap (ninja.Bootstrap)3 Route (ninja.Route)3 RouteBuilderImpl (ninja.RouteBuilderImpl)3 Router (ninja.Router)3 RouterImpl (ninja.RouterImpl)3 Routes (testapplication.conf.Routes)3 AbstractModule (com.google.inject.AbstractModule)2 LangImpl (ninja.i18n.LangImpl)2 ParamParser (ninja.params.ParamParser)2 Multibinder (com.google.inject.multibindings.Multibinder)1 URI (java.net.URI)1 Context (ninja.Context)1 Cache (ninja.cache.Cache)1 JpaInitializer (ninja.jpa.JpaInitializer)1 JpaModule (ninja.jpa.JpaModule)1