Search in sources :

Example 31 with ActionRuntime

use of jodd.madvoc.config.ActionRuntime in project jodd by oblac.

the class ActionsManagerTest method testActionPathMacros2.

@Test
void testActionPathMacros2() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.registerAction(FooAction.class, "two", new ActionDefinition("/xxx-{two}"));
    actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/{one}"));
    ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo"));
    assertEquals("one", actionRuntime.getActionClassMethod().getName());
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo/boo"));
    assertNull(actionRuntime);
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/xxx-foo"));
    // best match!
    assertEquals("two", actionRuntime.getActionClassMethod().getName());
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

Example 32 with ActionRuntime

use of jodd.madvoc.config.ActionRuntime in project jodd by oblac.

the class ServletDispatcherResultTest method createActionRequest.

protected ActionRequest createActionRequest(String actionPath) {
    HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    HttpServletResponse servletResponse = mock(HttpServletResponse.class);
    HttpSession httpSession = mock(HttpSession.class);
    ServletContext servletContext = mock(ServletContext.class);
    when(servletRequest.getSession()).thenReturn(httpSession);
    when(httpSession.getServletContext()).thenReturn(servletContext);
    MadvocController madvocController = new MadvocController();
    Object action = new Object();
    ActionRuntime actionRuntime = new ActionRuntime(null, Action.class, ClassUtil.findMethod(Action.class, "view"), null, null, new ActionDefinition(actionPath, "GET"), ServletDispatcherActionResult.class, null, false, false, null, null);
    return new ActionRequest(madvocController, actionRuntime.getActionPath(), MadvocUtil.splitPathToChunks(actionRuntime.getActionPath()), actionRuntime, action, servletRequest, servletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MadvocController(jodd.madvoc.component.MadvocController) ActionRequest(jodd.madvoc.ActionRequest) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition)

Aggregations

ActionRuntime (jodd.madvoc.config.ActionRuntime)32 Test (org.junit.jupiter.api.Test)24 ActionMethodParser (jodd.madvoc.component.ActionMethodParser)11 RootPackages (jodd.madvoc.component.RootPackages)10 ActionDefinition (jodd.madvoc.config.ActionDefinition)10 ActionsManager (jodd.madvoc.component.ActionsManager)9 WebApp (jodd.madvoc.WebApp)7 RouteChunk (jodd.madvoc.config.RouteChunk)5 Map (java.util.Map)2 ActionRequest (jodd.madvoc.ActionRequest)2 MadvocException (jodd.madvoc.MadvocException)2 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1