use of jodd.madvoc.WebApp in project jodd by oblac.
the class ServletDispatcherResultTest method testServletDispatcherLookup.
@Test
void testServletDispatcherLookup() throws Exception {
WebApp webapp = new WebApp();
webapp.start();
final List<String> targets = new ArrayList<>();
ServletDispatcherActionResult sdr = new ServletDispatcherActionResult() {
@Override
protected boolean targetExists(ActionRequest actionRequest, String target) {
targets.add(target);
return false;
}
};
ResultMapper resultMapper = webapp.madvocContainer().lookupComponent(ResultMapper.class);
BeanUtil.declared.setProperty(sdr, "resultMapper", resultMapper);
ActionRequest actionRequest = createActionRequest("/hello.world.html");
sdr.render(actionRequest, Forward.to("ok"));
assertEquals("[" + "/hello.world.html.ok.jspf, " + "/hello.world.html.ok.jsp, " + "/hello.world.html.jspf, " + "/hello.world.html.jsp, " + "/hello.world.ok.jspf, " + "/hello.world.ok.jsp, " + "/hello.world.jspf, " + "/hello.world.jsp, " + "/hello.ok.jspf, " + "/hello.ok.jsp, " + "/hello.jspf, " + "/hello.jsp, " + "/ok.jspf, " + "/ok.jsp" + "]", targets.toString());
// folder
targets.clear();
actionRequest = createActionRequest("/pak/hello.world.html");
sdr.render(actionRequest, Forward.to("ok"));
assertEquals("[" + "/pak/hello.world.html.ok.jspf, " + "/pak/hello.world.html.ok.jsp, " + "/pak/hello.world.html.jspf, " + "/pak/hello.world.html.jsp, " + "/pak/hello.world.ok.jspf, " + "/pak/hello.world.ok.jsp, " + "/pak/hello.world.jspf, " + "/pak/hello.world.jsp, " + "/pak/hello.ok.jspf, " + "/pak/hello.ok.jsp, " + "/pak/hello.jspf, " + "/pak/hello.jsp, " + "/pak/ok.jspf, " + "/pak/ok.jsp" + "]", targets.toString());
// null result
targets.clear();
actionRequest = createActionRequest("/hello.world.html");
sdr.render(actionRequest, null);
assertEquals("[" + "/hello.world.html.jspf, " + "/hello.world.html.jsp, " + "/hello.world.jspf, " + "/hello.world.jsp, " + "/hello.jspf, " + "/hello.jsp" + "]", targets.toString());
}
use of jodd.madvoc.WebApp in project jodd by oblac.
the class MadvocParamsInjectorTest method testInjection.
@Test
void testInjection() {
WebApp webapp = new WebApp();
webapp.start();
PetiteContainer madpc = webapp.madvocContainer().getPetiteContainer();
String baseName = StringUtil.uncapitalize(FooBean.class.getSimpleName());
madpc.defineParameter("foo", "1");
madpc.defineParameter(baseName + ".integer", "173");
madpc.defineParameter(baseName + ".string", "jodd");
madpc.defineParameter(baseName, "huh");
ParamsScope paramsScope = new ParamsScope();
BeanUtil.declared.setProperty(paramsScope, "madpc", madpc);
FooBean fooBean = new FooBean();
paramsScope.inject(new Targets(fooBean, null));
assertEquals(173, fooBean.getInteger().intValue());
assertEquals("jodd", fooBean.getString());
}
use of jodd.madvoc.WebApp 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);
}
use of jodd.madvoc.WebApp in project jodd by oblac.
the class ActionsManagerTest method testActionPathMacros3.
@Test
void testActionPathMacros3() {
WebApp webapp = new WebApp();
webapp.start();
ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/yyy-{one}"));
actionsManager.registerAction(FooAction.class, "two", new ActionDefinition("/xxx-{two}"));
assertEquals(2, actionsManager.getActionsCount());
ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo"));
assertNull(actionRuntime);
actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/yyy-111"));
assertEquals("one", actionRuntime.getActionClassMethod().getName());
actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/xxx-222"));
assertEquals("two", actionRuntime.getActionClassMethod().getName());
try {
actionsManager.registerAction(FooAction.class, "two", new ActionDefinition("/xxx-{two}"));
fail("error");
} catch (Exception ex) {
// ignore
}
}
use of jodd.madvoc.WebApp in project jodd by oblac.
the class ActionsManagerTest method testActionPathMacros4.
@Test
void testActionPathMacros4() {
WebApp webapp = new WebApp();
webapp.start();
ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
// no macro
actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/dummy"));
actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/{one}"));
actionsManager.registerAction(FooAction.class, "three", new ActionDefinition("/life/{three}"));
actionsManager.registerAction(FooAction.class, "two", new ActionDefinition("/{two}/{three}"));
ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo"));
assertEquals("one", actionRuntime.getActionClassMethod().getName());
actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/scott/ramonna"));
assertEquals("two", actionRuntime.getActionClassMethod().getName());
actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/life/universe"));
assertEquals("three", actionRuntime.getActionClassMethod().getName());
actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/scott/ramonna/envy"));
assertNull(actionRuntime);
actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/life/universe/else"));
assertNull(actionRuntime);
}
Aggregations