<?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>redstream &#187; Spring Framework</title>
	<atom:link href="http://www.redstream.nl/category/technical/spring-framework-technical/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redstream.nl</link>
	<description>Pragmatic Integrators</description>
	<lastBuildDate>Fri, 27 Jan 2012 19:31:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unit test your Spring/Hibernate and MongoDB setup</title>
		<link>http://www.redstream.nl/2011/07/27/unit-test-your-springhibernate-and-mongodb-setup/</link>
		<comments>http://www.redstream.nl/2011/07/27/unit-test-your-springhibernate-and-mongodb-setup/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 08:00:12 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Spring Framework]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2807</guid>
		<description><![CDATA[In my previous post I described how you can setup Spring and Hibernate in combination with the MongoDB. In this post I show you how you can write your unit test for this setup including a workaround for the fact &#8230; <a href="http://www.redstream.nl/2011/07/27/unit-test-your-springhibernate-and-mongodb-setup/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F07%2F27%2Funit-test-your-springhibernate-and-mongodb-setup%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F07%2F27%2Funit-test-your-springhibernate-and-mongodb-setup%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>In my <a href="http://www.redstream.nl/2011/07/14/use-spring-and-hibernate-with-mongodb/">previous</a> post I described how you can setup <a href="http://www.springsource.org/">Spring</a> and <a href="http://www.hibernate.org/">Hibernate</a> in combination with the <a href="http://www.mongodb.org/">MongoDB</a>. In this post I show you how you can write your unit test for this setup including a workaround for the fact that there isn&#8217;t an embedded version of MongoDB.<br />
<span id="more-2807"></span><br />
Of course you can check manually if your code works by checking the content of the MongoDB. You can use <a href="http://www.mongodb.org/display/DOCS/mongo+-+The+Interactive+Shell">the MongoDB shell</a> or the REST interface by using &#8216;curl&#8217; (when using REST make sure you start the database with the &#8216;&#8211;rest&#8217; option). For example see the result of <code>curl 'http://localhost:28017/redstream/logItem/'</code> </p>
<blockquote><p>
pascal@~$ curl &#8216;http://localhost:28017/redstream/logItem/&#8217;<br />
{<br />
  &#8220;offset&#8221; : 0,<br />
  &#8220;rows&#8221;: [<br />
    { "_id" : { "$oid" : "4e1c2ffca0eee881985e04f0" }, "_class" : "nl.redstream.mongo.entity.LogItem", "message" : "just some text 0" } ,<br />
    { "_id" : { "$oid" : "4e1c2ffda0eee881985e04f1" }, "_class" : "nl.redstream.mongo.entity.LogItem", "message" : "just some text 1" } ,<br />
    { "_id" : { "$oid" : "4e1c2ffda0eee881985e04f2" }, "_class" : "nl.redstream.mongo.entity.LogItem", "message" : "just some text 2" } ,<br />
    { "_id" : { "$oid" : "4e1c4289a0ee3d15a8af39d3" }, "_class" : "nl.redstream.mongo.entity.LogItem", "message" : "just some text 0" }<br />
  ],<br />
  &#8220;total_rows&#8221; : 3 ,<br />
  &#8220;query&#8221; : {} ,<br />
  &#8220;millis&#8221; : 0<br />
}<br />
pascal@~$
</p></blockquote>
<p>However, when building software you want your test to be performed automatically so we use JUnit to perform the tests and checks. And I use JUnit to start and stop my local MongoDB instance. Here is how it works (I assume you have the same project setup as I created in my <a href="http://www.redstream.nl/2011/07/14/use-spring-and-hibernate-with-mongodb/">previous</a> post):</p>
<ul>
<li>Wire the Spring beans in your test context</li>
<p>I created a SpringContext class for testing purposes:</p>

<div class="wp_codebox"><table><tr id="p28074"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code" id="p2807code4"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.redstream.mongo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.ApplicationContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.support.ClassPathXmlApplicationContext</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Only to be used in test classes!!
 * 
 * @author pascal
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyTestApplicationContext <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> MyTestApplicationContext testContext <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    ApplicationContext context <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> MyTestApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> MyTestApplicationContext getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>testContext <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            testContext <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyTestApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            testContext.<span style="color: #006633;">initialise</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> testContext<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> initialise<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClassPathXmlApplicationContext<span style="color: #009900;">&#40;</span>
                <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;spring-config.xml&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> getBean<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> context.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> ApplicationContext getSpringContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> context<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>With this class I can access my Spring beans easily in my Unit tests.</p>
<li>Write the test class</li>
<p>I use <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/ProcessBuilder.html">ProcessBuilder</a> to start and stop the local MongoDB instance before the test class is executed. The base Testclass looks like this:</p>

<div class="wp_codebox"><table><tr id="p28075"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code" id="p2807code5"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.redstream.mongo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.After</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.AfterClass</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Before</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.BeforeClass</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MongoDBTest <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>MongoDBTest.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aprocess+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Process</span></a> p <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    @Before
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//@Todo Run mongo with a test specific .js file to produce initial data state</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @After
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> tearDown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//@Todo Drop database</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @BeforeClass
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> beforeClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> command <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;/Users/pascal/development/mongodb-osx-x86_64-1.8.2/bin/mongod&quot;</span>, <span style="color: #0000ff;">&quot;--dbpath&quot;</span>, <span style="color: #0000ff;">&quot;/Users/pascal/development/mongodb/data&quot;</span>, <span style="color: #0000ff;">&quot;--rest&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        ProcessBuilder pb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ProcessBuilder<span style="color: #009900;">&#40;</span>command<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        p <span style="color: #339933;">=</span> pb.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Process started with pid: &quot;</span> <span style="color: #339933;">+</span> p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @AfterClass
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> afterClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Stop mongod process</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> processClosed <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>p <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>processClosed<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                    p.<span style="color: #006633;">destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    processClosed <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Process destroyed: &quot;</span> <span style="color: #339933;">+</span> p.<span style="color: #006633;">exitValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aillegalthreadstateexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IllegalThreadStateException</span></a> itse<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    logger.<span style="color: #006633;">warn</span><span style="color: #009900;">&#40;</span>itse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    processClosed <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And the actual test class:</p>

<div class="wp_codebox"><table><tr id="p28076"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code" id="p2807code6"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.redstream.mongo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">junit.framework.Assert</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nl.redstream.mongo.entity.LogItem</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nl.redstream.mongo.services.LogService</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.bson.types.ObjectId</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Before</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LogServiceTest <span style="color: #000000; font-weight: bold;">extends</span> MongoDBTest <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>LogServiceTest.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> LogService<span style="color: #339933;">&lt;</span>LogItem<span style="color: #339933;">&gt;</span> service <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testCreateAndFindLog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
        ObjectId id <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            LogItem log <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LogItem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            log.<span style="color: #006633;">setMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;just some text &quot;</span> <span style="color: #339933;">+</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            id <span style="color: #339933;">=</span> service.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>log<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;log.id = &quot;</span> <span style="color: #339933;">+</span> id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        LogItem logFound <span style="color: #339933;">=</span> service.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;log = &quot;</span> <span style="color: #339933;">+</span> logFound.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertNotNull</span><span style="color: #009900;">&#40;</span>logFound<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Before
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
        logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;setting up test&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">setUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        service <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>LogService<span style="color: #339933;">&lt;</span>LogItem<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> MyTestApplicationContext.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;logService&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//@TODO Run mongo with a test specific .js file to produce initial data state</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<li>Run it!</li>
<p>The test output shows it ran successfully:</p>
<blockquote><p>
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
 T E S T S<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Running nl.redstream.mongo.LogServiceTest<br />
DEBUG [main] nl.redstream.mongo.MongoDBTest: Process started with pid: java.lang.UNIXProcess@603b1d04<br />
INFO  [main] nl.redstream.mongo.LogServiceTest: setting up test<br />
DEBUG [main] nl.redstream.mongo.services.MongoDBLoggerServiceImpl: Adding a new LogItem instance<br />
DEBUG [main] nl.redstream.mongo.LogServiceTest: log.id = 4e2fc241a0eea3de77684fdf<br />
DEBUG [main] nl.redstream.mongo.services.MongoDBLoggerServiceImpl: Adding a new LogItem instance<br />
DEBUG [main] nl.redstream.mongo.LogServiceTest: log.id = 4e2fc241a0eea3de77684fe0<br />
DEBUG [main] nl.redstream.mongo.services.MongoDBLoggerServiceImpl: Adding a new LogItem instance<br />
DEBUG [main] nl.redstream.mongo.LogServiceTest: log.id = 4e2fc241a0eea3de77684fe1<br />
DEBUG [main] nl.redstream.mongo.LogServiceTest: log = LogItem [id=4e2fc241a0eea3de77684fe1, message=just some text 2, timestamp=null]<br />
INFO  [main] nl.redstream.mongo.MongoDBTest:  Process destroyed: 12<br />
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.798 sec</p>
<p>Results :</p>
<p>Tests run: 1, Failures: 0, Errors: 0, Skipped: 0</p></blockquote>
</ul>
<p>There is definitely room for improvement, like adding the possibility to run &#8216;.js&#8217; scripts to set the database in a predefined state in the @Before method of the test class and remove the database in the @After method.<br />
Another thing that bothered me is the &#8216;Thread.sleep&#8217; that I had to add at some places to make it work. Nevertheless I showed how to setup a basic test case with MongoDB/Spring combination and if you have a better solution please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/07/27/unit-test-your-springhibernate-and-mongodb-setup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Use Spring and Hibernate with MongoDB</title>
		<link>http://www.redstream.nl/2011/07/14/use-spring-and-hibernate-with-mongodb/</link>
		<comments>http://www.redstream.nl/2011/07/14/use-spring-and-hibernate-with-mongodb/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 09:12:53 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Spring Framework]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2801</guid>
		<description><![CDATA[One of the requirements we have for one of our Mule ESB implementations is to log the messages that went through the ESB (especially handy during development and testing). There has been written a lot already about logging with Mule &#8230; <a href="http://www.redstream.nl/2011/07/14/use-spring-and-hibernate-with-mongodb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F07%2F14%2Fuse-spring-and-hibernate-with-mongodb%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F07%2F14%2Fuse-spring-and-hibernate-with-mongodb%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>One of the requirements we have for one of our Mule ESB implementations is to log the messages that went through the ESB (especially handy during development and testing). There has been written a lot already about logging with Mule so I am not going to discuss that again. In this post I&#8217;ll only show you how you can use Spring/Hibernate and <a href="http://www.mongodb.org/">MongoDB</a> to store your messages in the MongoDB, because a document-oriented database like MongoDB is a nice fit for this requirement.<br />
<span id="more-2801"></span></p>
<p>The first thing to do is to install MongoDB on your machine (unfortunately it is not yet possible to run it embedded so we use a local instance instead). For installation see <a href="http://www.mongodb.org/display/DOCS/Quickstart+OS+X">this</a>.</p>
<p>After MongoDB is installed we can create a new standard Maven project and modify the generated pom.xml to the following <a href="http://www.redstream.nl/wp-content/uploads/2011/07/pom.xml">pom.xml</a>.</p>
<p>Next step is the creation of the Hibernate Entity class like this:</p>

<div class="wp_codebox"><table><tr id="p280110"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code" id="p2801code10"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.redstream.mongo.entity</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Entity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Id</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Table</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.bson.types.ObjectId</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Model object 
 * @author pascal
 */</span>
@<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aentity+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Entity</span></a>
@Table<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;logItems&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LogItem <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aserializable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Serializable</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
    @Id
    <span style="color: #000000; font-weight: bold;">private</span> ObjectId id<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> message<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> timestamp<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> ObjectId getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span>ObjectId id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> message<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMessage<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">message</span> <span style="color: #339933;">=</span> message<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getTimestamp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTimestamp<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> timestamp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">timestamp</span> <span style="color: #339933;">=</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;LogItem [id=&quot;</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;, message=&quot;</span> <span style="color: #339933;">+</span> message <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;, timestamp=&quot;</span> <span style="color: #339933;">+</span> timestamp <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;]&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>As you might notice I have used the ObjectId as primary Id. I was forced to this by bug <a href="https://jira.springsource.org/browse/DATADOC-176">DATADOC-176</a> which only recently got fixed.</p>
<p>The Dao and Service object classes that are used to access the MongoDB are:</p>
<ul>
<li><a href="http://www.redstream.nl/wp-content/uploads/2011/07/BaseDao.java">BaseDao.java</a></li>
<li><a href="http://www.redstream.nl/wp-content/uploads/2011/07/AbstractBaseDao.java">AbstractBaseDao.java</a></li>
<li><a href="http://www.redstream.nl/wp-content/uploads/2011/07/LogItemDaoImpl.java">LogItemDaoImpl.java</a></li>
<li><a href="http://www.redstream.nl/wp-content/uploads/2011/07/LogService.java">LogService.java</a></li>
<li><a href="http://www.redstream.nl/wp-content/uploads/2011/07/MongoDBLoggerServiceImpl.java">MongoDBLoggerServiceImpl.java</a></li>
</ul>
<p>Now wire this all together with the following spring config files:</p>

<div class="wp_codebox"><table><tr id="p280111"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p2801code11"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xsi:schemaLocation</span>=</span>
<span style="color: #009900;">               <span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans</span>
<span style="color: #009900;">                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;import</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;spring-mongodb-config.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;logService&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;nl.redstream.mongo.services.MongoDBLoggerServiceImpl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dao&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;logDao&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;logDao&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;nl.redstream.mongo.dao.LogItemDaoImpl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mongoTemplate&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;mongoTemplate&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>and the &#8216;spring-mongodb-config.xml&#8217; (as described <a href="http://static.springsource.org/spring-data/data-document/docs/1.0.0.M3/reference/html/#mongodb-connectors">here</a>):</p>

<div class="wp_codebox"><table><tr id="p280112"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p2801code12"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:mongo</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/data/mongo&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xsi:schemaLocation</span>=</span>
<span style="color: #009900;">               <span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans</span>
<span style="color: #009900;">                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd</span>
<span style="color: #009900;">                http://www.springframework.org/schema/data/mongo</span>
<span style="color: #009900;">                http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- Default bean name is 'mongo' --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mongo:mongo</span> <span style="color: #000066;">host</span>=<span style="color: #ff0000;">&quot;localhost&quot;</span> <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;27017&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- OPTIONAL: configure &lt;mongo:options /&gt; --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mongo:mongo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mongo:db-factory</span> <span style="color: #000066;">dbname</span>=<span style="color: #ff0000;">&quot;redstream&quot;</span> <span style="color: #000066;">mongo-ref</span>=<span style="color: #ff0000;">&quot;mongo&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mongoTemplate&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.data.document.mongodb.MongoTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;mongoDbFactory&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>That&#8217;s it. Now you have a foundation to start using MongoDB with Spring and Hibernate classes. In the next post I will show how you can test this setup without manually having to start and stop MongoDB.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/07/14/use-spring-and-hibernate-with-mongodb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Citrus testcase example: CSV File Inbound -&gt; Xml Http Outbound</title>
		<link>http://www.redstream.nl/2011/04/30/citrus-testcase-example-csv-file-inbound-xml-http-outbound/</link>
		<comments>http://www.redstream.nl/2011/04/30/citrus-testcase-example-csv-file-inbound-xml-http-outbound/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 06:51:01 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Citrus]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[Spring Integration]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2679</guid>
		<description><![CDATA[As promised I&#8217;m going to show a test case for which I have used Citrus to implement it. The case is like this: In a predefined folder on a machine a character-separated file is placed. This file is picked up &#8230; <a href="http://www.redstream.nl/2011/04/30/citrus-testcase-example-csv-file-inbound-xml-http-outbound/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F04%2F30%2Fcitrus-testcase-example-csv-file-inbound-xml-http-outbound%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F04%2F30%2Fcitrus-testcase-example-csv-file-inbound-xml-http-outbound%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>As <a href="http://www.redstream.nl/2011/04/15/setup-citrus-for-testing-mule-esb/">promised</a> I&#8217;m going to show a test case for which I have used <a href="http://www.citrusframework.org/">Citrus</a> to implement it. The case is like this:<br />
In a predefined folder on a machine a character-separated file is placed. This file is picked up by our <a href="http://www.mulesoft.org/what-mule-esb">Mule ESB</a> application. The content is transformed to XML and this XML document is posted to another application over HTTP. This application responds with XML document telling the document was processed correctly.<br />
To test this interface with Citrus we have to perform the following steps:</p>
<ol>
<li>Copy the input test-file to the predefined folder so it is picked up by the test instance of our Mule ESB</li>
<p>Our Mule ESB will poll a directory each second to check if there is placed a new file to process. Our test case starts by having Citrus putting a test file in the directory .</p>
<li>Have Citrus listen on a predefined HTTP port to receive the XML message over HTTP</li>
<p>Inside our Mule ESB the file is transformed to XML message and posted on a HTTP port to be processed by the &#8216;ORDER&#8217; system. We have configured Citrus to listen on this specific HTTP port to pick up the XML message.</p>
<li>Reply to the received message with a predefined XML message</li>
<p>This steps mimics the &#8216;ORDER&#8217; system as it would normally process the incoming XML message and respond with another XML message. In this case Citrus will send back a predefined XML message as response.
</ol>
<p><span id="more-2679"></span><br />
The citrus-config.xml for this test case can be found <a href="http://www.redstream.nl/wp-content/uploads/2011/04/citrus-context.xml">here</a>. I will explain the content of the config file next:</p>

<div class="wp_codebox"><table><tr id="p267922"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p2679code22"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;citrusJMSConnectionFactory&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brokerURL&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;vm://localhost:61616&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;user&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;password&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This part defines a &#8216;in-memory&#8217; JMS provider to be used by Citrus. We will see later how we use it to check the incoming HTTP request (as described <a href="http://www.citrusframework.org/reference/html/index.html#http-message-handler-jms">here</a> in the Citrus reference guide).</p>

<div class="wp_codebox"><table><tr id="p267923"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2679code23"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;namespaceContextBuilder&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.xml.namespace.NamespaceContextBuilder&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;namespaceMappings&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;ns1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>http://www.redstream.nl/invoice<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Here we define the namespaces that are used in the xml messages in our test. We will use this namespace in the test to check values of certain XML elements.</p>

<div class="wp_codebox"><table><tr id="p267924"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p2679code24"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;redstreamIntegrationTests&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.TestSuite&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tasksBefore&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.actions.ExecuteSQLAction&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;rsDataSource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;statements&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>DELETE FROM RS_LOGS<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>With this part I have Citrus clean up my log table in the database of my Mule ESB. We log all incoming and outgoing messages in our ESB to the database.</p>

<div class="wp_codebox"><table><tr id="p267925"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p2679code25"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- manadatory if XML files are used in a test --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;xmlMessageValidator&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.validation.xml.DomXmlMessageValidator&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;schemaRepository&quot;</span></span>
<span style="color: #009900;">           <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.xml.XsdSchemaRepository&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;schemas&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.xml.xsd.SimpleXsdSchema&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;xsd&quot;</span></span>
<span style="color: #009900;">                               <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;classpath:schemas/rs_invoice_0.3.xsd&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>When you want to work with XML messages in your test (and that is very likely nowadays) you will need to define an &#8216;xmlMessageValidator&#8217;. And to be able to validate the message against an XML schema you will need to define the schemas in the &#8216;schemaRepository&#8217; as I have done here.</p>

<div class="wp_codebox"><table><tr id="p267926"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2679code26"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;rsDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.commons.dbcp.BasicDataSource&quot;</span> <span style="color: #000066;">destroy-method</span>=<span style="color: #ff0000;">&quot;close&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:oracle:thin:@test-vm:1521:XE&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;user&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;password&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverClassName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;oracle.jdbc.xa.client.OracleXADataSource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;removeAbandoned&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This is the datasource that Citrus can use to access the database that is used by our Mule ESB application. We use this datasource to clean up the logtable and can use it to perform validations after messages have been processed.</p>

<div class="wp_codebox"><table><tr id="p267927"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2679code27"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;citrus:message-channel-sender</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;invoiceFileSender&quot;</span> <span style="color: #000066;">channel</span>=<span style="color: #ff0000;">&quot;fileOutboundChannel&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;file:outbound-channel-adapter</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;invoice-files-out&quot;</span> <span style="color: #000066;">channel</span>=<span style="color: #ff0000;">&quot;fileOutboundChannel&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">directory</span>=<span style="color: #ff0000;">&quot;file://Volumes/staging/invoice&quot;</span> <span style="color: #000066;">filename-generator</span>=<span style="color: #ff0000;">&quot;test-filename-generator&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;test-filename-generator&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;nl.redstream.citrus.TestFileNameGenerator&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;si:channel</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;fileOutboundChannel&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>This is a mix of Citrus with spring-integration configuration. With this configuration I am able to send files to my test VM with Citrus. It also shows how easy it is to mix Citrus with spring-integration.</p>

<div class="wp_codebox"><table><tr id="p267928"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2679code28"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- receive Invoice HTTP request --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;citrus-http:server</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;orderHttpServer&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;8060&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;/services/post-invoice&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">deamon</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">message-handler</span>=<span style="color: #ff0000;">&quot;jmsForwardingMessageHandler&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">auto-start</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>Definition of the HTTP Server in Citrus which listens on port 8060 for a request of our Mule ESB.</p>

<div class="wp_codebox"><table><tr id="p267929"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p2679code29"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jmsForwardingMessageHandler&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.adapter.handler.JmsConnectingMessageHandler&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;destinationName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Citrus.order-response&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connectionFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;citrusJMSConnectionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replyTimeout&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;6000&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- Process all received requests --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;citrus:jms-sync-message-receiver</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;orderRequestReceiver&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">destination-name</span>=<span style="color: #ff0000;">&quot;Citrus.order-response&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">connection-factory</span>=<span style="color: #ff0000;">&quot;citrusJMSConnectionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;citrus:jms-reply-message-sender</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;orderResponseSender&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">reply-destination-holder</span>=<span style="color: #ff0000;">&quot;orderRequestReceiver&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">connection-factory</span>=<span style="color: #ff0000;">&quot;citrusJMSConnectionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>THis part forwards the incoming HTTP request to a JMS endpoint. In our test we can perform tests on this incoming JMS message and check if it is valid.</p>
<p>Next thing I want to explain is the test-config.xml itself. I think it is quite self-explainatory:</p>

<div class="wp_codebox"><table><tr id="p267930"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code" id="p2679code30"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.citrusframework.org/schema/testcase&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">xmlns:ws</span>=<span style="color: #ff0000;">&quot;http://www.citrusframework.org/schema/ws/testcase&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">xmlns:spring</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans</span>
<span style="color: #009900;">              http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</span>
<span style="color: #009900;">                  http://www.citrusframework.org/schema/ws/testcase</span>
<span style="color: #009900;">                  http://www.citrusframework.org/schema/ws/testcase/citrus-ws-testcase.xsd</span>
<span style="color: #009900;">                  http://www.citrusframework.org/schema/testcase</span>
<span style="color: #009900;">                  http://www.citrusframework.org/schema/testcase/citrus-testcase.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;testcase</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Testcase001Test&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta-info<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Redstream Development Team<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;creationdate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2011-04-24<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/creationdate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>DRAFT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/meta-info<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tests Testcase001<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;actions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;send</span> <span style="color: #000066;">with</span>=<span style="color: #ff0000;">&quot;invoiceFileSender&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;classpath:data/testcase001.txt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/send<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;receive</span> <span style="color: #000066;">with</span>=<span style="color: #ff0000;">&quot;orderRequestReceiver&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">schema-validation</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;validate</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;//ns1:post-invoice/ns1:CompanyCode&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;validate</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;string:count(//ns1:post-invoice/ns1:InvoiceLine/ns1:DocID)&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;rs_address&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;order-purchase-invoice-queue&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extract<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;count(//ns1:post-invoice/ns1:InvoiceLine/ns1:DocID)&quot;</span> <span style="color: #000066;">variable</span>=<span style="color: #ff0000;">&quot;${nrOfInvoiceLines}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extract<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/receive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${nrOfInvoiceLines}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;send</span> <span style="color: #000066;">with</span>=<span style="color: #ff0000;">&quot;orderResponseSender&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;classpath:data/response-testcase001.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/send<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/actions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/testcase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spring:beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The first action that is done is sending a file to my Mule ESB. The next step is that I wait for the response from my ESB. When I received that I check the contents of XML message at some points and check if it is valid against the schema.<br />
Then after echoing the number of invoice lines I have Citrus return the HTTP request with a fixed XML response so the Mule ESB ends this action successfully.<br />
That completes this example of how to use Citrus to test your ESB implemention. I hope it is more clear now how you can use Citrus  for your (automated) integration tests with this real life example.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/04/30/citrus-testcase-example-csv-file-inbound-xml-http-outbound/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Combining ActiveMQ, Tomcat and Mule ESB</title>
		<link>http://www.redstream.nl/2011/01/17/combining-activemq-tomcat-and-mule-esb/</link>
		<comments>http://www.redstream.nl/2011/01/17/combining-activemq-tomcat-and-mule-esb/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 13:16:38 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Mule2]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[Tomcat Mule2 ActiveMQ]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2390</guid>
		<description><![CDATA[This post describes how we managed to use standalone ActiveMQ (v5.2.0) as JNDI datasource in our Mule ESB application deployed in Apache Tomcat(v6.0). If you are still with me after reading this first line then I may assume you know &#8230; <a href="http://www.redstream.nl/2011/01/17/combining-activemq-tomcat-and-mule-esb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F01%2F17%2Fcombining-activemq-tomcat-and-mule-esb%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F01%2F17%2Fcombining-activemq-tomcat-and-mule-esb%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>This post describes how we managed to use standalone <a href="http://activemq.apache.org/">ActiveMQ</a> (v5.2.0) as JNDI datasource in our <a href="http://www.mulesoft.com/mule-esb-open-source-esb">Mule ESB</a> application deployed in <a href="http://tomcat.apache.org/">Apache Tomcat</a>(v6.0). If you are still with me after reading this first line then I may assume you know your way in this part of the Java open-source world :-)<br />
Here is the situation:<br />
We have deployed a number (about 10) of Mule applications as WAR&#8217;s in our Tomcat installation. Each WAR is using the same standalone ActiveMQ instance as JMS provider. We implemented this by defining an ActiveMQ connector in each WAR (actually in a separate JAR that is included in each WAR).<span id="more-2390"></span></p>
<p>However, recently we defined our database datasource as a JNDI resource in Tomcat. The big advantage is that it is only configured in just one place and maintained by the container instead of each WAR creating its own pool of connections.<br />
So we decided we could do the same for the ActiveMQ datasource (actually I was triggered by <a href="http://www.tomcatexpert.com/blog/2010/12/16/integrating-activemq-tomcat-using-local-jndi">this article</a>).</p>
<p>So here are the steps we took to make this work:</p>
<ol>
<li>Define a global resource in server.xml of the Tomcat instance:</li>

<div class="wp_codebox"><table><tr id="p239035"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p2390code35"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Resource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jms/ConnectionFactory&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">auth</span>=<span style="color: #ff0000;">&quot;Container&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;JMS Connection Factory&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">factory</span>=<span style="color: #ff0000;">&quot;org.apache.activemq.jndi.JNDIReferenceFactory&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">brokerURL</span>=<span style="color: #ff0000;">&quot;tcp://localhost:61616&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">brokerName</span>=<span style="color: #ff0000;">&quot;myActiveMQBroker&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">userName</span>=<span style="color: #ff0000;">&quot;user&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;password&quot;</span>                            </span>
<span style="color: #009900;">          <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<li>Define a global resourceLink in the context.xml of the Tomcat instance:</li>

<div class="wp_codebox"><table><tr id="p239036"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2390code36"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ResourceLink</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jms/myJMS&quot;</span> <span style="color: #000066;">global</span>=<span style="color: #ff0000;">&quot;jms/ConnectionFactory&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<li>Add to necessary libs to your /TOMCAT_HOME/lib directory:</li>
<p>For your Tomcat instance to be able to work with the standalone ActiveMQ it must have loaded the necessary classes on its classpath. To make this possible you should copy the jar  <a href="http://www.java2s.com/Code/JarDownload/activemq-all-5.2.0.jar.zip">activemq-all-5.2.0.jar</a> into your $TOMCAT_HOME$/lib directory.
</ol>
<p>These are the steps to setup Tomcat. Now you have to tell your Mule application it has to access this datasource instead creating its own pool. For this add the following to your Mule config:</p>
<ul>
<li>Define your (Spring) datasource:</li>

<div class="wp_codebox"><table><tr id="p239037"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p2390code37"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;activeMqConnectionFactory&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.jndi.JndiObjectFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jndiName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;java:comp/env/jms/shipJMS&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<li>Define the activeMQ connection like this:</li>

<div class="wp_codebox"><table><tr id="p239038"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p2390code38"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jms:activemq-connector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;JMSConnector&quot;</span> <span style="color: #000066;">specification</span>=<span style="color: #ff0000;">&quot;1.1&quot;</span> <span style="color: #000066;">dynamicNotification</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">connectionFactory-ref</span>=<span style="color: #ff0000;">&quot;activeMqConnectionFactory&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">acknowledgementMode</span>=<span style="color: #ff0000;">&quot;AUTO_ACKNOWLEDGE&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">maxRedelivery</span>=<span style="color: #ff0000;">&quot;3&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">disableTemporaryReplyToDestinations</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">persistentDelivery</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;custom-exception-strategy</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;nl.redstream.exceptionhandlers.DefaultConnectorExceptionHandler&quot;</span> <span style="color: #000066;">enableNotifications</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:outbound-endpoint</span> <span style="color: #000066;">connector-ref</span>=<span style="color: #ff0000;">&quot;vmConnector&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;error-handler&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/custom-exception-strategy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ee:retry-forever-policy</span> <span style="color: #000066;">frequency</span>=<span style="color: #ff0000;">&quot;30000&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jms:activemq-connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>In the next post I show how to config your unit tests to work with this configuration</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/01/17/combining-activemq-tomcat-and-mule-esb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

