use of org.apache.struts.action.ActionMapping in project sonar-java 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);
}
use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.
the class TestRequestUtils method testCreateActionForm4a.
// Default module -- Dynamic ActionForm with initializers
public void testCreateActionForm4a() {
// Retrieve an appropriately configured DynaActionForm instance
request.setPathElements("/myapp", "/dynamic0.do", null, null);
ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/dynamic0");
assertNotNull("Found /dynamic0 mapping", mapping);
assertNotNull("Mapping has non-null name", mapping.getName());
assertEquals("Mapping has correct name", "dynamic0", 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);
// Validate the property values
DynaActionForm dform = (DynaActionForm) form;
Boolean booleanProperty = (Boolean) dform.get("booleanProperty");
assertTrue("booleanProperty is true", booleanProperty.booleanValue());
String stringProperty = (String) dform.get("stringProperty");
assertEquals("stringProperty is correct", "String Property", stringProperty);
Object value = null;
value = dform.get("intArray1");
assertNotNull("intArray1 exists", value);
assertTrue("intArray1 is int[]", value instanceof int[]);
int[] intArray1 = (int[]) value;
assertEquals("intArray1 length is correct", 3, intArray1.length);
assertEquals("intArray1[0] value is correct", 1, intArray1[0]);
assertEquals("intArray1[1] value is correct", 2, intArray1[1]);
assertEquals("intArray1[2] value is correct", 3, intArray1[2]);
value = dform.get("intArray2");
assertNotNull("intArray2 exists", value);
assertTrue("intArray2 is int[]", value instanceof int[]);
int[] intArray2 = (int[]) value;
assertEquals("intArray2 length is correct", 5, intArray2.length);
assertEquals("intArray2[0] value is correct", 0, intArray2[0]);
assertEquals("intArray2[1] value is correct", 0, intArray2[1]);
assertEquals("intArray2[2] value is correct", 0, intArray2[2]);
assertEquals("intArray2[3] value is correct", 0, intArray2[3]);
assertEquals("intArray2[4] value is correct", 0, intArray2[4]);
value = dform.get("principal");
assertNotNull("principal exists", value);
assertTrue("principal is MockPrincipal", value instanceof MockPrincipal);
value = dform.get("stringArray1");
assertNotNull("stringArray1 exists", value);
assertTrue("stringArray1 is int[]", value instanceof String[]);
String[] stringArray1 = (String[]) value;
assertEquals("stringArray1 length is correct", 3, stringArray1.length);
assertEquals("stringArray1[0] value is correct", "aaa", stringArray1[0]);
assertEquals("stringArray1[1] value is correct", "bbb", stringArray1[1]);
assertEquals("stringArray1[2] value is correct", "ccc", stringArray1[2]);
value = dform.get("stringArray2");
assertNotNull("stringArray2 exists", value);
assertTrue("stringArray2 is int[]", value instanceof String[]);
String[] stringArray2 = (String[]) value;
assertEquals("stringArray2 length is correct", 3, stringArray2.length);
assertEquals("stringArray2[0] value is correct", new String(), stringArray2[0]);
assertEquals("stringArray2[1] value is correct", new String(), stringArray2[1]);
assertEquals("stringArray2[2] value is correct", new String(), stringArray2[2]);
// Different form beans should get different property value instances
Object value1 = null;
DynaActionForm dform1 = (DynaActionForm) RequestUtils.createActionForm(request, mapping, moduleConfig, null);
value = dform.get("principal");
value1 = dform1.get("principal");
assertEquals("Different form beans get equal instance values", value, value1);
assertTrue("Different form beans get different instances 1", value != value1);
value = dform.get("stringArray1");
value1 = dform1.get("stringArray1");
assertTrue("Different form beans get different instances 2", value != value1);
dform1.set("stringProperty", "Different stringProperty value");
value = dform.get("stringProperty");
value1 = dform1.get("stringProperty");
assertTrue("Different form beans get different instances 3", value != value1);
}
use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.
the class TestRequestUtils method testCreateActionForm1b.
// Second module -- No ActionForm should be created
public void testCreateActionForm1b() {
request.setPathElements("/myapp", "/2/noform.do", null, null);
ActionMapping mapping = (ActionMapping) moduleConfig2.findActionConfig("/noform");
assertNotNull("Found /noform mapping", mapping);
ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig2, null);
assertNull("No ActionForm returned", form);
}
use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.
the class TestMockBase method setUpSecondApp.
protected void setUpSecondApp() {
ActionFormBean formBean = null;
ActionMapping mapping = null;
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
moduleConfig2 = factoryObject.createModuleConfig("/2");
context.setAttribute(Globals.MODULE_KEY + "/2", moduleConfig2);
// Forward "external" to "http://jakarta.apache.org/"
moduleConfig2.addForwardConfig(new ActionForward("external", "http://jakarta.apache.org/", false));
// Forward "foo" to "/baz.jsp" (different from default)
moduleConfig2.addForwardConfig(new ActionForward("foo", "/baz.jsp", false));
// Forward "relative1" to "relative.jsp" non-context-relative
moduleConfig2.addForwardConfig(new ActionForward("relative1", "relative.jsp", false));
// Forward "relative2" to "relative.jsp" context-relative
moduleConfig2.addForwardConfig(new ActionForward("relative2", "relative.jsp", false));
// Form Bean "static" is a standard ActionForm subclass (same as default)
formBean = new ActionFormBean("static", "org.apache.struts.mock.MockFormBean");
moduleConfig2.addFormBeanConfig(formBean);
// Action "/static" uses the "static" form bean in request scope (same as default)
mapping = new ActionMapping();
mapping.setInput("/static.jsp");
mapping.setName("static");
mapping.setPath("/static");
mapping.setScope("request");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig2.addActionConfig(mapping);
// Form Bean "dynamic2" is a DynaActionForm with the same properties
formBean = new ActionFormBean("dynamic2", "org.apache.struts.action.DynaActionForm");
formBean.addFormPropertyConfig(new FormPropertyConfig("booleanProperty", "boolean", "false"));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringProperty", "java.lang.String", null));
moduleConfig2.addFormBeanConfig(formBean);
// Action "/dynamic2" uses the "dynamic2" form bean in session scope
mapping = new ActionMapping();
mapping.setInput("/dynamic2.jsp");
mapping.setName("dynamic2");
mapping.setPath("/dynamic2");
mapping.setScope("session");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig2.addActionConfig(mapping);
// Action "/noform" has no form bean associated with it (same as default)
mapping = new ActionMapping();
mapping.setPath("/noform");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig2.addActionConfig(mapping);
// Configure global forward declarations
moduleConfig2.addForwardConfig(new ForwardConfig("moduleForward", "/module/forward", // No redirect, same module
false));
moduleConfig2.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", // Redirect, same module
true));
moduleConfig2.addForwardConfig(new ForwardConfig("contextForward", // No redirect
"/forward", // No redirect
false, // Specify module
"/context"));
moduleConfig2.addForwardConfig(new ForwardConfig("contextRedirect", // Redirect
"/redirect", // Redirect
true, // Specify module
"/context"));
moduleConfig2.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", // No redirect, same module
false));
moduleConfig2.addForwardConfig(new ForwardConfig("contextNoslash", // No redirect
"noslash", // No redirect
false, // Specify module
"/context"));
}
use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.
the class TestMockBase method setUpDefaultApp.
protected void setUpDefaultApp() {
ActionFormBean formBean = null;
ActionMapping mapping = null;
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
moduleConfig = factoryObject.createModuleConfig("");
context.setAttribute(Globals.MODULE_KEY, moduleConfig);
// Forward "external" to "http://jakarta.apache.org/"
moduleConfig.addForwardConfig(new ActionForward("external", "http://jakarta.apache.org/", false));
// Forward "foo" to "/bar.jsp"
moduleConfig.addForwardConfig(new ActionForward("foo", "/bar.jsp", false));
// Forward "relative1" to "relative.jsp" non-context-relative
moduleConfig.addForwardConfig(new ActionForward("relative1", "relative.jsp", false));
// Forward "relative2" to "relative.jsp" context-relative
moduleConfig.addForwardConfig(new ActionForward("relative2", "relative.jsp", false));
// Form Bean "static" is a standard ActionForm subclass
formBean = new ActionFormBean("static", "org.apache.struts.mock.MockFormBean");
moduleConfig.addFormBeanConfig(formBean);
// Action "/static" uses the "static" form bean in request scope
mapping = new ActionMapping();
mapping.setInput("/static.jsp");
mapping.setName("static");
mapping.setPath("/static");
mapping.setScope("request");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Form Bean "dynamic" is a DynaActionForm with the same properties
formBean = new ActionFormBean("dynamic", "org.apache.struts.action.DynaActionForm");
formBean.addFormPropertyConfig(new FormPropertyConfig("booleanProperty", "boolean", "false"));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringProperty", "java.lang.String", null));
moduleConfig.addFormBeanConfig(formBean);
// Action "/dynamic" uses the "dynamic" form bean in session scope
mapping = new ActionMapping();
mapping.setInput("/dynamic.jsp");
mapping.setName("dynamic");
mapping.setPath("/dynamic");
mapping.setScope("session");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Form Bean "/dynamic0" is a DynaActionForm with initializers
formBean = new ActionFormBean("dynamic0", "org.apache.struts.action.DynaActionForm");
formBean.addFormPropertyConfig(new FormPropertyConfig("booleanProperty", "boolean", "true"));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringProperty", "java.lang.String", "String Property"));
formBean.addFormPropertyConfig(new FormPropertyConfig("intArray1", "int[]", "{1,2,3}", // 4 should be ignored
4));
formBean.addFormPropertyConfig(new FormPropertyConfig("intArray2", "int[]", null, // 5 should be respected
5));
formBean.addFormPropertyConfig(new FormPropertyConfig("principal", "org.apache.struts.mock.MockPrincipal", null));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray1", "java.lang.String[]", "{aaa,bbb,ccc}", // 2 should be ignored
2));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray2", "java.lang.String[]", null, // 3 should be respected
3));
moduleConfig.addFormBeanConfig(formBean);
// Action "/dynamic0" uses the "dynamic0" form bean in request scope
mapping = new ActionMapping();
mapping.setName("dynamic0");
mapping.setPath("/dynamic0");
mapping.setScope("request");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Action "/noform" has no form bean associated with it
mapping = new ActionMapping();
mapping.setPath("/noform");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Configure global forward declarations
moduleConfig.addForwardConfig(new ForwardConfig("moduleForward", "/module/forward", // No redirect, same module
false));
moduleConfig.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", // Redirect, same module
true));
moduleConfig.addForwardConfig(new ForwardConfig("contextForward", // No redirect
"/forward", // No redirect
false, // Specify module
"/context"));
moduleConfig.addForwardConfig(new ForwardConfig("contextRedirect", // Redirect
"/redirect", // Redirect
true, // Specify module
"/context"));
moduleConfig.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", // No redirect, same module
false));
moduleConfig.addForwardConfig(new ForwardConfig("contextNoslash", // No redirect
"noslash", // No redirect
false, // Specify module
"/context"));
}
Aggregations