use of com.blade.mvc.hook.WebHook in project blade by biezhi.
the class BladeTest method testUse.
@Test
public void testUse() {
Blade blade = Blade.of().use(new CsrfMiddleware());
List<WebHook> middleware = blade.middleware();
Assert.assertNotNull(middleware);
assertEquals(1, middleware.size());
}
use of com.blade.mvc.hook.WebHook in project blade by biezhi.
the class RouteMethodHandler method invokeMiddleware.
private boolean invokeMiddleware(List<Route> middleware, RouteContext context) throws BladeException {
if (BladeKit.isEmpty(middleware)) {
return true;
}
for (Route route : middleware) {
WebHook webHook = (WebHook) WebContext.blade().ioc().getBean(route.getTargetType());
boolean flag = webHook.before(context);
if (!flag)
return false;
}
return true;
}
use of com.blade.mvc.hook.WebHook in project blade by biezhi.
the class MiddlewareTest method testMiddleware.
@Test
public void testMiddleware() throws Exception {
WebHook middleware = mock(WebHook.class);
Signature signature = mock(Signature.class);
middleware.before(signature.routeContext());
middleware.after(signature.routeContext());
verify(middleware).before(signature.routeContext());
verify(middleware).after(signature.routeContext());
}
Aggregations