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;
}
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());
}
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());
}
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())));
}
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())));
}
Aggregations