Search in sources :

Example 6 with NinjaPropertiesImpl

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

the class NinjaServletListenerTest method testThatSettingNinjaPropertiesTwiceDoesNotWork.

@Test
public void testThatSettingNinjaPropertiesTwiceDoesNotWork() {
    NinjaServletListener ninjaServletListener = new NinjaServletListener();
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    // first setting works
    ninjaServletListener.setNinjaProperties(ninjaProperties);
    boolean gotException = false;
    try {
        //setting the properties a second time does not work...
        ninjaServletListener.setNinjaProperties(ninjaProperties);
    } catch (IllegalStateException illegalStateException) {
        gotException = true;
    }
    assertThat(gotException, equalTo(true));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Test(org.junit.Test)

Example 7 with NinjaPropertiesImpl

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

the class PostofficeProviderTest method verifySingletonProviderAndInstance.

@Test
public void verifySingletonProviderAndInstance() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(PostofficeConstant.postofficeImplementation, null);
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    PostofficeProvider provider = injector.getInstance(PostofficeProvider.class);
    // cache provider should be a singleton
    assertThat(provider, sameInstance(injector.getInstance(PostofficeProvider.class)));
    assertThat(provider, sameInstance(injector.getInstance(PostofficeProvider.class)));
    Postoffice postoffice = provider.get();
    // cache should be a singleton
    assertThat(postoffice, sameInstance(provider.get()));
    assertThat(postoffice, sameInstance(injector.getInstance(Postoffice.class)));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 8 with NinjaPropertiesImpl

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

the class PostofficeProviderTest method missingImplementationThrowsExceptionOnUseNotCreate.

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

Example 9 with NinjaPropertiesImpl

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

the class MigrationEngineProviderTest method defaultImplementation.

@Test
public void defaultImplementation() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.MIGRATION_ENGINE_IMPLEMENTATION, null);
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    Provider<MigrationEngine> provider = injector.getProvider(MigrationEngine.class);
    assertThat(provider.get(), instanceOf(MigrationEngineFlyway.class));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) MigrationEngineFlyway(ninja.migrations.flyway.MigrationEngineFlyway) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 10 with NinjaPropertiesImpl

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

the class ControllerMethodInvokerTest 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)

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