Search in sources :

Example 11 with ActionRuntime

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

the class ActionMethodParserTest method testMethodWithPackage.

@Test
void testMethodWithPackage() {
    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.tst.BooAction#foo");
    assertNotNull(cfg);
    assertEquals(BooAction.class, cfg.getActionClass());
    assertEquals("/fixtures/tst/boo.foo", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo1");
    assertEquals("/fixtures/tst/boo.xxx", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo2");
    assertEquals("/fixtures/tst/boo.foo2.xxx", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo3");
    assertEquals("/fixtures/tst/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());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo6");
    assertEquals("/fixtures/tst/boo.qfoo62", cfg.getActionPath());
    cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo7");
    assertEquals("/foo7.html", 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 12 with ActionRuntime

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

the class ActionResultTest method testAlias2.

@Test
void testAlias2() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.registerAction(BooAction.class, "foo2", null);
    actionsManager.registerPathAlias("/boo.foo2.xxx", "/aliased");
    ResultMapper resultMapper = webapp.madvocContainer().lookupComponent(ResultMapper.class);
    ActionMethodParser actionMethodParser = webapp.madvocContainer().lookupComponent(ActionMethodParser.class);
    ActionRuntime cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo2");
    String path = cfg.getActionPath();
    String resultPath = resultMapper.resolveResultPathString(path, null);
    assertEquals("/aliased", resultPath);
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) ResultMapper(jodd.madvoc.component.ResultMapper) ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.jupiter.api.Test)

Example 13 with ActionRuntime

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

the class AnnArgTest method testDefaultMethods.

@Test
void testDefaultMethods() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionMethodParser actionMethodParser = webapp.madvocContainer().lookupComponent(ActionMethodParser.class);
    ActionRuntime cfg = parse(actionMethodParser, "fixtures.tst.SuperAction#add");
    assertNotNull(cfg);
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.jupiter.api.Test)

Example 14 with ActionRuntime

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

the class ManualRegistrationTest method testManualAction_asComponent.

@Test
void testManualAction_asComponent() {
    WebApp webApp = WebApp.createWebApp().registerComponent(ManualRegistration.class).start();
    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 : ActionsManager(jodd.madvoc.component.ActionsManager) ActionRuntime(jodd.madvoc.config.ActionRuntime) Test(org.junit.jupiter.api.Test)

Example 15 with ActionRuntime

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

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