Search in sources :

Example 46 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class AliasInterceptorTest method testUsingDefaultInterceptorThatAliasPropertiesAreCopied.

public void testUsingDefaultInterceptorThatAliasPropertiesAreCopied() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("aliasSource", "source here");
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
    container.inject(provider);
    loadConfigurationProviders(provider);
    ActionProxy proxy = actionProxyFactory.createActionProxy("", "aliasTest", null, params);
    SimpleAction actionOne = (SimpleAction) proxy.getAction();
    actionOne.setAliasSource("name to be copied");
    actionOne.setFoo(17);
    actionOne.setBar(23);
    proxy.execute();
    assertEquals("name to be copied", actionOne.getAliasSource());
    assertEquals(actionOne.getAliasSource(), actionOne.getAliasDest());
    // WW-5087
    assertNull(actionOne.getBlah());
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ActionProxy(com.opensymphony.xwork2.ActionProxy) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy) HashMap(java.util.HashMap) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 47 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class AliasInterceptorTest method testNotExisting.

public void testNotExisting() throws Exception {
    Map<String, Object> params = new HashMap<>();
    Map<String, Object> httpParams = new HashMap<>();
    httpParams.put("notExisting", "from http parameter");
    params.put(ActionContext.PARAMETERS, HttpParameters.create(httpParams).build());
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
    container.inject(provider);
    loadConfigurationProviders(provider);
    ActionProxy proxy = actionProxyFactory.createActionProxy("", "aliasTest", null, params);
    SimpleAction actionOne = (SimpleAction) proxy.getAction();
    // prevent ERROR result
    actionOne.setFoo(-1);
    actionOne.setBar(1);
    proxy.execute();
    assertEquals("from http parameter", actionOne.getBlah());
    // WW-5087
    assertNull(actionOne.getAliasDest());
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ActionProxy(com.opensymphony.xwork2.ActionProxy) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy) HashMap(java.util.HashMap) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 48 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class AliasInterceptorTest method testValueNotAccepted.

public void testValueNotAccepted() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("aliasSource", "source here");
    Map<String, String> httpParams = new HashMap<>();
    httpParams.put("name", "aliasSource");
    httpParams.put("value", "[0].aliasDest");
    params.put("parameters", HttpParameters.create(httpParams).build());
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
    container.inject(provider);
    loadConfigurationProviders(provider);
    ActionProxy proxy = actionProxyFactory.createActionProxy("", "dynamicAliasTest", null, params);
    SimpleAction actionOne = (SimpleAction) proxy.getAction();
    actionOne.setAliasSource("name to be copied");
    // prevent ERROR result
    actionOne.setFoo(-1);
    actionOne.setBar(1);
    proxy.execute();
    assertEquals("name to be copied", actionOne.getAliasSource());
    assertNotEquals(actionOne.getAliasSource(), actionOne.getAliasDest());
    proxy = actionProxyFactory.createActionProxy("", "dynamicAliasTest", null, params);
    ((AliasInterceptor) proxy.getConfig().getInterceptors().get(1).getInterceptor()).setExcludedPatterns(NO_EXCLUSION_PATTERNS_CHECKER);
    ((AliasInterceptor) proxy.getConfig().getInterceptors().get(1).getInterceptor()).setAcceptedPatterns(ACCEPT_ALL_PATTERNS_CHECKER);
    actionOne = (SimpleAction) proxy.getAction();
    actionOne.setAliasSource("name to be copied");
    // prevent ERROR result
    actionOne.setFoo(-1);
    actionOne.setBar(1);
    proxy.execute();
    assertEquals("name to be copied", actionOne.getAliasSource());
    assertEquals(actionOne.getAliasSource(), actionOne.getAliasDest());
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ActionProxy(com.opensymphony.xwork2.ActionProxy) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy) HashMap(java.util.HashMap) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 49 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class ChainingInterceptorWithConfigTest method testTwoExcludesPropertiesChained.

public void testTwoExcludesPropertiesChained() throws Exception {
    assertNotNull(objectFactory);
    ActionProxy proxy = actionProxyFactory.createActionProxy("", CHAINED_ACTION, null, null);
    SimpleAction chainedAction = (SimpleAction) proxy.getAction();
    chainedAction.setBar(1);
    chainedAction.setFoo(1);
    chainedAction.setBlah("WW-4528");
    proxy.execute();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 50 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class ConversionErrorInterceptorTest method testFieldErrorAdded.

public void testFieldErrorAdded() throws Exception {
    conversionErrors.put("foo", new ConversionData(123L, int.class));
    SimpleAction action = new SimpleAction();
    mockInvocation.expectAndReturn("getAction", action);
    stack.push(action);
    mockInvocation.matchAndReturn("getAction", action);
    assertNull(action.getFieldErrors().get("foo"));
    interceptor.doIntercept(invocation);
    assertTrue(action.hasFieldErrors());
    assertNotNull(action.getFieldErrors().get("foo"));
}
Also used : ConversionData(com.opensymphony.xwork2.conversion.impl.ConversionData)

Aggregations

SimpleAction (com.opensymphony.xwork2.SimpleAction)32 ActionProxy (com.opensymphony.xwork2.ActionProxy)24 HashMap (java.util.HashMap)23 LinkedHashMap (java.util.LinkedHashMap)17 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)14 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)8 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)7 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)7 OgnlUtil (com.opensymphony.xwork2.ognl.OgnlUtil)6 Action (com.opensymphony.xwork2.Action)5 TestBean (com.opensymphony.xwork2.TestBean)5 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)5 ValueStack (com.opensymphony.xwork2.util.ValueStack)5 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)4 ModelDrivenAction (com.opensymphony.xwork2.ModelDrivenAction)3 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)3 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)3 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)3 MockConfigurationProvider (com.opensymphony.xwork2.config.providers.MockConfigurationProvider)2 MockResult (com.opensymphony.xwork2.mock.MockResult)2