⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionsfromspringtest.java

📁 在Struts2中的jar包xwork的源代码.版本为2.0.7
💻 JAVA
字号:
/* * Created on Jun 12, 2004 */package com.opensymphony.xwork2.spring;import com.opensymphony.xwork2.*;import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;import org.springframework.context.ApplicationContext;/** * Test loading actions from the Spring Application Context. * * @author Simon Stewart */public class ActionsFromSpringTest extends XWorkTestCase {    private ApplicationContext appContext;    protected void setUp() throws Exception {        super.setUp();        // Set up XWork        loadConfigurationProviders(new XmlConfigurationProvider("com/opensymphony/xwork2/spring/actionContext-xwork.xml"));        appContext = ((SpringObjectFactory)container.getInstance(ObjectFactory.class)).appContext;    }    public void testLoadSimpleAction() throws Exception {        ActionProxy proxy = actionProxyFactory.createActionProxy(null, "simpleAction", null);        Object action = proxy.getAction();        Action expected = (Action) appContext.getBean("simple-action");        assertEquals(expected.getClass(), action.getClass());    }    public void testLoadActionWithDependencies() throws Exception {        ActionProxy proxy = actionProxyFactory.createActionProxy(null, "dependencyAction", null);        SimpleAction action = (SimpleAction) proxy.getAction();        assertEquals("injected", action.getBlah());    }    public void testProxiedActionIsNotStateful() throws Exception {        ActionProxy proxy = actionProxyFactory.createActionProxy(null, "proxiedAction", null);        SimpleAction action = (SimpleAction) proxy.getAction();        action.setBlah("Hello World");        proxy = actionProxyFactory.createActionProxy(null, "proxiedAction", null);        action = (SimpleAction) proxy.getAction();        // If the action is a singleton, this test will fail        SimpleAction sa = new SimpleAction();        assertEquals(sa.getBlah(), action.getBlah());        // And if the advice is not being applied, this will be SUCCESS.        String result = action.execute();        assertEquals(Action.INPUT, result);    }    public void testAutoProxiedAction() throws Exception {        ActionProxy proxy = actionProxyFactory.createActionProxy(null, "autoProxiedAction", null);        SimpleAction action = (SimpleAction) proxy.getAction();        String result = action.execute();        assertEquals(Action.INPUT, result);    }        public void testActionWithSpringResult() throws Exception {    	        ActionProxy proxy = actionProxyFactory.createActionProxy(null, "simpleActionSpringResult", null);    	                    	        proxy.execute();    	            	        SpringResult springResult = (SpringResult) proxy.getInvocation().getResult();    	        assertTrue(springResult.isInitialize());    	        assertNotNull(springResult.getStringParameter());    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -