Search in sources :

Example 1 with ActionDefinition

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

the class ActionsManagerTest method testActionPathMacrosRegexp.

@Test
void testActionPathMacrosRegexp() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.setPathMacroClass(RegExpPathMacros.class);
    actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/{one:[ab]+}"));
    ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/a"));
    assertNotNull(actionRuntime);
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/ac"));
    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 2 with ActionDefinition

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

the class ActionsManagerTest method testActionPathMacros3.

@Test
void testActionPathMacros3() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/yyy-{one}"));
    actionsManager.registerAction(FooAction.class, "two", new ActionDefinition("/xxx-{two}"));
    assertEquals(2, actionsManager.getActionsCount());
    ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo"));
    assertNull(actionRuntime);
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/yyy-111"));
    assertEquals("one", actionRuntime.getActionClassMethod().getName());
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/xxx-222"));
    assertEquals("two", actionRuntime.getActionClassMethod().getName());
    try {
        actionsManager.registerAction(FooAction.class, "two", new ActionDefinition("/xxx-{two}"));
        fail("error");
    } catch (Exception ex) {
    // ignore
    }
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

Example 3 with ActionDefinition

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

the class ActionsManagerTest method testActionPathMacros4.

@Test
void testActionPathMacros4() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    // no macro
    actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/dummy"));
    actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/{one}"));
    actionsManager.registerAction(FooAction.class, "three", new ActionDefinition("/life/{three}"));
    actionsManager.registerAction(FooAction.class, "two", new ActionDefinition("/{two}/{three}"));
    ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo"));
    assertEquals("one", actionRuntime.getActionClassMethod().getName());
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/scott/ramonna"));
    assertEquals("two", actionRuntime.getActionClassMethod().getName());
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/life/universe"));
    assertEquals("three", actionRuntime.getActionClassMethod().getName());
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/scott/ramonna/envy"));
    assertNull(actionRuntime);
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/life/universe/else"));
    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 4 with ActionDefinition

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

the class ActionRequestRecursionTest method createMyActionRequest.

private MyActionRequest createMyActionRequest(ActionFilter[] actionFilters, ActionInterceptor[] actionInterceptors) {
    SimpleMadvocController madvocController = new SimpleMadvocController();
    Action action = new Action();
    ActionRuntime actionRuntime = new ActionRuntime(null, Action.class, ClassUtil.findMethod(Action.class, "view"), actionFilters, actionInterceptors, new ActionDefinition("path", "method"), ServletDispatcherActionResult.class, null, false, false, null, null);
    return new MyActionRequest(madvocController, "actionPath", actionRuntime, action, null, null);
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition)

Example 5 with ActionDefinition

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

the class ActionsManagerTest method testActionPathMacros_679.

@Test
void testActionPathMacros_679() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.setPathMacroClass(RegExpPathMacros.class);
    ActionRuntime a1 = actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/hello/{id}"));
    ActionRuntime a2 = actionsManager.registerAction(FooAction.class, "two", new ActionDefinition("/hello/default"));
    ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/hello/123"));
    assertSame(a1, actionRuntime);
    actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/hello/default"));
    assertSame(a2, actionRuntime);
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

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