Search in sources :

Example 11 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class ExecuteCommand method getCommand.

/**
     * <p>Find the <code>ActionConfig</code> in the current context and, if it
     * is properly configured, lookup the appropriate <code>commons-chain</code>
     * command.</p>
     *
     * @param context A valid ActionContext
     * @return a <code>Command</code> to execute, or null if none is specified
     *         or if the specified command cannot be found.
     */
protected Command getCommand(ActionContext context) {
    ActionConfig actionConfig = context.getActionConfig();
    String commandName = actionConfig.getCommand();
    if (commandName == null) {
        return null;
    }
    String catalogName = actionConfig.getCatalog();
    return getCommand(commandName, catalogName);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 12 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class TestActionServlet method testProcessActionConfigClassSubConfigCustomClass.

/**
     * Make sure processActionConfigClass() returns the same class instance if
     * the base config isn't using a custom class.
     */
public void testProcessActionConfigClassSubConfigCustomClass() throws Exception {
    moduleConfig.addActionConfig(baseAction);
    ActionConfig customSub = new ActionMapping();
    customSub.setPath("/sub");
    customSub.setExtends("/index");
    moduleConfig.addActionConfig(customSub);
    ActionConfig result = actionServlet.processActionConfigClass(customSub, moduleConfig);
    assertSame("The instance returned should be the param given it.", customSub, result);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 13 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class TestActionServlet method testProcessActionConfigClass.

/**
     * Make sure processActionConfigClass() returns an instance of the correct
     * class if the base config is using a custom class.
     */
public void testProcessActionConfigClass() throws Exception {
    CustomActionConfig customBase = new CustomActionConfig("/base");
    moduleConfig.addActionConfig(customBase);
    ActionMapping customSub = new ActionMapping();
    customSub.setPath("/sub");
    customSub.setExtends("/base");
    moduleConfig.addActionConfig(customSub);
    ActionConfig result = actionServlet.processActionConfigClass(customSub, moduleConfig);
    assertTrue("Incorrect class of action config", result instanceof CustomActionConfig);
    assertEquals("Incorrect path", customSub.getPath(), result.getPath());
    assertEquals("Incorrect extends", customSub.getExtends(), result.getExtends());
    assertSame("Result was not registered in the module config", result, moduleConfig.findActionConfig("/sub"));
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 14 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class TestActionServlet method testProcessActionConfigClassNoExtends.

/**
     * Make sure processActionConfigClass() returns what it was given if the
     * action passed to it doesn't extend anything.
     */
public void testProcessActionConfigClassNoExtends() throws Exception {
    moduleConfig.addActionConfig(baseAction);
    ActionConfig result = null;
    try {
        result = actionServlet.processActionConfigClass(baseAction, moduleConfig);
    } catch (UnavailableException e) {
        fail("An exception should not be thrown here");
    }
    assertSame("Result should be the same as the input.", baseAction, result);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) UnavailableException(javax.servlet.UnavailableException)

Example 15 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class TestActionServlet method notestProcessActionConfigClassError.

/**
     * Make sure the code throws the correct exception when it can't create an
     * instance of the base config's custom class.
     */
public void notestProcessActionConfigClassError() throws Exception {
    ActionConfig customBase = new CustomActionConfigArg("/index");
    moduleConfig.addActionConfig(customBase);
    ActionConfig customSub = new ActionMapping();
    customSub.setPath("/sub");
    customSub.setExtends("/index");
    moduleConfig.addActionConfig(customSub);
    try {
        actionServlet.processActionConfigClass(customSub, moduleConfig);
        fail("Exception should be thrown");
    } catch (UnavailableException e) {
    // success
    } catch (Exception e) {
        fail("Unexpected exception thrown.");
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Aggregations

ActionConfig (org.apache.struts.config.ActionConfig)76 ForwardConfig (org.apache.struts.config.ForwardConfig)14 UnavailableException (javax.servlet.UnavailableException)8 ActionForm (org.apache.struts.action.ActionForm)8 ExceptionConfig (org.apache.struts.config.ExceptionConfig)8 FormBeanConfig (org.apache.struts.config.FormBeanConfig)8 ModuleConfig (org.apache.struts.config.ModuleConfig)8 ServletException (javax.servlet.ServletException)6 MalformedURLException (java.net.MalformedURLException)4 Map (java.util.Map)4 Action (org.apache.struts.action.Action)4 UnauthorizedActionException (org.apache.struts.chain.commands.UnauthorizedActionException)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 MissingResourceException (java.util.MissingResourceException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JspException (javax.servlet.jsp.JspException)2 ActionErrors (org.apache.struts.action.ActionErrors)2 MockActionContext (org.apache.struts.chain.contexts.MockActionContext)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2