use of jodd.madvoc.component.RootPackages 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());
}
use of jodd.madvoc.component.RootPackages in project jodd by oblac.
the class RootPackagesTest method testDuplicateRootPackages.
@Test
void testDuplicateRootPackages() {
RootPackages rootPackages = new RootPackages();
rootPackages.addRootPackage("xx.zz", "foo");
try {
rootPackages.addRootPackage("xx.zz", "bar");
fail("error");
} catch (MadvocException ignore) {
}
}
use of jodd.madvoc.component.RootPackages in project jodd by oblac.
the class RootPackagesTest method testRootPackagesFindForPath.
@Test
void testRootPackagesFindForPath() {
RootPackages rootPackages = new RootPackages();
rootPackages.addRootPackage("xx");
rootPackages.addRootPackage("xx.admin.actions", "admin");
rootPackages.addRootPackage("xx.cms.actions", "cms");
assertEquals("xx", rootPackages.findRootPackageForActionPath("/foo"));
assertEquals("xx.admin.actions", rootPackages.findRootPackageForActionPath("/admin"));
assertEquals("xx.admin.actions", rootPackages.findRootPackageForActionPath("/admin/hey"));
assertEquals("xx.cms.actions", rootPackages.findRootPackageForActionPath("/cms"));
assertEquals("xx.cms.actions", rootPackages.findRootPackageForActionPath("/cms/hay"));
}
use of jodd.madvoc.component.RootPackages 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());
}
use of jodd.madvoc.component.RootPackages 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());
}
Aggregations