Search in sources :

Example 11 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 12 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)

Example 13 with NinjaPropertiesImpl

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

the class ApplicationControllerTest method testRouteOrdering.

@Test
public void testRouteOrdering() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    Provider<RouteBuilderImpl> routeBuilderImplProvider = Mockito.mock(Provider.class);
    when(routeBuilderImplProvider.get()).thenAnswer((invocation) -> new RouteBuilderImpl(ninjaProperties, ninjaBaseDirectoryResolver));
    RouterImpl router = new RouterImpl(injector, ninjaProperties, routeBuilderImplProvider);
    Routes routes = new Routes(ninjaProperties);
    routes.init(router);
    router.compileRoutes();
    Route route0 = router.getRoutes().get(0);
    Assert.assertThat(route0.getUri(), CoreMatchers.equalTo("/base/middle/app/get"));
    Route route8 = router.getRoutes().get(8);
    Assert.assertThat(route8.getUri(), CoreMatchers.equalTo("/base/middle/app/put"));
    Route route16 = router.getRoutes().get(16);
    Assert.assertThat(route16.getUri(), CoreMatchers.equalTo("/base/middle/app/post"));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) RouteBuilderImpl(ninja.RouteBuilderImpl) RouterImpl(ninja.RouterImpl) Routes(testapplication.conf.Routes) Route(ninja.Route) Test(org.junit.Test)

Example 14 with NinjaPropertiesImpl

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

the class ApplicationControllerTest method testHasKeyedRoute.

@Test
public void testHasKeyedRoute() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty("testkey", "true");
    Provider<RouteBuilderImpl> routeBuilderImplProvider = Mockito.mock(Provider.class);
    when(routeBuilderImplProvider.get()).thenAnswer((invocation) -> new RouteBuilderImpl(ninjaProperties, ninjaBaseDirectoryResolver));
    RouterImpl router = new RouterImpl(injector, ninjaProperties, routeBuilderImplProvider);
    Routes routes = new Routes(ninjaProperties);
    routes.init(router);
    router.compileRoutes();
    String route = router.getReverseRoute(ApplicationController.class, "testKeyedRoute");
    Assert.assertThat(route, CoreMatchers.equalTo("/base/middle/app/keyTest"));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) RouteBuilderImpl(ninja.RouteBuilderImpl) RouterImpl(ninja.RouterImpl) Routes(testapplication.conf.Routes) Test(org.junit.Test)

Example 15 with NinjaPropertiesImpl

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

the class BootstrapTest method frameworkModuleSkipsNinjaClassicModule.

@Test
public void frameworkModuleSkipsNinjaClassicModule() {
    ninjaPropertiesImpl = Mockito.spy(new NinjaPropertiesImpl(NinjaMode.test));
    Mockito.when(ninjaPropertiesImpl.get(NinjaConstant.APPLICATION_MODULES_BASE_PACKAGE)).thenReturn("com.example.frameworkmodule");
    Bootstrap bootstrap = new Bootstrap(ninjaPropertiesImpl);
    bootstrap.boot();
    try {
        Cache cache = bootstrap.getInjector().getInstance(Cache.class);
        fail("cache should not have been found");
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("No implementation for ninja.cache.Cache was bound"));
    }
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Cache(ninja.cache.Cache) 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