Search in sources :

Example 6 with ActionDefinition

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

the class ActionsManagerTest method testActionPathMacrosWildcard.

@Test
void testActionPathMacrosWildcard() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.setPathMacroClass(WildcardPathMacros.class);
    actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/{one:a?a}"));
    ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/aaa"));
    assertNotNull(actionRuntime);
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/aab"));
    assertNull(actionRuntime);
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

Example 7 with ActionDefinition

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

the class ActionsManagerTest method testActionPathMacros1.

@Test
void testActionPathMacros1() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/{one}"));
    ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo"));
    assertNotNull(actionRuntime);
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo/boo"));
    assertNull(actionRuntime);
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo/boo/zoo"));
    assertNull(actionRuntime);
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

Example 8 with ActionDefinition

use of jodd.madvoc.config.ActionDefinition 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 9 with ActionDefinition

use of jodd.madvoc.config.ActionDefinition 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

ActionDefinition (jodd.madvoc.config.ActionDefinition)9 ActionRuntime (jodd.madvoc.config.ActionRuntime)9 WebApp (jodd.madvoc.WebApp)7 Test (org.junit.jupiter.api.Test)7 ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 ActionRequest (jodd.madvoc.ActionRequest)1 MadvocController (jodd.madvoc.component.MadvocController)1