Search in sources :

Example 16 with NinjaPropertiesImpl

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

the class BootstrapTest method testInitializeWithAllUserSpecifiedThingsInConfDirectory.

@Test
public void testInitializeWithAllUserSpecifiedThingsInConfDirectory() {
    ninjaPropertiesImpl = new NinjaPropertiesImpl(NinjaMode.test);
    Bootstrap bootstrap = new Bootstrap(ninjaPropertiesImpl);
    bootstrap.boot();
    assertThat("Ninja Boostrap process picks up user supplied conf.Ninja definition", bootstrap.getInjector().getInstance(ninja.Ninja.class), is(instanceOf(conf.Ninja.class)));
    assertThat("Ninja Boostrap process picks up user supplied Guice module in conf.Module", bootstrap.getInjector().getInstance(conf.Module.DummyInterfaceForTesting.class), is(instanceOf(conf.Module.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(com.example.controllers.DummyApplication.class.getClass())));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Test(org.junit.Test)

Example 17 with NinjaPropertiesImpl

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

the class MigrationEngineProviderTest method missingImplementationThrowsExceptionOnUseNotCreate.

@Test
public void missingImplementationThrowsExceptionOnUseNotCreate() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.MIGRATION_ENGINE_IMPLEMENTATION, "not_existing_implementation");
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    Provider<MigrationEngine> provider = injector.getProvider(MigrationEngine.class);
    // this will not work => we expect a runtime exception...
    thrown.expect(RuntimeException.class);
    MigrationEngine migrationEngine = injector.getInstance(MigrationEngine.class);
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 18 with NinjaPropertiesImpl

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

the class ControllerMethodInvokerWithDeprecatedValidationTest method setUp.

@Before
public void setUp() throws Exception {
    this.ninjaProperties = Mockito.spy(new NinjaPropertiesImpl(NinjaMode.test));
    this.lang = new LangImpl(this.ninjaProperties);
    this.validation = new ValidationImpl();
    when(this.context.getSession()).thenReturn(this.session);
    when(this.context.getFlashScope()).thenReturn(this.flash);
    when(this.context.getValidation()).thenReturn(this.validation);
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) LangImpl(ninja.i18n.LangImpl) Before(org.junit.Before)

Example 19 with NinjaPropertiesImpl

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

the class PostofficeProviderTest method defaultImplementation.

@Test
public void defaultImplementation() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(PostofficeConstant.postofficeImplementation, null);
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    PostofficeProvider postofficeProvider = injector.getInstance(PostofficeProvider.class);
    assertThat(postofficeProvider.get(), instanceOf(PostofficeMockImpl.class));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) PostofficeMockImpl(ninja.postoffice.mock.PostofficeMockImpl) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 20 with NinjaPropertiesImpl

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

the class CacheProviderTest method verifySingletonProviderAndInstance.

@Test
public void verifySingletonProviderAndInstance() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, CacheMockImpl.class.getCanonicalName());
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    CacheProvider cacheProvider = injector.getInstance(CacheProvider.class);
    // cache provider should be a singleton
    assertThat(cacheProvider, sameInstance(injector.getInstance(CacheProvider.class)));
    assertThat(cacheProvider, sameInstance(injector.getInstance(CacheProvider.class)));
    Cache cache = cacheProvider.get();
    // cache should be a singleton
    assertThat(cache, sameInstance(cacheProvider.get()));
    assertThat(cache, sameInstance(injector.getInstance(Cache.class)));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) 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