use of jodd.madvoc.component.RootPackages 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());
}
use of jodd.madvoc.component.RootPackages in project jodd by oblac.
the class RootPackagesTest method testRootPackagesPackagePath.
@Test
void testRootPackagesPackagePath() {
RootPackages rootPackages = new RootPackages();
rootPackages.addRootPackage("xx");
rootPackages.addRootPackage("xx.admin.actions", "admin");
rootPackages.addRootPackage("xx.cms.actions", "cms");
for (int i = 0; i < 2; i++) {
// test cache
assertEquals("", rootPackages.findPackagePathForActionPackage("xx"));
assertEquals("/admin", rootPackages.findPackagePathForActionPackage("xx.admin.actions"));
assertEquals("/admin/hey", rootPackages.findPackagePathForActionPackage("xx.admin.actions.hey"));
assertEquals("/cms", rootPackages.findPackagePathForActionPackage("xx.cms.actions"));
assertEquals("/cms/hay", rootPackages.findPackagePathForActionPackage("xx.cms.actions.hay"));
}
}
Aggregations