Search in sources :

Example 1 with StrutsXmlConfigurationProvider

use of org.apache.struts2.config.StrutsXmlConfigurationProvider in project struts by apache.

the class ValidateAction method testNonexistentParametersGetLoggedInDevMode.

public void testNonexistentParametersGetLoggedInDevMode() throws Exception {
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-test-beans.xml");
    container.inject(provider);
    loadConfigurationProviders(provider, new MockConfigurationProvider(Collections.singletonMap("struts.devMode", "true")));
    Map<String, Object> params = new HashMap<>();
    params.put("not_a_property", "There is no action property named like this");
    HashMap<String, Object> extraContext = new HashMap<>();
    extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
    ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME);
    container.inject(config.getInterceptors().get(0).getInterceptor());
    ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
    proxy.execute();
    final String actionMessage = "" + ((SimpleAction) proxy.getAction()).getActionMessages().toArray()[0];
    assertTrue(actionMessage.contains("Error setting expression 'not_a_property' with value 'There is no action property named like this'"));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) ActionProxy(com.opensymphony.xwork2.ActionProxy) MockConfigurationProvider(com.opensymphony.xwork2.config.providers.MockConfigurationProvider) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with StrutsXmlConfigurationProvider

use of org.apache.struts2.config.StrutsXmlConfigurationProvider in project struts by apache.

the class ValidateAction method testNonexistentParametersAreIgnoredInProductionMode.

public void testNonexistentParametersAreIgnoredInProductionMode() throws Exception {
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-test-beans.xml");
    container.inject(provider);
    loadConfigurationProviders(provider, new MockConfigurationProvider(Collections.singletonMap("struts.devMode", "false")));
    Map<String, Object> params = new HashMap<>();
    params.put("not_a_property", "There is no action property named like this");
    HashMap<String, Object> extraContext = new HashMap<>();
    extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
    ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME);
    container.inject(config.getInterceptors().get(0).getInterceptor());
    ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
    proxy.execute();
    assertTrue(((SimpleAction) proxy.getAction()).getActionMessages().isEmpty());
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) ActionProxy(com.opensymphony.xwork2.ActionProxy) MockConfigurationProvider(com.opensymphony.xwork2.config.providers.MockConfigurationProvider) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 3 with StrutsXmlConfigurationProvider

use of org.apache.struts2.config.StrutsXmlConfigurationProvider in project struts by apache.

the class XmlConfigurationProviderInterceptorParamOverridingTest method testInterceptorParamOveriding.

public void testInterceptorParamOveriding() throws Exception {
    DefaultConfiguration conf = new DefaultConfiguration();
    final XmlConfigurationProvider p = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-interceptor-param-overriding.xml");
    DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
    factory.setContainer(container);
    factory.setFileManager(new DefaultFileManager());
    p.setFileManagerFactory(factory);
    conf.reloadContainer(new ArrayList<ContainerProvider>() {

        {
            add(new StrutsDefaultConfigurationProvider());
            add(p);
        }
    });
    RuntimeConfiguration rtConf = conf.getRuntimeConfiguration();
    ActionConfig actionOne = rtConf.getActionConfig("", "actionOne");
    ActionConfig actionTwo = rtConf.getActionConfig("", "actionTwo");
    List<InterceptorMapping> actionOneInterceptors = actionOne.getInterceptors();
    List<InterceptorMapping> actionTwoInterceptors = actionTwo.getInterceptors();
    assertNotNull(actionOne);
    assertNotNull(actionTwo);
    assertNotNull(actionOneInterceptors);
    assertNotNull(actionTwoInterceptors);
    assertEquals(actionOneInterceptors.size(), 3);
    assertEquals(actionTwoInterceptors.size(), 3);
    InterceptorMapping actionOneInterceptorMapping1 = actionOneInterceptors.get(0);
    InterceptorMapping actionOneInterceptorMapping2 = actionOneInterceptors.get(1);
    InterceptorMapping actionOneInterceptorMapping3 = actionOneInterceptors.get(2);
    InterceptorMapping actionTwoInterceptorMapping1 = actionTwoInterceptors.get(0);
    InterceptorMapping actionTwoInterceptorMapping2 = actionTwoInterceptors.get(1);
    InterceptorMapping actionTwoInterceptorMapping3 = actionTwoInterceptors.get(2);
    assertNotNull(actionOneInterceptorMapping1);
    assertNotNull(actionOneInterceptorMapping2);
    assertNotNull(actionOneInterceptorMapping3);
    assertNotNull(actionTwoInterceptorMapping1);
    assertNotNull(actionTwoInterceptorMapping2);
    assertNotNull(actionTwoInterceptorMapping3);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamOne(), "i1p1");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamTwo(), "i1p2");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamOne(), "i2p1");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamTwo(), "i2p2");
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamOne(), "i3p1");
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamTwo(), "i3p2");
}
Also used : DefaultFileManagerFactory(com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory) ContainerProvider(com.opensymphony.xwork2.config.ContainerProvider) ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) DefaultFileManager(com.opensymphony.xwork2.util.fs.DefaultFileManager) DefaultConfiguration(com.opensymphony.xwork2.config.impl.DefaultConfiguration) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 4 with StrutsXmlConfigurationProvider

