Search in sources :

Example 11 with ActionsManager

use of jodd.madvoc.component.ActionsManager 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 12 with ActionsManager

use of jodd.madvoc.component.ActionsManager 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)

Example 13 with ActionsManager

use of jodd.madvoc.component.ActionsManager in project jodd by oblac.

the class ManualRegistrationTest method testManualAction_asArgument.

@Test
void testManualAction_asArgument() {
    WebApp webApp = WebApp.createWebApp().start(madvoc -> madvoc.route().path("/hello").mapTo(BooAction.class, "foo1").bind().route().path("/world").mapTo(BooAction.class, "foo2").interceptBy(EchoInterceptor.class).bind().interceptor(EchoInterceptor.class, i -> i.setPrefixIn("====> ")));
    ActionsManager actionsManager = webApp.madvocContainer().requestComponent(ActionsManager.class);
    assertEquals(2, actionsManager.getActionsCount());
    ActionRuntime actionRuntime = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/hello"));
    assertNotNull(actionRuntime);
    assertEquals(BooAction.class, actionRuntime.getActionClass());
    assertEquals("foo1", actionRuntime.getActionClassMethod().getName());
    actionRuntime = actionsManager.lookup("GET", MadvocUtil.splitPathToChunks("/world"));
    assertNotNull(actionRuntime);
    assertEquals(BooAction.class, actionRuntime.getActionClass());
    assertEquals("foo2", actionRuntime.getActionClassMethod().getName());
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) Test(org.junit.jupiter.api.Test) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BooAction(jodd.madvoc.fixtures.tst.BooAction) ActionsManager(jodd.madvoc.component.ActionsManager) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EchoInterceptor(jodd.madvoc.interceptor.EchoInterceptor) ActionsManager(jodd.madvoc.component.ActionsManager) EchoInterceptor(jodd.madvoc.interceptor.EchoInterceptor) ActionRuntime(jodd.madvoc.config.ActionRuntime) Test(org.junit.jupiter.api.Test)

Aggregations

ActionsManager (jodd.madvoc.component.ActionsManager)13 Test (org.junit.jupiter.api.Test)10 ActionRuntime (jodd.madvoc.config.ActionRuntime)9 RootPackages (jodd.madvoc.component.RootPackages)4 RouteChunk (jodd.madvoc.config.RouteChunk)3 ActionMethodParser (jodd.madvoc.component.ActionMethodParser)2 ResultMapper (jodd.madvoc.component.ResultMapper)2 Map (java.util.Map)1 FiltersManager (jodd.madvoc.component.FiltersManager)1 InterceptorsManager (jodd.madvoc.component.InterceptorsManager)1 MadvocConfig (jodd.madvoc.component.MadvocConfig)1 MadvocController (jodd.madvoc.component.MadvocController)1 ResultsManager (jodd.madvoc.component.ResultsManager)1 AutomagicMadvocConfigurator (jodd.madvoc.config.AutomagicMadvocConfigurator)1 MadvocConfigurator (jodd.madvoc.config.MadvocConfigurator)1 ResultPath (jodd.madvoc.config.ResultPath)1 BooAction (jodd.madvoc.fixtures.tst.BooAction)1 EchoInterceptor (jodd.madvoc.interceptor.EchoInterceptor)1 ProxettaAwareActionsManager (jodd.madvoc.proxetta.ProxettaAwareActionsManager)1 Props (jodd.props.Props)1