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);
}
}
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);
}
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);
}
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());
}
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);
}
Aggregations