Search in sources :

Example 1 with ResultMapper

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

the class ActionResultTest method testAlias.

@Test
void testAlias() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.registerAction(BooAction.class, "foo5", null);
    actionsManager.registerPathAlias("ok", "xxx.jsp");
    actionsManager.registerPathAlias("sok", "zzz");
    ResultMapper resultMapper = webapp.madvocContainer().lookupComponent(ResultMapper.class);
    String path = "/boo.foo.html";
    ResultPath resultPath = resultMapper.resolveResultPath(path, "/<ok>?foo=1");
    assertEquals("/xxx.jsp?foo=1", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "<sok>");
    assertEquals("/boo.foo.html.zzz", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "#<sok>");
    assertEquals("/boo.foo.zzz", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "<dude>?foo=1");
    assertEquals("/xxx.html?foo=1", resultPath.pathValue());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) ResultMapper(jodd.madvoc.component.ResultMapper) ResultPath(jodd.madvoc.config.ResultPath) Test(org.junit.jupiter.api.Test)

Example 2 with ResultMapper

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

the class ActionResultTest method testAlias2.

@Test
void testAlias2() {
    WebApp webapp = new WebApp();
    webapp.start();
    ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class);
    actionsManager.registerAction(BooAction.class, "foo2", null);
    actionsManager.registerPathAlias("/boo.foo2.xxx", "/aliased");
    ResultMapper resultMapper = webapp.madvocContainer().lookupComponent(ResultMapper.class);
    ActionMethodParser actionMethodParser = webapp.madvocContainer().lookupComponent(ActionMethodParser.class);
    ActionRuntime cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo2");
    String path = cfg.getActionPath();
    String resultPath = resultMapper.resolveResultPathString(path, null);
    assertEquals("/aliased", resultPath);
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) ResultMapper(jodd.madvoc.component.ResultMapper) ActionRuntime(jodd.madvoc.config.ActionRuntime) ActionMethodParser(jodd.madvoc.component.ActionMethodParser) Test(org.junit.jupiter.api.Test)

Example 3 with ResultMapper

use of jodd.madvoc.component.ResultMapper 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 4 with ResultMapper

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

the class ActionResultTest method testMethodWithPrefix.

@Test
void testMethodWithPrefix() {
    final WebApp webapp = new WebApp();
    webapp.start();
    final ResultMapper resultMapper = webapp.madvocContainer().lookupComponent(ResultMapper.class);
    resultMapper.setResultPathPrefix("/WEB-INF");
    String path = "/boo.foo";
    ResultPath resultPath = resultMapper.resolveResultPath(path, "ok");
    assertEquals("/WEB-INF/boo.foo.ok", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "doo.ok");
    assertEquals("/WEB-INF/boo.foo.doo.ok", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "#ok");
    assertEquals("/WEB-INF/boo.ok", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "#");
    assertEquals("/WEB-INF/boo", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "#doo.ok");
    assertEquals("/WEB-INF/boo.doo.ok", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, null);
    assertEquals("/WEB-INF/boo.foo", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "/xxx");
    assertEquals("/xxx", resultPath.pathValue());
    resultPath = resultMapper.resolveResultPath(path, "/xxx.ext");
    assertEquals("/xxx.ext", resultPath.pathValue());
}
Also used : ResultMapper(jodd.madvoc.component.ResultMapper) ResultPath(jodd.madvoc.config.ResultPath) Test(org.junit.jupiter.api.Test)

Example 5 with ResultMapper

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

the class ActionResultTest method testResolveResultPath.

@Test
void testResolveResultPath() {
    WebApp webapp = new WebApp();
    webapp.start();
    ResultMapper resultMapper = webapp.madvocContainer.lookupComponent(ResultMapper.class);
    String path = "/boo.foo.html";
    ResultPath resultPath = resultMapper.resolveResultPath(path, "ok");
    assertEquals("/boo.foo.html.ok", resultPath.pathValue());
    assertEquals("/boo.foo.html", resultPath.path());
    assertEquals("ok", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "doo.ok");
    assertEquals("/boo.foo.html.doo.ok", resultPath.pathValue());
    assertEquals("/boo.foo.html", resultPath.path());
    assertEquals("doo.ok", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "#ok");
    assertEquals("/boo.foo.ok", resultPath.pathValue());
    assertEquals("/boo.foo.ok", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "#.ok");
    assertEquals("/boo.foo.ok", resultPath.pathValue());
    assertEquals("/boo.foo", resultPath.path());
    assertEquals("ok", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "#.ok.do");
    assertEquals("/boo.foo.ok.do", resultPath.pathValue());
    assertEquals("/boo.foo", resultPath.path());
    assertEquals("ok.do", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##ok");
    assertEquals("/boo.ok", resultPath.pathValue());
    assertEquals("/boo.ok", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##.ok");
    assertEquals("/boo.ok", resultPath.pathValue());
    assertEquals("/boo", resultPath.path());
    assertEquals("ok", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##ok.do");
    assertEquals("/boo.ok.do", resultPath.pathValue());
    assertEquals("/boo.ok.do", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##ok..do");
    assertEquals("/boo.ok.do", resultPath.pathValue());
    assertEquals("/boo.ok", resultPath.path());
    assertEquals("do", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "#");
    assertEquals("/boo.foo", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, null);
    assertEquals("/boo.foo.html", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "/xxx");
    assertEquals("/xxx", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "/xxx.ext");
    assertEquals("/xxx.ext", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "/xxx..ext");
    assertEquals("/xxx", resultPath.path());
    assertEquals("ext", resultPath.value());
    path = "/boo.html";
    resultPath = resultMapper.resolveResultPath(path, "ok");
    assertEquals("/boo.html", resultPath.path());
    assertEquals("ok", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "#.ok");
    assertEquals("/boo", resultPath.path());
    assertEquals("ok", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##ok");
    assertEquals("/ok", resultPath.path());
    assertEquals(null, resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##.ok");
    assertEquals("/", resultPath.path());
    assertEquals("ok", resultPath.value());
}
Also used : ResultMapper(jodd.madvoc.component.ResultMapper) ResultPath(jodd.madvoc.config.ResultPath) Test(org.junit.jupiter.api.Test)

Aggregations

ResultMapper (jodd.madvoc.component.ResultMapper)5 Test (org.junit.jupiter.api.Test)5 ResultPath (jodd.madvoc.config.ResultPath)3 ActionsManager (jodd.madvoc.component.ActionsManager)2 ArrayList (java.util.ArrayList)1 ActionRequest (jodd.madvoc.ActionRequest)1 WebApp (jodd.madvoc.WebApp)1 ActionMethodParser (jodd.madvoc.component.ActionMethodParser)1 ActionRuntime (jodd.madvoc.config.ActionRuntime)1