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

📄 actionautowiringinterceptortest.java

📁 在Struts2中的jar包xwork的源代码.版本为2.0.7
💻 JAVA
字号:
/* * Created on 6/11/2004 */package com.opensymphony.xwork2.spring.interceptor;import com.opensymphony.xwork2.*;import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;import org.springframework.context.ApplicationContext;import org.springframework.web.context.WebApplicationContext;import org.springframework.web.context.support.StaticWebApplicationContext;import java.util.HashMap;import java.util.Map;/** * @author Simon Stewart */public class ActionAutowiringInterceptorTest extends XWorkTestCase {    public void testShouldAutowireAction() throws Exception {        StaticWebApplicationContext context = new StaticWebApplicationContext();        context.getBeanFactory().registerSingleton("bean", new TestBean());        TestBean bean = (TestBean) context.getBean("bean");        loadSpringApplicationContextIntoApplication(context);        SimpleAction action = new SimpleAction();        ActionInvocation invocation = new TestActionInvocation(action);        ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor();        interceptor.setApplicationContext(context);        interceptor.init();        interceptor.intercept(invocation);        assertEquals(bean, action.getBean());    }    public void testSetAutowireType() throws Exception {        XmlConfigurationProvider c = new XmlConfigurationProvider("com/opensymphony/xwork2/spring/xwork-autowire.xml");        configurationManager.addConfigurationProvider(c);        configurationManager.reload();        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);    }    protected void loadSpringApplicationContextIntoApplication(ApplicationContext appContext) {        Map application = new HashMap();        application.put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);        Map context = new HashMap();        context.put(ActionContext.APPLICATION, application);        ActionContext actionContext = new ActionContext(context);        ActionContext.setContext(actionContext);    }    public void testLoadsApplicationContextUsingWebApplicationContextUtils() throws Exception {        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);    }    public void testIfApplicationContextIsNullThenBeanWillNotBeWiredUp() throws Exception {        Map context = new HashMap();        context.put(ActionContext.APPLICATION, new HashMap());        ActionContext actionContext = new ActionContext(context);        ActionContext.setContext(actionContext);        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());    }}

⌨️ 快捷键说明

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