|
Struts example source code file (ActionAutowiringInterceptorTest.java)
The Struts ActionAutowiringInterceptorTest.java source code/* * 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 prov = new XmlConfigurationProvider("xwork-default.xml"); prov.setThrowExceptionOnDuplicateBeans(false); XmlConfigurationProvider c = new XmlConfigurationProvider("com/opensymphony/xwork2/spring/xwork-autowire.xml"); 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); } protected void loadSpringApplicationContextIntoApplication(ApplicationContext appContext) { Map<Object, Object> application = new HashMap Other Struts examples (source code examples)Here is a short list of links related to this Struts ActionAutowiringInterceptorTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.