Search in sources :

Example 21 with NinjaPropertiesImpl

use of ninja.utils.NinjaPropertiesImpl in project ninja by ninjaframework.

the class CacheProviderTest method defaultImplementation.

@Test
public void defaultImplementation() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, null);
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    CacheProvider cacheProvider = injector.getInstance(CacheProvider.class);
    assertThat(cacheProvider.get(), instanceOf(CacheEhCacheImpl.class));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 22 with NinjaPropertiesImpl

use of ninja.utils.NinjaPropertiesImpl in project ninja by ninjaframework.

the class CacheProviderTest method configuredImplementation.

@Test
public void configuredImplementation() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, CacheMemcachedImpl.class.getName());
    // just a dummy to test that loading works
    ninjaProperties.setProperty(NinjaConstant.MEMCACHED_HOST, "127.0.0.1:1234");
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    Provider<Cache> cacheProvider = injector.getProvider(Cache.class);
    assertThat(cacheProvider.get(), instanceOf(CacheMemcachedImpl.class));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 23 with NinjaPropertiesImpl

use of ninja.utils.NinjaPropertiesImpl in project ninja by ninjaframework.

the class NinjaServletListenerTest method testCreatingInjectorWithCustomModulesPackageWorks.

@Test
public void testCreatingInjectorWithCustomModulesPackageWorks() {
    // setup stuff
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.APPLICATION_MODULES_BASE_PACKAGE, "ninja.servlet");
    NinjaServletListener ninjaServletListener = new NinjaServletListener();
    ninjaServletListener.setNinjaProperties(ninjaProperties);
    // start the injector:
    ninjaServletListener.contextInitialized(servletContextEvent);
    // test stuff
    Injector injector = ninjaServletListener.getInjector();
    Router router = injector.getInstance((Router.class));
    //router is initialized otherwise there will be exception that routes isn't compiled
    router.getRouteFor("GET", "/");
    //validate that main application module is initialized
    Boolean mainModuleConstant = injector.getInstance(Key.get(Boolean.class, Names.named(Module.TEST_CONSTANT_NAME)));
    assertThat(mainModuleConstant, is(true));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) Router(ninja.Router) Test(org.junit.Test)

Example 24 with NinjaPropertiesImpl

use of ninja.utils.NinjaPropertiesImpl in project ninja by ninjaframework.

the class NinjaServletListenerTest method testCreatingInjectorWithCustomNinjaPropertiesWorks.

@Test
public void testCreatingInjectorWithCustomNinjaPropertiesWorks() {
    // setup stuff
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty("key!", "value!");
    NinjaServletListener ninjaServletListener = new NinjaServletListener();
    ninjaServletListener.setNinjaProperties(ninjaProperties);
    // start the injector:
    ninjaServletListener.contextInitialized(servletContextEvent);
    // test stuff
    Injector injector = ninjaServletListener.getInjector();
    NinjaProperties ninjaPropertiesFromServer = injector.getInstance(NinjaProperties.class);
    assertThat(ninjaPropertiesFromServer.get("key!"), equalTo("value!"));
    // make sure we are using the context path from the serveltcontext here
    assertThat(ninjaProperties.getContextPath(), equalTo(CONTEXT_PATH));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) NinjaProperties(ninja.utils.NinjaProperties) Test(org.junit.Test)

Example 25 with NinjaPropertiesImpl

use of ninja.utils.NinjaPropertiesImpl in project ninja by ninjaframework.

the class NinjaDaoTestBase method initialize.

@Before
public final void initialize() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(ninjaMode);
    injector = Guice.createInjector(new JpaModule(ninjaProperties));
    jpaInitializer = injector.getInstance(JpaInitializer.class);
    jpaInitializer.start();
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) JpaInitializer(ninja.jpa.JpaInitializer) JpaModule(ninja.jpa.JpaModule) Before(org.junit.Before)

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