Search in sources :

Example 1 with ActionDef

use of jodd.madvoc.ActionDef 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 ActionDef

use of jodd.madvoc.ActionDef 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 ActionDef

use of jodd.madvoc.ActionDef 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 ActionDef

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

the class ServletDispatcherResultTest method createActionRequest.

protected ActionRequest createActionRequest(String actionPath) {
    HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    HttpServletResponse servletResponse = mock(HttpServletResponse.class);
    HttpSession httpSession = mock(HttpSession.class);
    ServletContext servletContext = mock(ServletContext.class);
    when(servletRequest.getSession()).thenReturn(httpSession);
    when(httpSession.getServletContext()).thenReturn(servletContext);
    MadvocController madvocController = new MadvocController();
    Object action = new Object();
    ActionConfig actionConfig = new ActionConfig(Action.class, ReflectUtil.findMethod(Action.class, "view"), null, null, new ActionDef(actionPath, "GET"), null, false, null, null);
    return new ActionRequest(madvocController, actionConfig.getActionPath(), actionConfig, action, servletRequest, servletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActionConfig(jodd.madvoc.ActionConfig) MadvocController(jodd.madvoc.component.MadvocController) ActionRequest(jodd.madvoc.ActionRequest) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) ActionDef(jodd.madvoc.ActionDef)

Example 5 with ActionDef

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

the class ActionsManagerTest method testActionPathMacrosWildcard.

@Test
public void testActionPathMacrosWildcard() {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    ActionsManager actionsManager = webapp.getComponent(ActionsManager.class);
    MadvocConfig madvocConfig = webapp.getComponent(MadvocConfig.class);
    madvocConfig.setPathMacroClass(WildcardPathMacros.class);
    actionsManager.register(FooAction.class, "one", new ActionDef("/${one:a?a}"));
    ActionConfig actionConfig = actionsManager.lookup("/aaa", null);
    assertNotNull(actionConfig);
    actionConfig = actionsManager.lookup("/aab", null);
    assertNull(actionConfig);
}
Also used : ActionConfig(jodd.madvoc.ActionConfig) WebApplication(jodd.madvoc.WebApplication) ActionDef(jodd.madvoc.ActionDef) Test(org.junit.Test)

Aggregations

ActionConfig (jodd.madvoc.ActionConfig)7 ActionDef (jodd.madvoc.ActionDef)7 WebApplication (jodd.madvoc.WebApplication)6 Test (org.junit.Test)6 ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 ActionRequest (jodd.madvoc.ActionRequest)1 MadvocController (jodd.madvoc.component.MadvocController)1