Search in sources :

Example 31 with SimpleAction

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

the class ActionAutowiringInterceptorTest method testSetAutowireType.

public void testSetAutowireType() throws Exception {
    XmlConfigurationProvider prov = new StrutsXmlConfigurationProvider("xwork-default.xml");
    container.inject(prov);
    prov.setThrowExceptionOnDuplicateBeans(false);
    XmlConfigurationProvider c = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/spring/xwork-autowire.xml");
    container.inject(c);
    loadConfigurationProviders(c, prov);
    StaticWebApplicationContext appContext = new StaticWebApplicationContext();
    loadSpringApplicationContextIntoApplication(appContext);
    ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor();
    interceptor.init();
    SimpleAction action = new SimpleAction();
    ActionInvocation invocation = new TestActionInvocation(action);
    interceptor.intercept(invocation);
    ApplicationContext loadedContext = interceptor.getApplicationContext();
    assertEquals(appContext, loadedContext);
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) WebApplicationContext(org.springframework.web.context.WebApplicationContext) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 32 with SimpleAction

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

the class ActionAutowiringInterceptorTest method testIfApplicationContextIsNullThenBeanWillNotBeWiredUp.

public void testIfApplicationContextIsNullThenBeanWillNotBeWiredUp() throws Exception {
    ActionContext.of(new HashMap<>()).withApplication(new HashMap<>()).bind();
    ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor();
    interceptor.init();
    SimpleAction action = new SimpleAction();
    ActionInvocation invocation = new TestActionInvocation(action);
    TestBean bean = action.getBean();
    // If an exception is thrown here, things are going to go wrong in
    // production
    interceptor.intercept(invocation);
    assertEquals(bean, action.getBean());
}
Also used : HashMap(java.util.HashMap) TestBean(com.opensymphony.xwork2.TestBean) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 33 with SimpleAction

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

the class ActionsFromSpringTest method testLoadSimpleAction.

public void testLoadSimpleAction() throws Exception {
    ActionProxy proxy = actionProxyFactory.createActionProxy(null, "simpleAction", null, null);
    Object action = proxy.getAction();
    Action expected = (Action) appContext.getBean("simple-action");
    assertEquals(expected.getClass(), action.getClass());
}
Also used : SimpleAction(com.opensymphony.xwork2.SimpleAction) Action(com.opensymphony.xwork2.Action) ActionProxy(com.opensymphony.xwork2.ActionProxy)

Example 34 with SimpleAction

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

the class ActionsFromSpringTest method testLoadActionWithDependencies.

public void testLoadActionWithDependencies() throws Exception {
    ActionProxy proxy = actionProxyFactory.createActionProxy(null, "dependencyAction", null, null);
    SimpleAction action = (SimpleAction) proxy.getAction();
    assertEquals("injected", action.getBlah());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 35 with SimpleAction

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

the class ActionsFromSpringTest method testAutoProxiedAction.

public void testAutoProxiedAction() throws Exception {
    ActionProxy proxy = actionProxyFactory.createActionProxy(null, "autoProxiedAction", null, null);
    SimpleAction action = (SimpleAction) proxy.getAction();
    String result = action.execute();
    assertEquals(Action.INPUT, result);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) SimpleAction(com.opensymphony.xwork2.SimpleAction)

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