use of org.apache.struts.action.ActionMapping in project sonar-java 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 sonar-java by SonarSource.
the class TestRequestUtils method testCreateActionForm3a.
// Default module -- Dynamic ActionForm should be created
public void testCreateActionForm3a() {
request.setPathElements("/myapp", "/dynamic.do", null, null);
ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/dynamic");
assertNotNull("Found /dynamic mapping", mapping);
assertNotNull("Mapping has non-null name", mapping.getName());
assertEquals("Mapping has correct name", "dynamic", mapping.getName());
assertNotNull("AppConfig has form bean " + mapping.getName(), moduleConfig.findFormBeanConfig(mapping.getName()));
ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig, null);
assertNotNull("ActionForm returned", form);
assertTrue("ActionForm of correct type", form instanceof DynaActionForm);
}
use of org.apache.struts.action.ActionMapping in project sonar-java 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 sonar-java by SonarSource.
the class TestRequestUtils method testCreateActionForm1a.
// ----------------------------------------------------- createActionForm()
// Default module -- No ActionForm should be created
public void testCreateActionForm1a() {
request.setPathElements("/myapp", "/noform.do", null, null);
ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/noform");
assertNotNull("Found /noform mapping", mapping);
ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig, null);
assertNull("No ActionForm returned", form);
}
use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.
the class ConfigHelper method getActionForm.
/*
* <p>
* Retrieve and return the <code>ActionForm</code> bean associated with
* this mapping, creating and stashing one if necessary. If there is no
* form bean associated with this mapping, return <code>null</code>.
* </p>
*/
public ActionForm getActionForm() {
// Is there a mapping associated with this request?
ActionMapping mapping = getMapping();
if (mapping == null) {
return (null);
}
// Is there a form bean associated with this mapping?
String attribute = mapping.getAttribute();
if (attribute == null) {
return (null);
}
// Look up the existing form bean, if any
ActionForm instance;
if ("request".equals(mapping.getScope())) {
instance = (ActionForm) this.request.getAttribute(attribute);
} else {
instance = (ActionForm) this.session.getAttribute(attribute);
}
return instance;
}
Aggregations