Search in sources :

Example 16 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonarqube by SonarSource.

the class TestRequestUtilsPopulate method testMultipartVisibility.

/**
     * Ensure that the getMultipartRequestHandler cannot be seen in
     * a subclass of ActionForm.
     *
     * The purpose of this test is to ensure that Bug #38534 is fixed.
     *
     */
public void testMultipartVisibility() throws Exception {
    String mockMappingName = "mockMapping";
    String stringValue = "Test";
    MockFormBean mockForm = new MockFormBean();
    ActionMapping mapping = new ActionMapping();
    mapping.setName(mockMappingName);
    // Set up the mock HttpServletRequest
    request.setMethod("POST");
    request.setContentType("multipart/form-data");
    request.setAttribute(Globals.MULTIPART_KEY, MockMultipartRequestHandler.class.getName());
    request.setAttribute(Globals.MAPPING_KEY, mapping);
    request.addParameter("stringProperty", stringValue);
    request.addParameter("multipartRequestHandler.mapping.name", "Bad");
    // Check the Mapping/ActionForm before
    assertNull("Multipart Handler already set", mockForm.getMultipartRequestHandler());
    assertEquals("Mapping name not set correctly", mockMappingName, mapping.getName());
    // Try to populate
    try {
        RequestUtils.populate(mockForm, request);
    } catch (ServletException se) {
        // Expected BeanUtils.populate() to throw a NestedNullException
        // which gets wrapped in RequestUtils in a ServletException
        assertEquals("Unexpected type of Exception thrown", "BeanUtils.populate", se.getMessage());
    }
    // Check the Mapping/ActionForm after
    assertNotNull("Multipart Handler Missing", mockForm.getMultipartRequestHandler());
    assertEquals("Mapping name has been modified", mockMappingName, mapping.getName());
}
Also used : ServletException(javax.servlet.ServletException) ActionMapping(org.apache.struts.action.ActionMapping) MockMultipartRequestHandler(org.apache.struts.mock.MockMultipartRequestHandler) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 17 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonarqube by SonarSource.

the class TestActionConfigMatcher method testCheckMultipleSubstitutions.

public void testCheckMultipleSubstitutions() {
    ActionMapping[] mapping = new ActionMapping[1];
    mapping[0] = new ActionMapping();
    mapping[0].setPath("/foo*");
    mapping[0].setName("name,{1}-{1}");
    ActionConfigMatcher matcher = new ActionConfigMatcher(mapping);
    ActionConfig m = matcher.match("/fooBar");
    assertTrue("Name hasn't been replaced correctly: " + m.getName(), "name,Bar-Bar".equals(m.getName()));
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping)

Example 18 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonarqube by SonarSource.

the class TestActionConfigMatcher method buildActionConfig.

private ActionConfig buildActionConfig(String path) {
    ActionMapping mapping = new ActionMapping();
    mapping.setName("name,{1}");
    mapping.setPath(path);
    mapping.setScope("request");
    mapping.setUnknown(false);
    mapping.setValidate(true);
    mapping.setPrefix("foo,{1}");
    mapping.setSuffix("bar,{1}");
    mapping.setType("foo.bar.{1}Action");
    mapping.setRoles("public,{1}");
    mapping.setParameter("param,{1}");
    mapping.setAttribute("attrib,{1}");
    mapping.setForward("fwd,{1}");
    mapping.setInclude("include,{1}");
    mapping.setInput("input,{1}");
    ForwardConfig cfg = new ActionForward();
    cfg.setName("name");
    cfg.setPath("path,{1}");
    cfg.setModule("mod{1}");
    cfg.setProperty("foo", "bar,{1}");
    mapping.addForwardConfig(cfg);
    cfg = new ActionForward();
    cfg.setName("name2");
    cfg.setPath("path2");
    cfg.setModule("mod{1}");
    mapping.addForwardConfig(cfg);
    ExceptionConfig excfg = new ExceptionConfig();
    excfg.setKey("foo");
    excfg.setType("foo.Bar");
    excfg.setPath("path");
    mapping.addExceptionConfig(excfg);
    excfg = new ExceptionConfig();
    excfg.setKey("foo2");
    excfg.setType("foo.Bar2");
    excfg.setPath("path2");
    mapping.addExceptionConfig(excfg);
    mapping.setProperty("testprop", "testval");
    mapping.setProperty("testprop2", "test{1}");
    mapping.freeze();
    return mapping;
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ActionForward(org.apache.struts.action.ActionForward)

Example 19 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonarqube by SonarSource.

the class TestRequestUtils method testCreateActionForm3b.

// Second module -- Dynamic ActionForm should be created
public void testCreateActionForm3b() {
    request.setPathElements("/myapp", "/2/dynamic2.do", null, null);
    ActionMapping mapping = (ActionMapping) moduleConfig2.findActionConfig("/dynamic2");
    assertNotNull("Found /dynamic2 mapping", mapping);
    assertNotNull("Mapping has non-null name", mapping.getName());
    assertEquals("Mapping has correct name", "dynamic2", mapping.getName());
    assertNotNull("AppConfig has form bean " + mapping.getName(), moduleConfig2.findFormBeanConfig(mapping.getName()));
    ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig2, null);
    assertNotNull("ActionForm returned", form);
    assertTrue("ActionForm of correct type", form instanceof DynaActionForm);
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) DynaActionForm(org.apache.struts.action.DynaActionForm) ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm)

Example 20 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonarqube by SonarSource.

the class TestRequestUtils method testCreateActionForm2b.

// Second module -- Standard ActionForm should be created
public void testCreateActionForm2b() {
    request.setPathElements("/myapp", "/2/static.do", null, null);
    ActionMapping mapping = (ActionMapping) moduleConfig2.findActionConfig("/static");
    assertNotNull("Found /static mapping", mapping);
    assertNotNull("Mapping has non-null name", mapping.getName());
    assertEquals("Mapping has correct name", "static", mapping.getName());
    assertNotNull("AppConfig has form bean " + mapping.getName(), moduleConfig.findFormBeanConfig(mapping.getName()));
    ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig2, null);
    assertNotNull("ActionForm returned", form);
    assertTrue("ActionForm of correct type", form instanceof MockFormBean);
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm) MockFormBean(org.apache.struts.mock.MockFormBean)

Aggregations

ActionMapping (org.apache.struts.action.ActionMapping)32 ActionForm (org.apache.struts.action.ActionForm)18 DynaActionForm (org.apache.struts.action.DynaActionForm)14 ActionForward (org.apache.struts.action.ActionForward)6 MockFormBean (org.apache.struts.mock.MockFormBean)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 ActionFormBean (org.apache.struts.action.ActionFormBean)4 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)4 FormPropertyConfig (org.apache.struts.config.FormPropertyConfig)4 ForwardConfig (org.apache.struts.config.ForwardConfig)4 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)4 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 JspException (javax.servlet.jsp.JspException)2 Field (org.apache.commons.validator.Field)2