use of ninja.params.ParamParsers in project ninja by ninjaframework.
the class RouterImplTest method before.
@Before
@SuppressWarnings("Convert2Lambda")
public void before() {
this.ninjaBaseDirectoryResolver = new NinjaBaseDirectoryResolver(ninjaProperties);
when(testControllerProvider.get()).thenReturn(new TestController());
when(injector.getProvider(TestController.class)).thenReturn(testControllerProvider);
when(injector.getInstance(ParamParsers.class)).thenReturn(new ParamParsers(Collections.emptySet()));
Provider<RouteBuilderImpl> routeBuilderImplProvider = mock(Provider.class);
when(routeBuilderImplProvider.get()).thenAnswer((invocation) -> new RouteBuilderImpl(ninjaProperties, ninjaBaseDirectoryResolver));
router = new RouterImpl(injector, ninjaProperties, routeBuilderImplProvider);
// add route:
router.GET().route("/testroute").with(TestController.class, "index");
router.GET().route("/user/{email}/{id: .*}").with(TestController.class, "user");
router.GET().route("/u{userId: .*}/entries/{entryId: .*}").with(TestController.class, "entry");
// second route to index should not break reverse routing matching the first
router.GET().route("/testroute/another_url_by_index").with(TestController.class, "index");
router.GET().route("/ref").with(new MethodReference(TestController.class, "ref"));
// functional interface / lambda routing
TestController testController1 = new TestController("Hi!");
router.GET().route("/any_instance_method_ref").with(TestController::home);
router.GET().route("/any_instance_method_ref_exception").with(TestController::exception);
router.GET().route("/any_instance_method_ref2").with(ControllerMethods.of(TestController::home));
router.GET().route("/specific_instance_method_ref").with(testController1::message);
router.GET().route("/specific_instance_method_ref_annotations").with(testController1::status);
router.GET().route("/anonymous_method_ref").with(() -> Results.status(202));
Result staticResult = Results.status(208);
router.GET().route("/anonymous_method_ref_captured").with(() -> staticResult);
router.GET().route("/anonymous_method_ref_context").with((Context context) -> Results.status(context.getParameterAsInteger("status")));
router.GET().route("/anonymous_class").with(new ControllerMethod0() {
@Override
public Result apply() {
return Results.status(203);
}
});
router.GET().route("/anonymous_class_annotations").with(new ControllerMethod1<Integer>() {
@Override
public Result apply(@Param("status") Integer status) {
return Results.status(status);
}
});
router.compileRoutes();
}
use of ninja.params.ParamParsers in project ninja by ninjaframework.
the class FileItemProviderImpl2 method init.
public void init(final Class<? extends FileItemProvider> fileItemProviderClass) throws IOException, ServletException {
//default setup for httpServlet request.
//According to servlet spec the following will be returned:
when(httpServletRequest.getContextPath()).thenReturn("");
when(httpServletRequest.getRequestURI()).thenReturn("/");
when(httpServletRequest.getContentType()).thenReturn("multipart/form-data");
when(httpServletRequest.getMethod()).thenReturn("POST");
NinjaPropertiesImpl properties = new NinjaPropertiesImpl(NinjaMode.test);
this.ninjaProperties = properties;
final FileItemIterator fileItemIterator = makeFileItemsIterator();
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(NinjaProperties.class).toInstance(ninjaProperties);
bind(FileItemProvider.class).to(fileItemProviderClass);
}
});
context = new NinjaServletContext(bodyParserEngineManager, flashCookie, ninjaProperties, resultHandler, sessionCookie, validation, injector, new ParamParsers(new HashSet<ParamParser>())) {
public FileItemIterator getFileItemIterator() {
return fileItemIterator;
}
;
};
}
use of ninja.params.ParamParsers in project ninja by ninjaframework.
the class ReverseRouterTest method before.
@Before
@SuppressWarnings("Convert2Lambda")
public void before() {
this.ninjaProperties = mock(NinjaProperties.class);
this.injector = mock(Injector.class);
this.testControllerProvider = mock(Provider.class);
this.ninjaBaseDirectoryResolver = new NinjaBaseDirectoryResolver(ninjaProperties);
when(testControllerProvider.get()).thenReturn(new TestController());
when(injector.getProvider(TestController.class)).thenReturn(testControllerProvider);
when(injector.getInstance(ParamParsers.class)).thenReturn(new ParamParsers(Collections.emptySet()));
Provider<RouteBuilderImpl> routeBuilderImplProvider = mock(Provider.class);
when(routeBuilderImplProvider.get()).thenAnswer((invocation) -> new RouteBuilderImpl(ninjaProperties, ninjaBaseDirectoryResolver));
router = new RouterImpl(injector, ninjaProperties, routeBuilderImplProvider);
reverseRouter = new ReverseRouter(ninjaProperties, router);
router.GET().route("/home").with(TestController::home);
router.GET().route("/user/{email}/{id: .*}").with(TestController::user);
router.GET().route("/u{userId: .*}/entries/{entryId: .*}").with(TestController::entry);
// second route to index should not break reverse routing matching the first
router.GET().route("/home/index").with(TestController::index);
router.compileRoutes();
}
Aggregations