Search in sources :

Example 1 with WebHook

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());
}
Also used : CsrfMiddleware(com.blade.security.web.csrf.CsrfMiddleware) WebHook(com.blade.mvc.hook.WebHook) Test(org.junit.Test)

Example 2 with WebHook

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;
}
Also used : WebHook(com.blade.mvc.hook.WebHook) Route(com.blade.mvc.route.Route)

Example 3 with WebHook

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());
}
Also used : Signature(com.blade.mvc.hook.Signature) WebHook(com.blade.mvc.hook.WebHook) Test(org.junit.Test)

Aggregations

WebHook (com.blade.mvc.hook.WebHook)3 Test (org.junit.Test)2 Signature (com.blade.mvc.hook.Signature)1 Route (com.blade.mvc.route.Route)1 CsrfMiddleware (com.blade.security.web.csrf.CsrfMiddleware)1