Search in sources :

Example 1 with MockConfigurationProvider

use of com.opensymphony.xwork2.config.providers.MockConfigurationProvider 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 MockConfigurationProvider

use of com.opensymphony.xwork2.config.providers.MockConfigurationProvider 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 MockConfigurationProvider

use of com.opensymphony.xwork2.config.providers.MockConfigurationProvider 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)

Example 4 with MockConfigurationProvider

use of com.opensymphony.xwork2.config.providers.MockConfigurationProvider in project struts by apache.

the class ChainingInterceptorWithConfigTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-default.xml");
    container.inject(provider);
    this.objectFactory = container.getInstance(ObjectFactory.class);
    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) ObjectFactory(com.opensymphony.xwork2.ObjectFactory)

Example 5 with MockConfigurationProvider

use of com.opensymphony.xwork2.config.providers.MockConfigurationProvider in project struts by apache.

the class LongRangeValidatorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-test-beans.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) MockConfigurationProvider(com.opensymphony.xwork2.config.providers.MockConfigurationProvider)

Aggregations

MockConfigurationProvider (com.opensymphony.xwork2.config.providers.MockConfigurationProvider)13 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)11 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)11 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)5 ActionProxy (com.opensymphony.xwork2.ActionProxy)3 TextProviderFactory (com.opensymphony.xwork2.TextProviderFactory)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)1 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)1 SimpleAction (com.opensymphony.xwork2.SimpleAction)1 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 ValueStackFactory (com.opensymphony.xwork2.util.ValueStackFactory)1 DoubleRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator)1