Search in sources :

Example 1 with Route

use of ninja.Route in project ninja by ninjaframework.

the class DiagnosticErrorRenderer method appendHeader.

private DiagnosticErrorRenderer appendHeader(Context context, Result result, String title) throws IOException {
    String headerTemplate = getResource("diagnostic_header.html");
    String styleTemplate = getResource("diagnostic.css");
    // simple token replacement
    headerTemplate = headerTemplate.replace("${TITLE}", escape(title));
    headerTemplate = headerTemplate.replace("${STYLE}", escape(styleTemplate));
    s.append(headerTemplate);
    if (result != null) {
        s.append("    <p id=\"detail\">\n");
        if (result.getStatusCode() != 200) {
            s.append("Status code ").append(result.getStatusCode());
        }
        s.append(" for request '").append(context.getMethod()).append(" ").append(context.getRequestPath()).append("'\n");
        // append info about the route itself
        if (context.getRoute() != null) {
            Route route = context.getRoute();
            s.append("<br />In controller method '").append(route.getControllerClass().getCanonicalName()).append(".").append(route.getControllerMethod().getName()).append("'\n");
        }
        s.append("    </p>\n");
    }
    return this;
}
Also used : Route(ninja.Route)

Example 2 with Route

use of ninja.Route in project ninja by ninjaframework.

the class FileItemProviderImpl2 method testControllerWithFileProviderAtClass.

@Test
public void testControllerWithFileProviderAtClass() throws Exception {
    context.init(servletContext, httpServletRequest, httpServletResponse);
    Class<ControllerImpl> controllerClass = ControllerImpl.class;
    Method controllerMethod = ControllerImpl.class.getMethod("method1");
    Route route = new Route("GET", "/", controllerMethod, null);
    context.setRoute(route);
    Assert.assertEquals("test#1", context.getParameterAsFileItem(file1).getContentType());
}
Also used : Method(java.lang.reflect.Method) Route(ninja.Route) Test(org.junit.Test)

Example 3 with Route

use of ninja.Route in project ninja by ninjaframework.

the class FileItemProviderImpl2 method testControllerWithFileProviderAtMethod.

@Test
public void testControllerWithFileProviderAtMethod() throws Exception {
    Class<ControllerImpl> controllerClass = ControllerImpl.class;
    Method controllerMethod = ControllerImpl.class.getMethod("method2");
    Route route = new Route("GET", "/", controllerMethod, null);
    context.setRoute(route);
    context.init(servletContext, httpServletRequest, httpServletResponse);
    Assert.assertEquals("test#2", context.getParameterAsFileItem(file1).getContentType());
}
Also used : Method(java.lang.reflect.Method) Route(ninja.Route) Test(org.junit.Test)

Example 4 with Route

use of ninja.Route in project ninja by ninjaframework.

the class NinjaServletBootstrapTest method userSuppliedServletModuleInShiftedConfDirectory.

@Test
public void userSuppliedServletModuleInShiftedConfDirectory() {
    ninjaPropertiesImpl = Mockito.spy(new NinjaPropertiesImpl(NinjaMode.test));
    Mockito.when(ninjaPropertiesImpl.get(NinjaConstant.APPLICATION_MODULES_BASE_PACKAGE)).thenReturn("custom_base_package");
    Bootstrap bootstrap = new NinjaServletBootstrap(ninjaPropertiesImpl);
    bootstrap.boot();
    assertThat("Ninja Boostrap process picks up user supplied Guice servlet module in custom_base_package.conf.ServletModule", bootstrap.getInjector().getInstance(custom_base_package.conf.ServletModule.DummyInterfaceForTesting.class), is(instanceOf(custom_base_package.conf.ServletModule.DummyClassForTesting.class)));
    Router router = bootstrap.getInjector().getInstance(Router.class);
    Route route = router.getRouteFor("GET", "/custom_base_package");
    assertThat("custom_base_package.conf.Routes initialized properly. We get back the class we defined by the route.", route.getControllerClass(), is(instanceOf(controller.DummyControllerForTesting.class.getClass())));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Bootstrap(ninja.Bootstrap) Router(ninja.Router) Route(ninja.Route) Test(org.junit.Test)

Example 5 with Route

use of ninja.Route in project ninja by ninjaframework.

the class NinjaServletBootstrapTest method userSuppliedServletModuleInConfDirectory.

@Test
public void userSuppliedServletModuleInConfDirectory() {
    ninjaPropertiesImpl = new NinjaPropertiesImpl(NinjaMode.test);
    Bootstrap bootstrap = new NinjaServletBootstrap(ninjaPropertiesImpl);
    bootstrap.boot();
    assertThat(bootstrap.getInjector().getInstance(Context.class), is(instanceOf(NinjaServletContext.class)));
    assertThat("Ninja Boostrap process picks up user supplied Guice servlet module in conf.ServletModule", bootstrap.getInjector().getInstance(conf.ServletModule.DummyInterfaceForTesting.class), is(instanceOf(conf.ServletModule.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(controller.DummyControllerForTesting.class.getClass())));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Context(ninja.Context) Bootstrap(ninja.Bootstrap) Router(ninja.Router) Route(ninja.Route) Test(org.junit.Test)

Aggregations

Route (ninja.Route)9 Test (org.junit.Test)5 NinjaPropertiesImpl (ninja.utils.NinjaPropertiesImpl)3 Method (java.lang.reflect.Method)2 Bootstrap (ninja.Bootstrap)2 Context (ninja.Context)2 Result (ninja.Result)2 Router (ninja.Router)2 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Cookie (ninja.Cookie)1 RouteBuilderImpl (ninja.RouteBuilderImpl)1 RouterImpl (ninja.RouterImpl)1 BadRequestException (ninja.exceptions.BadRequestException)1 FlashScope (ninja.session.FlashScope)1 Session (ninja.session.Session)1 ResponseStreams (ninja.utils.ResponseStreams)1 Before (org.junit.Before)1