Search in sources :

Example 1 with RouterImpl

use of ninja.RouterImpl 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 2 with RouterImpl

use of ninja.RouterImpl 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 3 with RouterImpl

use of ninja.RouterImpl in project ninja by ninjaframework.

the class ApplicationControllerTest method testMissingKeyedRoute.

@Test
public void testMissingKeyedRoute() {
    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();
    String route = router.getReverseRoute(ApplicationController.class, "testKeyedRoute");
    Assert.assertNull(route);
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) RouteBuilderImpl(ninja.RouteBuilderImpl) RouterImpl(ninja.RouterImpl) Routes(testapplication.conf.Routes) Test(org.junit.Test)

Aggregations

RouteBuilderImpl (ninja.RouteBuilderImpl)3 RouterImpl (ninja.RouterImpl)3 NinjaPropertiesImpl (ninja.utils.NinjaPropertiesImpl)3 Test (org.junit.Test)3 Routes (testapplication.conf.Routes)3 Route (ninja.Route)1