use of org.apache.struts2.config.StrutsXmlConfigurationProvider in project struts by apache.

the class XmlConfigurationProviderInterceptorStackParamOverridingTest method testInterceptorStackParamOveriding.

public void testInterceptorStackParamOveriding() throws Exception {
    DefaultConfiguration conf = new DefaultConfiguration();
    final XmlConfigurationProvider p = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-interceptor-stack-param-overriding.xml");
    DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
    factory.setContainer(container);
    factory.setFileManager(new DefaultFileManager());
    p.setFileManagerFactory(factory);
    configurationManager.addContainerProvider(p);
    conf.reloadContainer(new ArrayList<ContainerProvider>() {

        {
            add(new StrutsDefaultConfigurationProvider());
            add(p);
        }
    });
    RuntimeConfiguration rtConf = conf.getRuntimeConfiguration();
    ActionConfig actionOne = rtConf.getActionConfig("", "actionOne");
    ActionConfig actionTwo = rtConf.getActionConfig("", "actionTwo");
    List actionOneInterceptors = actionOne.getInterceptors();
    List actionTwoInterceptors = actionTwo.getInterceptors();
    assertNotNull(actionOne);
    assertNotNull(actionTwo);
    assertNotNull(actionOneInterceptors);
    assertNotNull(actionTwoInterceptors);
    assertEquals(actionOneInterceptors.size(), 3);
    assertEquals(actionTwoInterceptors.size(), 3);
    InterceptorMapping actionOneInterceptorMapping1 = (InterceptorMapping) actionOneInterceptors.get(0);
    InterceptorMapping actionOneInterceptorMapping2 = (InterceptorMapping) actionOneInterceptors.get(1);
    InterceptorMapping actionOneInterceptorMapping3 = (InterceptorMapping) actionOneInterceptors.get(2);
    InterceptorMapping actionTwoInterceptorMapping1 = (InterceptorMapping) actionTwoInterceptors.get(0);
    InterceptorMapping actionTwoInterceptorMapping2 = (InterceptorMapping) actionTwoInterceptors.get(1);
    InterceptorMapping actionTwoInterceptorMapping3 = (InterceptorMapping) actionTwoInterceptors.get(2);
    assertNotNull(actionOneInterceptorMapping1);
    assertNotNull(actionOneInterceptorMapping2);
    assertNotNull(actionOneInterceptorMapping3);
    assertNotNull(actionTwoInterceptorMapping1);
    assertNotNull(actionTwoInterceptorMapping2);
    assertNotNull(actionTwoInterceptorMapping3);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamOne(), "i1p1");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamTwo(), "i1p2");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamOne(), "i2p1");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamTwo(), "i2p2");
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamOne(), "i3p1");
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamTwo(), "i3p2");
}
Also used : DefaultFileManagerFactory(com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory) ContainerProvider(com.opensymphony.xwork2.config.ContainerProvider) ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) DefaultFileManager(com.opensymphony.xwork2.util.fs.DefaultFileManager) DefaultConfiguration(com.opensymphony.xwork2.config.impl.DefaultConfiguration) List(java.util.List) ArrayList(java.util.ArrayList) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 5 with StrutsXmlConfigurationProvider

use of org.apache.struts2.config.StrutsXmlConfigurationProvider in project struts by apache.

the class AnnotationWorkflowInterceptorTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-default.xml");
    container.inject(provider);
    loadConfigurationProviders(provider, new MockConfigurationProvider());
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider)

Aggregations

StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)56 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)33 HashMap (java.util.HashMap)12 MockConfigurationProvider (com.opensymphony.xwork2.config.providers.MockConfigurationProvider)9 ActionProxy (com.opensymphony.xwork2.ActionProxy)7 SimpleAction (com.opensymphony.xwork2.SimpleAction)7 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)7 ArrayList (java.util.ArrayList)7 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)6 LinkedHashMap (java.util.LinkedHashMap)6 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)5 ValueStack (com.opensymphony.xwork2.util.ValueStack)5 File (java.io.File)5 RuntimeConfiguration (com.opensymphony.xwork2.config.RuntimeConfiguration)4 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)4 StrutsDefaultConfigurationProvider (com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider)4 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)4 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)4 Element (org.w3c.dom.Element)4 NodeList (org.w3c.dom.NodeList)4