Search in sources :

Example 1 with WebApp

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());
}
Also used : ActionRequest(jodd.madvoc.ActionRequest) ResultMapper(jodd.madvoc.component.ResultMapper) ArrayList(java.util.ArrayList) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

Example 2 with WebApp

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());
}
Also used : ParamsScope(jodd.madvoc.scope.ParamsScope) Targets(jodd.madvoc.config.Targets) PetiteContainer(jodd.petite.PetiteContainer) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

Example 3 with WebApp

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);
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

Example 4 with WebApp

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
    }
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

Example 5 with WebApp

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);
}
Also used : ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionDefinition(jodd.madvoc.config.ActionDefinition) WebApp(jodd.madvoc.WebApp) Test(org.junit.jupiter.api.Test)

Aggregations

WebApp (jodd.madvoc.WebApp)9 Test (org.junit.jupiter.api.Test)9 ActionDefinition (jodd.madvoc.config.ActionDefinition)7 ActionRuntime (jodd.madvoc.config.ActionRuntime)7 ArrayList (java.util.ArrayList)1 ActionRequest (jodd.madvoc.ActionRequest)1 ResultMapper (jodd.madvoc.component.ResultMapper)1 Targets (jodd.madvoc.config.Targets)1 ParamsScope (jodd.madvoc.scope.ParamsScope)1 PetiteContainer (jodd.petite.PetiteContainer)1