Search in sources :

Example 21 with ActionRuntime

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

the class ActionPathMacroInjector method inject.

public void inject(final ActionRequest actionRequest, final Targets targets) {
    final ActionRuntime actionRuntime = actionRequest.getActionRuntime();
    final RouteChunk routeChunk = actionRuntime.getRouteChunk();
    if (!routeChunk.hasMacrosOnPath()) {
        // no action path macros at all, just exit
        return;
    }
    // inject
    final String[] actionPath = actionRequest.getActionPathChunks();
    int ndx = actionPath.length - 1;
    RouteChunk chunk = routeChunk;
    while (chunk.parent() != null) {
        final PathMacros pathMacros = chunk.pathMacros();
        if (pathMacros != null) {
            injectMacros(actionPath[ndx], pathMacros, targets);
        }
        ndx--;
        chunk = chunk.parent();
    }
}
Also used : PathMacros(jodd.madvoc.macro.PathMacros) ActionRuntime(jodd.madvoc.config.ActionRuntime) RouteChunk(jodd.madvoc.config.RouteChunk)

Example 22 with ActionRuntime

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

the class ActionMethodParserTest method testMacrosWildcards.

@Test
void testMacrosWildcards() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    RootPackages rootPackages = webapp.madvocContainer().lookupComponent(RootPackages.class);
    rootPackages.addRootPackageOf(this.getClass());
    actionsManager.registerAction(ReAction.class, "wild1", null);
    actionsManager.registerAction(ReAction.class, "wild2", null);
    ActionRuntime cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/ild123cat"));
    assertNull(cfg);
    cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/wild123ca"));
    assertNull(cfg);
    cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/wild123cat.html"));
    assertNotNull(cfg);
    assertEquals(ReAction.class, cfg.getActionClass());
    assertEquals("/re/wild{id}cat", cfg.getActionPath());
    RouteChunk chunk = cfg.getRouteChunk();
    assertEquals(1, chunk.pathMacros().macrosCount());
    assertEquals("id", chunk.pathMacros().names()[0]);
    cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/wild123dog.html"));
    assertNull(cfg);
    cfg = actionsManager.lookup("POST", MadvocUtil.splitPathToChunks("/re/wild123dog.html"));
    assertNotNull(cfg);
    assertEquals(ReAction.class, cfg.getActionClass());
    assertEquals("/re/wild{id}dog", cfg.getActionPath());
    assertEquals("POST", cfg.getActionMethod());
    chunk = cfg.getRouteChunk();
    assertEquals(1, chunk.pathMacros().macrosCount());
    assertEquals("id", chunk.pathMacros().names()[0]);
    assertEquals(2, actionsManager.getActionsCount());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) RootPackages(jodd.madvoc.component.RootPackages) ActionRuntime(jodd.madvoc.config.ActionRuntime) RouteChunk(jodd.madvoc.config.RouteChunk) Test(org.junit.jupiter.api.Test)

Example 23 with ActionRuntime

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

the class ActionMethodParserTest method testNoPackage.

