Search in sources :

Example 41 with ForwardConfig

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

the class TestActionServlet method testProcessForwardConfigClassOverriddenSubConfigClass.

/**
     * Test the case where the subconfig has already specified its own config
     * class.  If the code still attempts to create a new instance, an error
     * will be thrown.
     */
public void testProcessForwardConfigClassOverriddenSubConfigClass() throws Exception {
    moduleConfig.addForwardConfig(baseForward);
    ForwardConfig customSub = new CustomForwardConfigArg("failure", "/failure.jsp");
    customSub.setExtends("success");
    moduleConfig.addForwardConfig(customSub);
    try {
        actionServlet.processForwardConfigClass(customSub, moduleConfig, null);
    } catch (Exception e) {
        fail("Exception should not be thrown");
    }
}
Also used : ForwardConfig(org.apache.struts.config.ForwardConfig) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 42 with ForwardConfig

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

the class TestActionServlet method testProcessActionExtensionWithForwardConfig.

/**
     * Test that an ActionConfig's ForwardConfig can inherit from a
     * global ForwardConfig.
     */
public void testProcessActionExtensionWithForwardConfig() throws ServletException {
    ForwardConfig forwardConfig = new ForwardConfig();
    forwardConfig.setName("sub");
    forwardConfig.setExtends("success");
    baseAction.addForwardConfig(forwardConfig);
    moduleConfig.addActionConfig(baseAction);
    moduleConfig.addForwardConfig(baseForward);
    actionServlet.processActionConfigExtension(baseAction, moduleConfig);
    forwardConfig = baseAction.findForwardConfig("sub");
    assertEquals("'sub' forward's inheritance was not processed.", baseForward.getPath(), forwardConfig.getPath());
}
Also used : ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 43 with ForwardConfig

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

the class TestRequestUtils method testForwardURL3.

