Search in sources :

Example 6 with FormBeanConfig

use of org.apache.struts.config.FormBeanConfig in project sonarqube by SonarSource.

the class TestActionServlet method notestProcessFormBeanConfigClassError.

/**
     * Make sure the code throws the correct exception when it can't create an
     * instance of the base config's custom class.
     */
public void notestProcessFormBeanConfigClassError() throws Exception {
    CustomFormBeanConfigArg customBase = new CustomFormBeanConfigArg("customBase");
    moduleConfig.addFormBeanConfig(customBase);
    FormBeanConfig customSub = new FormBeanConfig();
    customSub.setName("customSub");
    customSub.setExtends("customBase");
    moduleConfig.addFormBeanConfig(customSub);
    try {
        actionServlet.processFormBeanConfigClass(customSub, moduleConfig);
        fail("Exception should be thrown");
    } catch (UnavailableException e) {
    // success
    } catch (Exception e) {
        fail("Unexpected exception thrown.");
    }
}
Also used : FormBeanConfig(org.apache.struts.config.FormBeanConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 7 with FormBeanConfig

use of org.apache.struts.config.FormBeanConfig in project sonarqube by SonarSource.

the class TestActionServlet method testInitModuleFormBeansNullFormType.

/**
     * Test that initModuleFormBeans throws an exception when a form with a
     * null type is present.
     */
public void testInitModuleFormBeansNullFormType() throws ServletException {
    FormBeanConfig formBean = new FormBeanConfig();
    formBean.setName("noTypeForm");
    moduleConfig.addFormBeanConfig(formBean);
    try {
        actionServlet.initModuleFormBeans(moduleConfig);
        fail("An exception should've been thrown here.");
    } catch (UnavailableException e) {
    // success
    } catch (Exception e) {
        fail("Unrecognized exception thrown: " + e);
    }
}
Also used : FormBeanConfig(org.apache.struts.config.FormBeanConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 8 with FormBeanConfig

use of org.apache.struts.config.FormBeanConfig in project sonarqube by SonarSource.

the class TestActionServlet method testProcessFormBeanConfigClassOverriddenSubFormClass.

/**
     * Test the case where the subform has already specified its own form bean
     * config class.  If the code still attempts to create a new instance, an
     * error will be thrown.
     */
public void testProcessFormBeanConfigClassOverriddenSubFormClass() throws Exception {
    CustomFormBeanConfigArg customBase = new CustomFormBeanConfigArg("customBase");
    moduleConfig.addFormBeanConfig(customBase);
    FormBeanConfig customSub = new CustomFormBeanConfigArg("customSub");
    customSub.setExtends("customBase");
    moduleConfig.addFormBeanConfig(customSub);
    try {
        actionServlet.processFormBeanConfigClass(customSub, moduleConfig);
    } catch (Exception e) {
        fail("Exception should not be thrown");
    }
}
Also used : FormBeanConfig(org.apache.struts.config.FormBeanConfig) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 9 with FormBeanConfig

use of org.apache.struts.config.FormBeanConfig in project sonarqube by SonarSource.

the class TestActionServlet method testProcessFormBeanConfigClassNoExtends.

/**
     * Make sure processFormBeanConfigClass() returns what it was given if the
     * form passed to it doesn't extend anything.
     */
public void testProcessFormBeanConfigClassNoExtends() throws Exception {
    moduleConfig.addFormBeanConfig(baseFormBean);
    FormBeanConfig result = null;
    try {
        result = actionServlet.processFormBeanConfigClass(baseFormBean, moduleConfig);
    } catch (UnavailableException e) {
        fail("An exception should not be thrown when there's nothing to do");
    }
    assertSame("Result should be the same as the input.", baseFormBean, result);
}
Also used : FormBeanConfig(org.apache.struts.config.FormBeanConfig) UnavailableException(javax.servlet.UnavailableException)

Example 10 with FormBeanConfig

use of org.apache.struts.config.FormBeanConfig in project sonarqube by SonarSource.

the class TestActionServlet method testProcessFormBeanConfigClass.

/**
     * Make sure processFormBeanConfigClass() returns an instance of the
     * correct class if the base config is using a custom class.
     */
public void testProcessFormBeanConfigClass() throws Exception {
    CustomFormBeanConfig customBase = new CustomFormBeanConfig();
    customBase.setName("customBase");
    moduleConfig.addFormBeanConfig(customBase);
    FormBeanConfig customSub = new FormBeanConfig();
    customSub.setName("customSub");
    customSub.setExtends("customBase");
    customSub.setType("org.apache.struts.action.DynaActionForm");
    moduleConfig.addFormBeanConfig(customSub);
    FormBeanConfig result = actionServlet.processFormBeanConfigClass(customSub, moduleConfig);
    assertTrue("Incorrect class of form bean config", result instanceof CustomFormBeanConfig);
    assertEquals("Incorrect name", customSub.getName(), result.getName());
    assertEquals("Incorrect type", customSub.getType(), result.getType());
    assertEquals("Incorrect extends", customSub.getExtends(), result.getExtends());
    assertEquals("Incorrect 'restricted' value", customSub.isRestricted(), result.isRestricted());
    assertSame("Result was not registered in the module config", result, moduleConfig.findFormBeanConfig("customSub"));
}
Also used : FormBeanConfig(org.apache.struts.config.FormBeanConfig)

Aggregations

FormBeanConfig (org.apache.struts.config.FormBeanConfig)18 UnavailableException (javax.servlet.UnavailableException)5 FormPropertyConfig (org.apache.struts.config.FormPropertyConfig)5 ServletException (javax.servlet.ServletException)4 ActionConfig (org.apache.struts.config.ActionConfig)4 ActionForm (org.apache.struts.action.ActionForm)3 Map (java.util.Map)2 ExceptionConfig (org.apache.struts.config.ExceptionConfig)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 MissingResourceException (java.util.MissingResourceException)1 StringTokenizer (java.util.StringTokenizer)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JspException (javax.servlet.jsp.JspException)1 MockActionContext (org.apache.struts.chain.contexts.MockActionContext)1 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)1 ActionConfigMatcher (org.apache.struts.config.ActionConfigMatcher)1 ForwardConfig (org.apache.struts.config.ForwardConfig)1 MessageResourcesConfig (org.apache.struts.config.MessageResourcesConfig)1 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)1