Search in sources :

Example 11 with MockFormBean

use of org.apache.struts.mock.MockFormBean in project sonarqube by SonarSource.

the class TestTagUtils method testComputeParametersPropertyThrowsException.

// accessing this property causes an exception
public void testComputeParametersPropertyThrowsException() {
    request.getSession().setAttribute("SomeBean", new MockFormBean(true));
    Map map = null;
    try {
        map = tagutils.computeParameters(pageContext, null, null, null, null, "SomeBean", "justThrowAnException", null, false);
        fail("JspException not thrown");
    } catch (JspException e) {
        assertNull("map is null", map);
    }
}
Also used : JspException(javax.servlet.jsp.JspException) MockFormBean(org.apache.struts.mock.MockFormBean) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with MockFormBean

use of org.apache.struts.mock.MockFormBean in project sonarqube by SonarSource.

the class TestCopyFormToContext method testLookupByNameAndRequestScope.

public void testLookupByNameAndRequestScope() throws Exception {
    CopyFormToContext command = new CopyFormToContext();
    String formName = "foo";
    command.setFormName(formName);
    command.setScope("request");
    command.setToKey(POST_EXECUTION_CONTEXT_KEY);
    assertNull(context.get(POST_EXECUTION_CONTEXT_KEY));
    assertNull(context.getRequestScope().get(formName));
    assertNull(context.getSessionScope().get(formName));
    command.execute(context);
    assertNotNull(context.get(POST_EXECUTION_CONTEXT_KEY));
    assertNotNull(context.getRequestScope().get(formName));
    assertNull(context.getSessionScope().get(formName));
    assertSame(context.get(POST_EXECUTION_CONTEXT_KEY), context.getRequestScope().get(formName));
    ActionForm theForm = (ActionForm) context.get(POST_EXECUTION_CONTEXT_KEY);
    assertTrue(theForm instanceof MockFormBean);
}
Also used : ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 13 with MockFormBean

use of org.apache.struts.mock.MockFormBean in project sonarqube by SonarSource.

the class TestCopyFormToContext method testLookupByActionPath.

public void testLookupByActionPath() throws Exception {
    CopyFormToContext command = new CopyFormToContext();
    command.setActionPath("/Test");
    command.setToKey(POST_EXECUTION_CONTEXT_KEY);
    // we know this, even though it's not being used for the lookup.
    String formName = "foo";
    assertNull(context.get(POST_EXECUTION_CONTEXT_KEY));
    assertNull(context.getRequestScope().get(formName));
    assertNull(context.getSessionScope().get(formName));
    command.execute(context);
    assertNotNull(context.get(POST_EXECUTION_CONTEXT_KEY));
    assertNotNull(context.getRequestScope().get(formName));
    assertNull(context.getSessionScope().get(formName));
    assertSame(context.get(POST_EXECUTION_CONTEXT_KEY), context.getRequestScope().get(formName));
    ActionForm theForm = (ActionForm) context.get(POST_EXECUTION_CONTEXT_KEY);
    assertTrue(theForm instanceof MockFormBean);
}
Also used : ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 14 with MockFormBean

use of org.apache.struts.mock.MockFormBean 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 15 with MockFormBean

use of org.apache.struts.mock.MockFormBean 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

MockFormBean (org.apache.struts.mock.MockFormBean)21 JspException (javax.servlet.jsp.JspException)15 HashMap (java.util.HashMap)8 Map (java.util.Map)8 ActionForm (org.apache.struts.action.ActionForm)5 DynaActionForm (org.apache.struts.action.DynaActionForm)5 ActionMapping (org.apache.struts.action.ActionMapping)3 ActionMessages (org.apache.struts.action.ActionMessages)2 ServletException (javax.servlet.ServletException)1 MockMultipartRequestHandler (org.apache.struts.mock.MockMultipartRequestHandler)1