Search in sources :

Example 6 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class RouteTableRouterBuilderTest method verify.

private void verify(String expected, H.Method method, String url) {
    H.Request req = Mockito.mock(H.Request.class);
    Mockito.when(ctx.req()).thenReturn(req);
    Mockito.when(ctx.attribute(anyString(), Matchers.any())).thenReturn(ctx);
    Mockito.when(req.path()).thenReturn(url);
    RequestHandler handler = router.getInvoker(method, url, ctx);
    if (handler == AlwaysNotFound.INSTANCE) {
        throw NotFound.get();
    } else if (handler == AlwaysBadRequest.INSTANCE) {
        throw BadRequest.get();
    }
    handler.handle(ctx);
    controllerInvoked(expected);
}
Also used : RequestHandler(act.handler.RequestHandler) H(org.osgl.http.H)

Example 7 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class RouterTest method searchBadUrl.

@Test
public void searchBadUrl() {
    RequestHandler handler = router.getInvoker(GET, "/nonexists", ctx);
    same(handler, AlwaysNotFound.INSTANCE);
}
Also used : RequestHandler(act.handler.RequestHandler) Test(org.junit.Test)

Example 8 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class RouterTest method doNotOverrideExistingRouting.

@Test
public void doNotOverrideExistingRouting() {
    routeWithStaticDir();
    router.addMapping(GET, "/public", "file:/private", ACTION_ANNOTATION);
    RequestHandler handler = router.getInvoker(GET, "/public/foo/bar.txt", ctx);
    yes(handler instanceof FileGetter);
    yes(handler.supportPartialPath());
    eq(new File(BASE, "/public"), fieldVal(handler, "base"));
}
Also used : RequestHandler(act.handler.RequestHandler) File(java.io.File) FileGetter(act.handler.builtin.FileGetter) Test(org.junit.Test)

Example 9 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class RouterTest method overrideExistingRouting.

@Test
public void overrideExistingRouting() {
    routeWithStaticDir();
    router.addMapping(GET, "/public", "file:/private");
    RequestHandler handler = router.getInvoker(GET, "/public/foo/bar.txt", ctx);
    yes(handler instanceof FileGetter);
    yes(handler.supportPartialPath());
    eq(new File(BASE, "/private"), fieldVal(handler, "base"));
}
Also used : RequestHandler(act.handler.RequestHandler) File(java.io.File) FileGetter(act.handler.builtin.FileGetter) Test(org.junit.Test)

Example 10 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class RouterTest method routeWithStaticDir.

@Test
public void routeWithStaticDir() {
    router.addMapping(GET, "/public", "file:/public");
    RequestHandler handler = router.getInvoker(GET, "/public/foo/bar.txt", ctx);
    yes(handler instanceof FileGetter);
    yes(handler.supportPartialPath());
    eq(new File(BASE, "/public"), fieldVal(handler, "base"));
}
Also used : RequestHandler(act.handler.RequestHandler) File(java.io.File) FileGetter(act.handler.builtin.FileGetter) Test(org.junit.Test)

Aggregations

RequestHandler (act.handler.RequestHandler)16 Test (org.junit.Test)7 H (org.osgl.http.H)7 FileGetter (act.handler.builtin.FileGetter)5 File (java.io.File)4 FastRequestHandler (act.handler.builtin.controller.FastRequestHandler)2 PreHandle (act.handler.event.PreHandle)2 EventBus (act.event.EventBus)1 AlwaysNotFound (act.handler.builtin.AlwaysNotFound)1 Echo (act.handler.builtin.Echo)1 ResourceGetter (act.handler.builtin.ResourceGetter)1 PostHandle (act.handler.event.PostHandle)1 Timer (act.metric.Timer)1 CORS (act.security.CORS)1 ActErrorResult (act.view.ActErrorResult)1 UndertowRequest (act.xio.undertow.UndertowRequest)1 URL (java.net.URL)1 NotAppliedException (org.osgl.exception.NotAppliedException)1 ErrorResult (org.osgl.mvc.result.ErrorResult)1 NotFound (org.osgl.mvc.result.NotFound)1