<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Xebia Blog &#187; stripes spring unit test actionbean</title>
	<atom:link href="http://blog.xebia.com/tag/stripes-spring-unit-test-actionbean/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xebia.com</link>
	<description>Software development done right!</description>
	<lastBuildDate>Wed, 01 Feb 2012 00:30:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Unit testing a Stripes ActionBean wired with Spring Beans</title>
		<link>http://blog.xebia.com/2008/12/16/unit-testing-a-stripes-actionbean-wired-with-spring-beans/</link>
		<comments>http://blog.xebia.com/2008/12/16/unit-testing-a-stripes-actionbean-wired-with-spring-beans/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 11:03:24 +0000</pubDate>
		<dc:creator>Jeroen van Wilgenburg</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/blog.xebia.com/www/wp-content/plugins/autometa/autometa.php</b> on line <b>303</b><br />
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[stripes spring unit test actionbean]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=847</guid>
		<description><![CDATA[Last friday I spent quite some time to figure out how to initialize my Spring beans when unit-testing some Stripes ActionBeans. There wasn&#8217;t any Spring context at all and you really need that for integration testing. How to set up a unit test with Stripes is explained pretty good here. I applied approach 2, run [...]]]></description>
			<content:encoded><![CDATA[<p>Last friday I spent quite some time to figure out how to initialize my Spring beans when unit-testing some Stripes ActionBeans. There wasn&#8217;t any Spring context at all and you really need that for integration testing.<br />
<span id="more-847"></span><br />
How to set up a unit test with Stripes is explained pretty good <a href="http://stripesframework.org/display/stripes/Unit+Testing" target="blank">here</a>.<br />
I applied approach 2, run the tests within a mock container.</p>
<p>My unit test is extending <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.html" target="_blank">AbstractTransactionalJUnit4SpringContextTests</a> and is annotated with @RunWith(SpringJUnit4ClassRunner.class) and @ContextConfiguration(locations = { &#8230; })</p>
<p>The code I&#8217;m about to show should be put after initialzing the MockServletContext. I recommend using a method annotated with @Before where you do the initialization (I called mine setUpMockServletContext)<br />
Since the unit tests run before the Spring config files are put in the WEB-INF directory, you have to tell Stripes where to find the configuration files:</p>
<pre lang="java">context.addInitParameter("contextConfigLocation",
"classpath:dataSourceContext.xml\nclasspath:daoContext.xml\nclasspath:applicationContext.xml");</pre>
<p>Stripes isn&#8217;t smart enough (yet?) to read the @ContextConfiguration annotation, but this file will probably included somewhere in a parent-unit test, so it isn&#8217;t a big deal.</p>
<p>The final step is telling Spring to initialize its context with your MockServletContext (note that this is a Stripes MockServletContext, not the one used by Spring!):</p>
<pre lang="java">ContextLoaderListener springContextLoader = new ContextLoaderListener();
springContextLoader.contextInitialized(new ServletContextEvent(context));</pre>
<p>That&#8217;s all there is to it. Let&#8217;s hope google picks up this blog and other people can handle this tiny problem quicker than I did.</p>
<h3>Sources</h3>
<p>* <a href="http://static.springframework.org/spring/docs/2.5.x/reference/testing.html" target="_blank">Unit testing with Spring</a><br />
* <a href="http://stripesframework.org/display/stripes/Unit+Testing" target="_blank">Unit testing Stripes</a><br />
* <a href="http://www.stripesframework.org/display/stripes/Spring+with+Stripes">Using Spring with Stripes</a><br />
* <a href="http://www.nabble.com/stripes-users-f16325.html">Stripes mailing list</a></p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2008/12/16/unit-testing-a-stripes-actionbean-wired-with-spring-beans/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2008%2F12%2F16%2Funit-testing-a-stripes-actionbean-wired-with-spring-beans%2F&amp;title=Unit%20testing%20a%20Stripes%20ActionBean%20wired%20with%20Spring%20Beans" id="wpa2a_2"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2008/12/16/unit-testing-a-stripes-actionbean-wired-with-spring-beans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.xebia.com/tag/stripes-spring-unit-test-actionbean/feed/ ) in 0.50673 seconds, on Feb 9th, 2012 at 6:40 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 9th, 2012 at 7:40 pm UTC -->
