Search in sources :

Example 11 with MadvocConfig

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

the class ActionMethodParserTest method testNoPackage.

@Test
public void testNoPackage() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionMethodParser actionMethodParser = webapp.getComponent(ActionMethodParser.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    madvocConfig.getRootPackages().addRootPackageOf(this.getClass());
    ActionConfig cfg = parse(actionMethodParser, "tst2.Boo5Action#foo");
    assertNotNull(cfg);
    assertEquals(Boo5Action.class, cfg.actionClass);
    assertEquals("/www.foo.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst2.Boo5Action#foo1");
    assertEquals("/www.xxx.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst2.Boo5Action#foo2");
    assertEquals("/www.foo2.xxx", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst2.Boo5Action#foo3");
    assertEquals("/www.html", cfg.actionPath);
}
Also used : MadvocConfig(jodd.madvoc.component.MadvocConfig) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.Test)

Example 12 with MadvocConfig

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

the class ActionMethodParserTest method testMacrosWildcards.

@Test
public void testMacrosWildcards() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionsManager actionsManager = webapp.getComponent(ActionsManager.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    madvocConfig.getRootPackages().addRootPackageOf(this.getClass());
    actionsManager.register(ReAction.class, "wild1");
    actionsManager.register(ReAction.class, "wild2");
    ActionConfig cfg = actionsManager.lookup("/re/ild123cat", "GET");
    assertNull(cfg);
    cfg = actionsManager.lookup("/re/wild123cat", "GET");
    assertNull(cfg);
    cfg = actionsManager.lookup("/re/wild123cat.html", "GET");
    assertNotNull(cfg);
    ActionConfigSet set = cfg.getActionConfigSet();
    assertEquals(ReAction.class, cfg.actionClass);
    assertEquals("/re/wild${id}cat.html", cfg.actionPath);
    assertEquals(2, set.deep);
    assertEquals(1, set.actionPathMacros.getMacrosCount());
    assertEquals("id", set.actionPathMacros.getNames()[0]);
    cfg = actionsManager.lookup("/re/wild123dog.html", "GET");
    assertNull(cfg);
    cfg = actionsManager.lookup("/re/wild123dog.html", "POST");
    assertNotNull(cfg);
    set = cfg.getActionConfigSet();
    assertEquals(ReAction.class, cfg.actionClass);
    assertEquals("/re/wild${id}dog.html", cfg.actionPath);
    assertEquals("POST", cfg.actionMethod);
    assertEquals(2, set.deep);
    assertEquals(1, set.actionPathMacros.getMacrosCount());
    assertEquals("id", set.actionPathMacros.getNames()[0]);
    assertEquals(2, actionsManager.getActionsCount());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) MadvocConfig(jodd.madvoc.component.MadvocConfig) Test(org.junit.Test)

Example 13 with MadvocConfig

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

the class ActionResultTest method testMethodWithPrefix.

@Test
public void testMethodWithPrefix() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ResultMapper resultMapper = webapp.getComponent(ResultMapper.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    madvocConfig.setResultPathPrefix("/WEB-INF");
    String path = "/boo.foo";
    ResultPath resultPath = resultMapper.resolveResultPath(path, "ok");
    assertEquals("/WEB-INF/boo.foo.ok", resultPath.getPathValue());
    resultPath = resultMapper.resolveResultPath(path, "doo.ok");
    assertEquals("/WEB-INF/boo.foo.doo.ok", resultPath.getPathValue());
    resultPath = resultMapper.resolveResultPath(path, "#ok");
    assertEquals("/WEB-INF/boo.ok", resultPath.getPathValue());
    resultPath = resultMapper.resolveResultPath(path, "#");
    assertEquals("/WEB-INF/boo", resultPath.getPathValue());
    resultPath = resultMapper.resolveResultPath(path, "#doo.ok");
    assertEquals("/WEB-INF/boo.doo.ok", resultPath.getPathValue());
    resultPath = resultMapper.resolveResultPath(path, null);
    assertEquals("/WEB-INF/boo.foo", resultPath.getPathValue());
    resultPath = resultMapper.resolveResultPath(path, "/xxx");
    assertEquals("/xxx", resultPath.getPathValue());
    resultPath = resultMapper.resolveResultPath(path, "/xxx.ext");
    assertEquals("/xxx.ext", resultPath.getPathValue());
}
Also used : ResultMapper(jodd.madvoc.component.ResultMapper) MadvocConfig(jodd.madvoc.component.MadvocConfig) Test(org.junit.Test)

Example 14 with MadvocConfig

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

the class ActionMethodParserTest method testMarkerClass.

@Test
public void testMarkerClass() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionMethodParser actionMethodParser = webapp.getComponent(ActionMethodParser.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    RootPackages rootPackages = madvocConfig.getRootPackages();
    String thisPackageName = this.getClass().getPackage().getName();
    assertNull(rootPackages.getPackageActionPath(thisPackageName + ".tst3"));
    ActionConfig cfg = parse(actionMethodParser, "tst3.JohnAction#hello");
    assertEquals("/root", rootPackages.getPackageActionPath(thisPackageName + ".tst3"));
    assertEquals("/root/john.hello.html", cfg.actionPath);
    cfg = parse(actionMethodParser, "tst3.JimAction#hello");
    assertEquals("/my-root/jim.my-hello.html", cfg.actionPath);
    assertNull(rootPackages.getPackageActionPath(thisPackageName + ".tst3.lvl1"));
    cfg = parse(actionMethodParser, "tst3.lvl1.EmaAction#hello");
    assertEquals("/root/lvl1/ema.hello.html", cfg.actionPath);
    assertEquals("/root/lvl1", rootPackages.getPackageActionPath(thisPackageName + ".tst3.lvl1"));
    assertNull(rootPackages.getPackageActionPath(thisPackageName + ".tst3.lvl2"));
    cfg = parse(actionMethodParser, "tst3.lvl2.DidyAction#hello");
    assertEquals("/gig/didy.hello.html", cfg.actionPath);
    assertEquals("/gig", rootPackages.getPackageActionPath(thisPackageName + ".tst3.lvl2"));
}
Also used : MadvocConfig(jodd.madvoc.component.MadvocConfig) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.Test)

Aggregations

MadvocConfig (jodd.madvoc.component.MadvocConfig)14 Test (org.junit.Test)13 ActionMethodParser (jodd.madvoc.component.ActionMethodParser)7 ActionsManager (jodd.madvoc.component.ActionsManager)5 WebApplication (jodd.madvoc.WebApplication)1 FiltersManager (jodd.madvoc.component.FiltersManager)1 InterceptorsManager (jodd.madvoc.component.InterceptorsManager)1 MadvocController (jodd.madvoc.component.MadvocController)1 ResultMapper (jodd.madvoc.component.ResultMapper)1 ResultsManager (jodd.madvoc.component.ResultsManager)1 AutomagicMadvocConfigurator (jodd.madvoc.config.AutomagicMadvocConfigurator)1 MadvocConfigurator (jodd.madvoc.config.MadvocConfigurator)1 PetiteContainer (jodd.petite.PetiteContainer)1 Props (jodd.props.Props)1