@Test
void testNoPackage() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionMethodParser actionMethodParser = webapp.madvocContainer().lookupComponent(ActionMethodParser.class);
    RootPackages rootPackages = webapp.madvocContainer().lookupComponent(RootPackages.class);
    rootPackages.addRootPackageOf(this.getClass());
    ActionRuntime cfg = parse(actionMethodParser, "fixtures.tst2.Boo5Action#foo");
    assertNotNull(cfg);
    assertEquals(Boo5Action.class, cfg.getActionClass());
    assertEquals("/www.foo", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst2.Boo5Action#foo1");
    assertEquals("/www.xxx", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst2.Boo5Action#foo2");
    assertEquals("/www.foo2.xxx", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst2.Boo5Action#foo3");
    assertEquals("/www", cfg.getActionPath());
}
Also used : RootPackages(jodd.madvoc.component.RootPackages) ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.jupiter.api.Test)

Example 24 with ActionRuntime

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

the class ActionMethodParserTest method testMacros.

@Test
void testMacros() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    RootPackages rootPackages = webapp.madvocContainer().lookupComponent(RootPackages.class);
    rootPackages.addRootPackageOf(this.getClass());
    actionsManager.registerAction(ReAction.class, "macro", null);
    ActionRuntime cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/user/173/macro.html"));
    assertNotNull(cfg);
    assertEquals(ReAction.class, cfg.getActionClass());
    assertEquals("/re/user/{id}/macro", cfg.getActionPath());
    RouteChunk chunk = cfg.getRouteChunk();
    assertNull(chunk.pathMacros());
    chunk = chunk.parent();
    assertEquals(1, chunk.pathMacros().macrosCount());
    assertEquals("id", chunk.pathMacros().names()[0]);
    assertNull(chunk.pathMacros().patterns()[0]);
    actionsManager.registerAction(ReAction.class, "macro2", null);
    cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/user/image/173/png/macro2.html"));
    assertNotNull(cfg);
    assertEquals(ReAction.class, cfg.getActionClass());
    assertEquals("/re/user/image/{id}/{fmt}/macro2", cfg.getActionPath());
    chunk = cfg.getRouteChunk();
    assertNull(chunk.pathMacros());
    chunk = chunk.parent();
    assertEquals(1, chunk.pathMacros().macrosCount());
    assertEquals("fmt", chunk.pathMacros().names()[0]);
    chunk = chunk.parent();
    assertEquals(1, chunk.pathMacros().macrosCount());
    assertEquals("id", chunk.pathMacros().names()[0]);
    chunk = cfg.getRouteChunk();
    assertNull(chunk.pathMacros());
    actionsManager.registerAction(ReAction.class, "macro3", null);
    cfg = actionsManager.lookup("POST", MadvocUtil.splitPathToChunks("/re/users/173/macro3"));
    assertNotNull(cfg);
    assertEquals(ReAction.class, cfg.getActionClass());
    assertEquals("/re/users/{id}/macro3", cfg.getActionPath());
    assertEquals("POST", cfg.getActionMethod());
    chunk = cfg.getRouteChunk();
    assertNull(chunk.pathMacros());
    chunk = chunk.parent();
    assertEquals(1, chunk.pathMacros().macrosCount());
    assertEquals("id", chunk.pathMacros().names()[0]);
    cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/user/index.html"));
    assertNull(cfg);
    cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/user/index/reindex/macro.html"));
    assertNull(cfg);
    cfg = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/re/users/173/macro3"));
    assertNull(cfg);
    assertEquals(3, actionsManager.getActionsCount());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) RootPackages(jodd.madvoc.component.RootPackages) ActionRuntime(jodd.madvoc.config.ActionRuntime) RouteChunk(jodd.madvoc.config.RouteChunk) Test(org.junit.jupiter.api.Test)

Example 25 with ActionRuntime

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

the class ActionMethodParserTest method testMethod.

@Test
void testMethod() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionMethodParser actionMethodParser = webapp.madvocContainer().lookupComponent(ActionMethodParser.class);
    ActionRuntime cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo");
    assertNotNull(cfg);
    assertEquals(BooAction.class, cfg.getActionClass());
    assertEquals("/boo.foo", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo1");
    assertEquals("/boo.xxx", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo2");
    assertEquals("/boo.foo2.xxx", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo3");
    assertEquals("/boo", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo4");
    assertEquals("/xxx", cfg.getActionPath());
    assertNull(cfg.getActionMethod());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo41");
    assertEquals("/xxx", cfg.getActionPath());
    assertEquals("DELETE", cfg.getActionMethod());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo5");
    assertEquals("/xxx.html", cfg.getActionPath());
    assertEquals("POST", cfg.getActionMethod());
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    assertEquals("/xxx.html", actionsManager.lookupPathAlias("dude"));
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.jupiter.api.Test)

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