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