// Third module (custom forwardPattern)
public void testForwardURL3() {
    request.setAttribute(Globals.MODULE_KEY, moduleConfig3);
    request.setPathElements("/myapp", "/3/action.do", null, null);
    ForwardConfig forward = null;
    String result = null;
    // redirect=false, module=null
    forward = moduleConfig3.findForwardConfig("moduleForward");
    assertNotNull("moduleForward found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("moduleForward computed", result);
    assertEquals("moduleForward value", "/forwarding/3/module/forward", result);
    // redirect=true, module=null
    forward = moduleConfig3.findForwardConfig("moduleRedirect");
    assertNotNull("moduleRedirect found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("moduleRedirect computed", result);
    assertEquals("moduleRedirect value", "/forwarding/3/module/redirect", result);
    // redirect=false, module=/context
    forward = moduleConfig3.findForwardConfig("contextForward");
    assertNotNull("contextForward found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("contextForward computed", result);
    assertEquals("contextForward value", "/forwarding/context/forward", result);
    // redirect=true, module=/context
    forward = moduleConfig3.findForwardConfig("contextRedirect");
    assertNotNull("contextRedirect found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("contextRedirect computed", result);
    assertEquals("contextRedirct value", "/forwarding/context/redirect", result);
    // noslash, module=null
    forward = moduleConfig3.findForwardConfig("moduleNoslash");
    assertNotNull("moduleNoslash found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("moduleNoslash computed", result);
    assertEquals("moduleNoslash value", "/forwarding/3/module/noslash", result);
    // noslash, module=/
    forward = moduleConfig3.findForwardConfig("contextNoslash");
    assertNotNull("contextNoslash found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("contextNoslash computed", result);
    assertEquals("contextNoslash value", "/forwarding/context/noslash", result);
}
Also used : ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 44 with ForwardConfig

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

the class TagTestBase method setUp.

/**
     * Helper method that creates/configures a basic configuration of Mock
     * Objects.
     *
     *
     * PageContext ServletConfig ServletContext HttpServletRequest HttpSession
     * HttpServletResponse
     *
     * "/myapp", "/foo", null, null,
     */
public void setUp() {
    // -- default Module
    this.moduleConfig = new ModuleConfigImpl("");
    this.moduleConfig.addForwardConfig(new ForwardConfig("foo", "/bar.jsp", false));
    this.moduleConfig.addForwardConfig(new ForwardConfig("relative1", "relative.jsp", false));
    this.moduleConfig.addForwardConfig(new ForwardConfig("relative2", "relative.jsp", false));
    this.moduleConfig.addForwardConfig(new ForwardConfig("external", "http://struts.apache.org/", false));
    // -- module "/2"
    this.moduleConfig2 = new ModuleConfigImpl("/2");
    this.moduleConfig2.addForwardConfig(new ForwardConfig("foo", "/baz.jsp", false));
    this.moduleConfig2.addForwardConfig(new ForwardConfig("relative1", "relative.jsp", false));
    this.moduleConfig2.addForwardConfig(new ForwardConfig("relative2", "relative.jsp", false));
    this.moduleConfig2.addForwardConfig(new ForwardConfig("external", "http://struts.apache.org/", false));
    // -- module "/3"
    this.moduleConfig3 = new ModuleConfigImpl("/3");
    // -- configure the ServletContext
    this.servletContext = new MockServletContext();
    this.servletContext.setAttribute(Globals.MODULE_KEY, moduleConfig);
    this.servletContext.setAttribute(Globals.MODULE_KEY + "/2", moduleConfig2);
    this.servletContext.setAttribute(Globals.MODULE_KEY + "/3", moduleConfig3);
    // -- configure the ServletConfig
    this.servletConfig = new MockServletConfig();
    this.servletConfig.setServletContext(servletContext);
    // -- configure the request
    this.request = new MockHttpServletRequest(new MockHttpSession());
    pageContext = new MockPageContext(servletConfig, request, new MockHttpServletResponse());
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) MockServletConfig(org.apache.struts.mock.MockServletConfig) MockHttpSession(org.apache.struts.mock.MockHttpSession) MockPageContext(org.apache.struts.mock.MockPageContext) ForwardConfig(org.apache.struts.config.ForwardConfig) ModuleConfigImpl(org.apache.struts.config.impl.ModuleConfigImpl) MockServletContext(org.apache.struts.mock.MockServletContext) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse)

Example 45 with ForwardConfig

use of org.apache.struts.config.ForwardConfig in project sonar-java by SonarSource.

the class TestActionServlet method testProcessForwardConfigClassNoExtends.

/**
 * Make sure processForwardConfigClass() returns what it was given if the
 * forward passed to it doesn't extend anything.
 */
public void testProcessForwardConfigClassNoExtends() throws Exception {
    moduleConfig.addForwardConfig(baseForward);
    ForwardConfig result = null;
    try {
        result = actionServlet.processForwardConfigClass(baseForward, moduleConfig, null);
    } catch (UnavailableException e) {
        fail("An exception should not be thrown when there's nothing to do");
    }
    assertSame("Result should be the same as the input.", baseForward, result);
}
Also used : UnavailableException(javax.servlet.UnavailableException) ForwardConfig(org.apache.struts.config.ForwardConfig)

Aggregations

ForwardConfig (org.apache.struts.config.ForwardConfig)63 ActionConfig (org.apache.struts.config.ActionConfig)14 UnavailableException (javax.servlet.UnavailableException)12 ServletException (javax.servlet.ServletException)10 ExceptionConfig (org.apache.struts.config.ExceptionConfig)10 MalformedURLException (java.net.MalformedURLException)8 ModuleConfig (org.apache.struts.config.ModuleConfig)8 IOException (java.io.IOException)6 MissingResourceException (java.util.MissingResourceException)6 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)6 SAXException (org.xml.sax.SAXException)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionFormBean (org.apache.struts.action.ActionFormBean)4 ActionForward (org.apache.struts.action.ActionForward)4 ActionMapping (org.apache.struts.action.ActionMapping)4 ActionServlet (org.apache.struts.action.ActionServlet)4 FormPropertyConfig (org.apache.struts.config.FormPropertyConfig)4 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)3 ArrayList (java.util.ArrayList)2