<?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>Java crumbs &#187; test</title>
	<atom:link href="http://blog.krecan.net/tag/test/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.krecan.net</link>
	<description>Short remarks from Java world</description>
	<lastBuildDate>Tue, 27 Jul 2010 13:56:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring WS Test</title>
		<link>http://blog.krecan.net/2009/09/02/spring-ws-test/</link>
		<comments>http://blog.krecan.net/2009/09/02/spring-ws-test/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 19:15:51 +0000</pubDate>
		<dc:creator>Lukáš Křečan</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tests]]></category>
		<category><![CDATA[spring-ws]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://blog.krecan.net/?p=422</guid>
		<description><![CDATA[Last few weeks I have been working on one of my pet projects. Its name is Spring WS Test. As the name implies, its main purpose is to simplify Spring WS tests. 
Again, I am scratching my own itch. I am quite test infected and I have needed something that allows me to write functional [...]]]></description>
			<content:encoded><![CDATA[<p>Last few weeks I have been working on one of my pet projects. Its name is <a href="http://javacrumbs.net/spring-ws-test/">Spring WS Test</a>. As the name implies, its main purpose is to simplify Spring WS tests. </p>
<p>Again, I am scratching my own itch. I am quite test infected and I have needed something that allows me to write functional tests of my application without having to depend on an external server.  Until now, you basically had two options. This first one is to test WS client application using plain old JUnit together with a library like EasyMock. But usually this test are quite ugly and hard to read. Moreover this type of tests does not test your configuration. The second option is to create a functional test that calls an external mock service. But this solution requires you to have two JVM, its configuration is complicated and error prone.</p>
<p><img src="/files/spring-ws-test/seq1.png" alt="Classical WS test" /></p>
<p>I have been looking for something in between, for something that would allow me to write functional tests using JUnit and would be able to run in the same JVM as the test. Unfortunately I have not been able to find anything similar.</p>
<p><img src="/files/spring-ws-test/seq2.png" alt="Spring WS Test test" /></p>
<p>That's the reason why I have created Spring WS Test project. It's quite simple and easy even though I had to spent lot of my evenings getting it into a publishable state.</p>
<p>Basic configuration looks like this</p>
<pre name="code" class="xml">
&lt;beans ...&gt;
  &lt;!-- Creates mock message sender --&gt;
  &lt;bean id=&quot;messageSender&quot; class=&quot;net.javacrumbs.springws.test.MockWebServiceMessageSender&quot;/&gt;

  &lt;!-- Injects mock message sender into WebServiceTemplate --&gt;
  &lt;bean class=&quot;net.javacrumbs.springws.test.util.MockMessageSenderInjector&quot;/&gt;

  &lt;!-- Looks for responses on the disc based on the provided XPath --&gt;
  &lt;bean class=&quot;net.javacrumbs.springws.test.generator.DefaultResponseGeneratorFactoryBean&quot;&gt;
     &lt;property name=&quot;namespaceMap&quot;&gt;
         &lt;map&gt;
            &lt;entry key=&quot;soapenv&quot;
                value=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;/&gt;
            &lt;entry key=&quot;ns&quot;
                value=&quot;http://www.springframework.org/spring-ws/samples/airline/schemas/messages&quot;/&gt;
         &lt;/map&gt;
     &lt;/property&gt;
     &lt;property name=&quot;XPathExpressions&quot;&gt;
         &lt;list&gt;
             &lt;value&gt;
                 concat(local-name(//soapenv:Body/*[1]),'/default-response.xml')
             &lt;/value&gt;
         &lt;/list&gt;
     &lt;/property&gt;
 &lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p>Here we have MockWebServiceMessageSender that replaces standard Spring <a href="http://static.springsource.org/spring-ws/sites/1.5/apidocs/org/springframework/ws/transport/WebServiceMessageSender.html">WebServiceMessageSender</a>. The replacement is done by MockMessageSenderInjector. The only other thing you have to do is to define ResponseGenerator. It's main purpose is to look for files in you test classpath and return them as mock responses. </p>
<p>Of course it has to decide, which file to use. By default a XPath expression is used to determine the resource name. In our example it is <code>concat(local-name(//soapenv:Body/*[1]),'/default-response.xml')</code>. It takes name of the payload (first soap:Body child) and uses it as a directory name. File “default-response.xml” from this directory is used as the mock response. Simple isn't it? </p>
<p>Of course you can define more complicated XPaths, you can use XSLT templates to generate your responses, you can validate your requests etc. More details can be found in the <a href="http://javacrumbs.net/spring-ws-test/">documentation</a>.  </p>
<p>Now I am looking for some end-user feedback. So please, if you are using Spring WS on the client side do not hesitate and test it. It should be stable enough to be used although there might be a bug here and there.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.krecan.net/2009/09/02/spring-ws-test/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Testing with Spring 2.5</title>
		<link>http://blog.krecan.net/2007/12/12/testing-with-spring-25/</link>
		<comments>http://blog.krecan.net/2007/12/12/testing-with-spring-25/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 18:45:16 +0000</pubDate>
		<dc:creator>Lukáš Křečan</dc:creator>
				<category><![CDATA[Articles in English]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tests]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[transaction]]></category>

		<guid isPermaLink="false">http://blog.krecan.net/2007/12/12/testing-with-spring-25/</guid>
		<description><![CDATA[Besides other cool features, Spring 2.5 brought completely rewritten support for functional tests.  Before this version, Spring had support for functional tests using JUnit 3 only. If you needed to use  JUnit 4 or TestNG you just did not get any help from the framework 
Now you can use brand new annotations and [...]]]></description>
			<content:encoded><![CDATA[<p>Besides other cool features, Spring 2.5 brought completely rewritten support for functional tests.  Before this version, Spring had support for functional tests using JUnit 3 only. If you needed to use  JUnit 4 or TestNG you just did not get any help from the framework </p>
<p>Now you can use brand new annotations and you are not constrained in your choice of testing framework any more. For complete information, please consult <a href="http://static.springframework.org/spring/docs/2.5.x/reference/testing.html#integration-testing">Spring reference</a>, I will show only small subset of the new features. Let's take a look on the first example.</p>
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
  <!-- start source code --></p>
<td nowrap="nowrap" valign="top" align="left">
    <code><br />
<font color="#808080">01</font>&nbsp;<font color="#646464">@RunWith</font><font color="#000000">(</font><font color="#000000">SpringJUnit4ClassRunner.</font><font color="#7f0055"><b>class</b></font><font color="#000000">)</font><br />
<font color="#808080">02</font>&nbsp;<font color="#646464">@ContextConfiguration</font><font color="#000000">(</font><font color="#000000">locations=</font><font color="#2a00ff">&#34;classpath:applicationContext.xml&#34;</font><font color="#000000">)</font><br />
<font color="#808080">03</font>&nbsp;<font color="#646464">@Transactional</font><br />
<font color="#808080">04</font>&nbsp;<font color="#7f0055"><b>public&nbsp;class&nbsp;</b></font><font color="#000000">TestJpaClientDao&nbsp;</font><font color="#000000">{</font><br />
<font color="#808080">05</font>&nbsp;<font color="#ffffff"></font><br />
<font color="#808080">06</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><b>private&nbsp;static&nbsp;final&nbsp;</b></font><font color="#7f0055"><b>long&nbsp;</b></font><font color="#000000">PERSONAL_NUM&nbsp;=&nbsp;</font><font color="#990000">123L</font><font color="#000000">;</font><br />
<font color="#808080">07</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#646464">@Autowired</font><br />
<font color="#808080">08</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><b>private&nbsp;</b></font><font color="#000000">ClientDao&nbsp;clientDao;</font><br />
<font color="#808080">09</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><br />
<font color="#808080">10</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#646464">@Test</font><br />
<font color="#808080">11</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><b>public&nbsp;</b></font><font color="#7f0055"><b>void&nbsp;</b></font><font color="#000000">testCreateClient</font><font color="#000000">()</font><br />
<font color="#808080">12</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">{</font><br />
<font color="#808080">13</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">Client&nbsp;client&nbsp;=&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Client</font><font color="#000000">(</font><font color="#000000">PERSONAL_NUM</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">14</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">client.setName</font><font color="#000000">(</font><font color="#2a00ff">&#34;John&nbsp;Doe&#34;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">15</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">client.addAddress</font><font color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Address</font><font color="#000000">(</font><font color="#2a00ff">&#34;Old&nbsp;st.&#34;</font><font color="#000000">,</font><font color="#2a00ff">&#34;2a&#34;</font><font color="#000000">,</font><font color="#2a00ff">&#34;Prague&#34;</font><font color="#000000">,</font><font color="#2a00ff">&#34;120&nbsp;00&#34;</font><font color="#000000">))</font><font color="#000000">;</font><br />
<font color="#808080">16</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">client.addAccount</font><font color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Account</font><font color="#000000">(</font><font color="#2a00ff">&#34;123-4560789&#34;</font><font color="#000000">))</font><font color="#000000">;</font><br />
<font color="#808080">17</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">client.addAccount</font><font color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Account</font><font color="#000000">(</font><font color="#2a00ff">&#34;888-8888888&#34;</font><font color="#000000">))</font><font color="#000000">;</font><br />
<font color="#808080">18</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">clientDao.createClient</font><font color="#000000">(</font><font color="#000000">client</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">19</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><br />
<font color="#808080">20</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">Client&nbsp;loadedClient&nbsp;=&nbsp;clientDao.loadClientWithPersonalNumber</font><font color="#000000">(</font><font color="#000000">PERSONAL_NUM</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">21</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">assertSame</font><font color="#000000">(</font><font color="#000000">client,&nbsp;loadedClient</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">22</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font></code></p>
</td>
<p>  <!-- end source code --><br />
   </tr>
</table>
</div>
<p>Here we see normal class with some annotations. But it is not normal class, it is JUnit 4 test. By <code>RunWith </code>annotation we are extending usual JUnit test runner in order to enable Spring support. Then we have to define where application context XML file(s) are (<code>@ContextConfiguration</code> annotation).  Now we can use <code>Autowire </code>annotations to have all necessary dependencies injected. If we use annotation <code>Transactional </code>we obtain similar behavior as when we were using old <code>AbstractTransactionalSpringContextTests</code>. It means:</p>
<ol>
<li>
The application context is shared for all test methods (in all test classes). So all the stuff is initialized only once. If your test does some changes to the application context and it has to be therefore discarded, you can use <code>DirtiesContext</code> annotation.</li>
<li>
All test methods are run in transaction which is rolled back at the end of every test method. You can change this behavior by <code>Rollback</code> annotation or by <code>TransactionConfiguration</code> annotation.</li>
</ol>
<p>The new Spring test support is great. I just miss one thing. Old test support classes gave me possibility to finish and start a transaction in the middle of the test method (by calling <code>setComplete</code>, <code>finishTransaction</code> and <code>startNewTransaction</code>). I agree, that you do not need such feature very often, but sometimes it is handy. I was not able to find something similar in the new support classes. Finally I found a solution but it is not so straightforward as the old one (If you know better one please inform me). </p>
<p>In the following example I am trying to test whether my DAO is fetching addresses of the client so I do not get LazyInit exception. In my test I need to store a client to the database, finish the transaction, then load the client from the DB in a new transaction and finally check if the addresses are accessible even when no transaction is active. </p>
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
  <!-- start source code --></p>
<td nowrap="nowrap" valign="top" align="left">
    <code><br />
<font color="#808080">01</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#646464">@Test</font><br />
<font color="#808080">02</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#646464">@NotTransactional</font><br />
<font color="#808080">03</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><b>public&nbsp;</b></font><font color="#7f0055"><b>void&nbsp;</b></font><font color="#000000">testCreateAndLoadInTwoTransactions</font><font color="#000000">()</font><br />
<font color="#808080">04</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">{</font><br />
<font color="#808080">05</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>final&nbsp;</b></font><font color="#000000">Client&nbsp;client&nbsp;=&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Client</font><font color="#000000">(</font><font color="#000000">PERSONAL_NUM</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">06</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">client.setName</font><font color="#000000">(</font><font color="#2a00ff">&#34;John&nbsp;Doe&#34;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">07</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">client.addAddress</font><font color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Address</font><font color="#000000">(</font><font color="#2a00ff">&#34;Old&nbsp;st.&#34;</font><font color="#000000">,</font><font color="#2a00ff">&#34;2a&#34;</font><font color="#000000">,</font><font color="#2a00ff">&#34;Prague&#34;</font><font color="#000000">,</font><font color="#2a00ff">&#34;120&nbsp;00&#34;</font><font color="#000000">))</font><font color="#000000">;</font><br />
<font color="#808080">08</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">client.addAccount</font><font color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Account</font><font color="#000000">(</font><font color="#2a00ff">&#34;123-4560789&#34;</font><font color="#000000">))</font><font color="#000000">;</font><br />
<font color="#808080">09</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">client.addAccount</font><font color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Account</font><font color="#000000">(</font><font color="#2a00ff">&#34;888-8888888&#34;</font><font color="#000000">))</font><font color="#000000">;</font><br />
<font color="#808080">10</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">getTransactionTemplate</font><font color="#000000">()</font><font color="#000000">.execute</font><font color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">TransactionCallback</font><font color="#000000">(){</font><br />
<font color="#808080">11</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>public&nbsp;</b></font><font color="#000000">Object&nbsp;doInTransaction</font><font color="#000000">(</font><font color="#000000">TransactionStatus&nbsp;status</font><font color="#000000">)&nbsp;{</font><br />
<font color="#808080">12</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>return&nbsp;</b></font><font color="#000000">clientDao.createClient</font><font color="#000000">(</font><font color="#000000">client</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">13</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#808080">14</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><br />
<font color="#808080">15</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">})</font><font color="#000000">;</font><br />
<font color="#808080">16</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">Client&nbsp;loadedClient&nbsp;=&nbsp;</font><font color="#000000">(</font><font color="#000000">Client</font><font color="#000000">)&nbsp;</font><font color="#000000">getTransactionTemplate</font><font color="#000000">()</font><font color="#000000">.execute</font><font color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">TransactionCallback</font><font color="#000000">(){</font><br />
<font color="#808080">17</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>public&nbsp;</b></font><font color="#000000">Object&nbsp;doInTransaction</font><font color="#000000">(</font><font color="#000000">TransactionStatus&nbsp;status</font><font color="#000000">)&nbsp;{</font><br />
<font color="#808080">18</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>return&nbsp;</b></font><font color="#000000">clientDao.loadClientWithPersonalNumber</font><font color="#000000">(</font><font color="#000000">PERSONAL_NUM</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">19</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#808080">20</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">})</font><font color="#000000">;</font><br />
<font color="#808080">21</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">assertEquals</font><font color="#000000">(</font><font color="#990000">2</font><font color="#000000">,loadedClient.getAccounts</font><font color="#000000">()</font><font color="#000000">.size</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#808080">22</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><br />
<font color="#808080">23</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//cleanup</font><br />
<font color="#808080">24</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">getTransactionTemplate</font><font color="#000000">()</font><font color="#000000">.execute</font><font color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">TransactionCallback</font><font color="#000000">(){</font><br />
<font color="#808080">25</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>public&nbsp;</b></font><font color="#000000">Object&nbsp;doInTransaction</font><font color="#000000">(</font><font color="#000000">TransactionStatus&nbsp;status</font><font color="#000000">)&nbsp;{</font><br />
<font color="#808080">26</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">clientDao.deleteClient</font><font color="#000000">(</font><font color="#000000">client.getId</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#808080">27</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>return&nbsp;null</b></font><font color="#000000">;</font><br />
<font color="#808080">28</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#808080">29</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><br />
<font color="#808080">30</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">})</font><font color="#000000">;</font><br />
<font color="#808080">31</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><br />
<font color="#808080">32</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#808080">33</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><b>private&nbsp;</b></font><font color="#000000">TransactionTemplate&nbsp;getTransactionTemplate</font><font color="#000000">()&nbsp;{</font><br />
<font color="#808080">34</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>return&nbsp;new&nbsp;</b></font><font color="#000000">TransactionTemplate</font><font color="#000000">(</font><font color="#000000">transactionManager</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#808080">35</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font></code></p>
</td>
<p>  <!-- end source code --><br />
   </tr>
</table>
</div>
<p>As you can see, I have marked the method as <code>NonTransactional</code>. Therefore, Spring does not create a  transaction for me and I can manage my transaction programmatically. For example using Spring transaction template. And that's it.</p>
<p><em>The source code can be downloaded from SVN repository <a href="https://java-crumbs.svn.sourceforge.net/svnroot/java-crumbs/jpa-test/tags/jpa-test-1.0">here</a>.</em></p>
<p><em>Note: If you wonder why the hell I have started to write in something that looks almost like English when apparently I do even more mistakes than in Czech, the answer is simple. I just need to practice my English (apart from that I want to be world famous, not just known in Czech Republic)</em><code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.krecan.net/2007/12/12/testing-with-spring-25/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
