Search in sources :

Example 1 with WebApplication

use of jodd.madvoc.WebApplication in project jodd by oblac.

the class ActionsManagerTest method testActionPathMacrosRegexp.

@Test
public void testActionPathMacrosRegexp() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionsManager actionsManager = webapp.getComponent(ActionsManager.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    madvocConfig.setPathMacroClass(RegExpPathMacros.class);
    actionsManager.register(FooAction.class, "one", new ActionDef("/${one:[ab]+}"));
    ActionConfig actionConfig = actionsManager.lookup("/a", null);
    assertNotNull(actionConfig);
    actionConfig = actionsManager.lookup("/ac", null);
    assertNull(actionConfig);
}
Also used : ActionConfig(jodd.madvoc.ActionConfig) WebApplication(jodd.madvoc.WebApplication) ActionDef(jodd.madvoc.ActionDef) Test(org.junit.Test)

Example 2 with WebApplication

use of jodd.madvoc.WebApplication in project jodd by oblac.

the class ActionsManagerTest method testActionPathMacros3.

@Test
public void testActionPathMacros3() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionsManager actionsManager = webapp.getComponent(ActionsManager.class);
    actionsManager.register(FooAction.class, "one", new ActionDef("/yyy-${one}"));
    actionsManager.register(FooAction.class, "two", new ActionDef("/xxx-${two}"));
    assertEquals(2, actionsManager.getActionsCount());
    ActionConfig actionConfig = actionsManager.lookup("/foo", null);
    assertNull(actionConfig);
    actionConfig = actionsManager.lookup("/yyy-111", null);
    assertEquals("one", actionConfig.actionClassMethod.getName());
    actionConfig = actionsManager.lookup("/xxx-222", null);
    assertEquals("two", actionConfig.actionClassMethod.getName());
    try {
        actionsManager.register(FooAction.class, "two", new ActionDef("/xxx-${two}"));
        Assert.fail();
    } catch (Exception ex) {
    // ignore
    }
}
Also used : ActionConfig(jodd.madvoc.ActionConfig) WebApplication(jodd.madvoc.WebApplication) ActionDef(jodd.madvoc.ActionDef) Test(org.junit.Test)

Example 3 with WebApplication

use of jodd.madvoc.WebApplication in project jodd by oblac.

the class ActionsManagerTest method testActionPathMacros4.

@Test
public void testActionPathMacros4() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionsManager actionsManager = webapp.getComponent(ActionsManager.class);
    actionsManager.register(FooAction.class, "one", new ActionDef("/${one}"));
    // no macro
    actionsManager.register(FooAction.class, "one", new ActionDef("/dummy"));
    actionsManager.register(FooAction.class, "two", new ActionDef("/${two}/${three}"));
    actionsManager.register(FooAction.class, "three", new ActionDef("/life/${three}"));
    ActionConfig actionConfig = actionsManager.lookup("/foo", null);
    assertEquals("one", actionConfig.actionClassMethod.getName());
    actionConfig = actionsManager.lookup("/scott/ramonna", null);
    assertEquals("two", actionConfig.actionClassMethod.getName());
    actionConfig = actionsManager.lookup("/life/universe", null);
    assertEquals("three", actionConfig.actionClassMethod.getName());
    actionConfig = actionsManager.lookup("/scott/ramonna/envy", null);
    assertNull(actionConfig);
    actionConfig = actionsManager.lookup("/life/universe/else", null);
    assertNull(actionConfig);
}
Also used : ActionConfig(jodd.madvoc.ActionConfig) WebApplication(jodd.madvoc.WebApplication) ActionDef(jodd.madvoc.ActionDef) Test(org.junit.Test)

Example 4 with WebApplication

use of jodd.madvoc.WebApplication in project jodd by oblac.

the class MadvocParamsInjectorTest method testInjection.

@Test
public void testInjection() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    PetiteContainer madpc = (PetiteContainer) webapp.getComponent(WebApplication.MADVOC_CONTAINER_NAME);
    MadvocConfig madvocConfig = new MadvocConfig();
    String baseName = FooBean.class.getName();
    madpc.defineParameter("foo", "1");
    madpc.defineParameter(baseName + ".integer", "173");
    madpc.defineParameter(baseName + ".string", "jodd");
    madpc.defineParameter(baseName, "huh");
    MadvocParamsInjector madvocParamsInjector = new MadvocParamsInjector(madvocConfig);
    FooBean fooBean = new FooBean();
    madvocParamsInjector.injectContext(new Target(fooBean), null, madpc);
    assertEquals(173, fooBean.getInteger().intValue());
    assertEquals("jodd", fooBean.getString());
}
Also used : WebApplication(jodd.madvoc.WebApplication) PetiteContainer(jodd.petite.PetiteContainer) MadvocConfig(jodd.madvoc.component.MadvocConfig) Test(org.junit.Test)

Example 5 with WebApplication

use of jodd.madvoc.WebApplication in project jodd by oblac.

the class ServletDispatcherResultTest method testServletDispatcherLookup.

@Test
public void testServletDispatcherLookup() throws Exception {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    final List<String> targets = new ArrayList<>();
    ServletDispatcherResult sdr = new ServletDispatcherResult() {

        @Override
        protected boolean targetExists(ActionRequest actionRequest, String target) {
            targets.add(target);
            return false;
        }
    };
    ResultMapper resultMapper = webapp.getComponent(ResultMapper.class);
    BeanUtil.declared.setProperty(sdr, "resultMapper", resultMapper);
    ActionRequest actionRequest = createActionRequest("/hello.world.html");
    sdr.render(actionRequest, "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, "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) WebApplication(jodd.madvoc.WebApplication) Test(org.junit.Test)

Aggregations

WebApplication (jodd.madvoc.WebApplication)8 Test (org.junit.Test)8 ActionConfig (jodd.madvoc.ActionConfig)6 ActionDef (jodd.madvoc.ActionDef)6 ArrayList (java.util.ArrayList)1 ActionRequest (jodd.madvoc.ActionRequest)1 MadvocConfig (jodd.madvoc.component.MadvocConfig)1 ResultMapper (jodd.madvoc.component.ResultMapper)1 PetiteContainer (jodd.petite.PetiteContainer)1