<?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>Technotrance, Illusions and Perspectives &#187; unitils</title>
	<atom:link href="http://myblog.shriharisc.com/tag/unitils/feed/" rel="self" type="application/rss+xml" />
	<link>http://myblog.shriharisc.com</link>
	<description>A dose of everyday bruises with Java/JEE</description>
	<lastBuildDate>Mon, 02 Aug 2010 17:45:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Establishing a webservice unit test infrastructure using Unitils on Apache CXF and Hibernate</title>
		<link>http://myblog.shriharisc.com/2009/07/16/establishing-a-webservice-unit-test-infrastructure-using-unitils-on-apache-cxf/</link>
		<comments>http://myblog.shriharisc.com/2009/07/16/establishing-a-webservice-unit-test-infrastructure-using-unitils-on-apache-cxf/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 12:38:23 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[jee-light]]></category>
		<category><![CDATA[apache-cxf]]></category>
		<category><![CDATA[unitils]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=72</guid>
		<description><![CDATA[Unitils is most preferred Spring based unit testing framework for unit testing DAOs and persistence layers. However using the power of inherent Spring support it has, added with flexible flavors on JUnit or TestNG, it could be extended to implement Web-services testing infrastructure such as Apache CXF which has persistence layer access through DAO layer, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://unitils.org/summary.html">Unitils</a> is most preferred Spring based unit testing framework for unit testing DAOs and persistence layers. However using the power of inherent Spring support it has, added with flexible flavors on JUnit or TestNG, it could be extended to implement Web-services testing infrastructure such as <a href="http://cxf.apache.org/">Apache CXF</a> which has persistence layer access through DAO layer, that gets rid of loads of boilerplate code we got to ensure, before a proxy gets initialized.</p>
<p>This quick tip addresses how to put in place a unit testing infrastructure, so that unit testing Apache CXF web-services becomes a easy task. We assume we would use TestNG flavor of Unitils for our understanding, using JUnit is equivalently similar, and Maven based POM.</p>
<p>1) Include the Unitils dependency with TestNG in ${basedir}/pom.xml as given below.</p>
<pre class="brush: xml">
&lt;dependency&gt;
 &lt;groupId&gt;org.unitils&lt;/groupId&gt;
 &lt;artifactId&gt;unitils&lt;/artifactId&gt;
 &lt;version&gt;2.3&lt;/version&gt;
 &lt;/dependency&gt;

 &lt;dependency&gt;
 &lt;groupId&gt;org.testng&lt;/groupId&gt;
 &lt;artifactId&gt;testng&lt;/artifactId&gt;
 &lt;version&gt;5.8&lt;/version&gt;
 &lt;classifier&gt;jdk15&lt;/classifier&gt;
 &lt;scope&gt;test&lt;/scope&gt;
 &lt;/dependency&gt;
</pre>
<p>2) Add a Spring configuration file under ${basedir}/src/test/resources, say as client-test-config.xml and add the JAXWSProxyFactoryBean wiring so as to obtain a proxy object of the service exposed on a specific WSDL url.</p>
<pre class="brush: xml">
&lt;beans&gt;
   &lt;bean id=&quot;propConfig&quot; class=&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;&gt;
     &lt;property name=&quot;systemPropertiesMode&quot; value=&quot;2&quot;/&gt;
     &lt;property name=&quot;location&quot; value=&quot;classpath:mytest.properties&quot;/&gt;
   &lt;/bean&gt;

   &lt;bean id=&quot;wsclient&quot;  class=&quot;mypackage.MyServiceInterface&quot; factory-bean=&quot;wsFactory&quot; factory-method=&quot;create&quot;/&gt;

   &lt;bean id=&quot;wsFactory&quot; class=&quot;org.apache.cxf.jaxws.JaxWsProxyFactoryBean&quot;&gt;
      &lt;property name=&quot;serviceClass&quot; value=&quot;mypackage.MyServiceInterface&quot;/&gt;
      &lt;property name=&quot;address&quot; value=&quot;${myservice.wsdl.url}&quot;/&gt;
   &lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p>3) Define a unit test-case using the Spring configuration file, to inject the proxy service bean, and invoke/unit test methods on the exposed service.</p>
<pre class="brush: java">
public class MyServiceTest extends UnitilsTestNG
{   @SpringApplicationContext
    public ConfigurableApplicationContext createApplicationContext()
    {  return new ClassPathXmlApplicationContext(&quot;client-test-config.xml&quot;);
    }

    @SpringBean(&quot;wsclient&quot;)
     private MyServiceInterface myService;&lt;/span&gt;
      //All your unit test methods annotated with @Test here&lt;/span&gt;
}
</pre>
<p>Thats it!. Your webservice unit test infrastructure for Apache CXF on Unitils is ready for adding test cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/07/16/establishing-a-webservice-unit-test-infrastructure-using-unitils-on-apache-cxf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing a Unitils DAO testing infrastructure for Spring and JPA on TestNG</title>
		<link>http://myblog.shriharisc.com/2009/06/29/implementing-a-unitils-dao-testing-infrastructure-for-spring-and-jpa-on-testng/</link>
		<comments>http://myblog.shriharisc.com/2009/06/29/implementing-a-unitils-dao-testing-infrastructure-for-spring-and-jpa-on-testng/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 17:50:51 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[unitils]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=47</guid>
		<description><![CDATA[Unitils provides an excellant infrastructure for unit testing DAO (and data-service) layers  for Spring as IoC Framework on all the component unit testing frameworks such as JUnit 3, JUnit4 and TestNG, without any boilerplate code or coniguration hassles. We will look at establishing a testing infrastructure for Spring with JPA on TestNG frmaework.
Suppose the custom [...]]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://unitils.org">Unitils</a></strong> provides an excellant infrastructure for unit testing DAO (and data-service) layers  for Spring as IoC Framework on all the component unit testing frameworks such as JUnit 3, JUnit4 and TestNG, without any boilerplate code or coniguration hassles. We will look at establishing a testing infrastructure for Spring with JPA on TestNG frmaework.</p>
<p>Suppose the custom DAO and its implementation definition are like this (with regard to semantics of Spring JPA integration)</p>
<pre><span style="color:#0000ff;"><code>package mypackage;
public CustomDAO
{    public List findAll();
     public void save(Entity eo);
}</code></span></pre>
<pre><span style="color:#0000ff;">package mypackage;
public CustomDAOImpl implements CustommmDAO
{   @PersistenceContext
    private EntityManager em;</span></pre>
<pre><span style="color:#0000ff;">    //all other method implementations..
      ....
}</span></pre>
<p>In order to setup a Unitils test infrastructure on TestNG, the following is the class-template:</p>
<pre><span style="color:#0000ff;"><code>public class CustomDAOTestCase extends UnitilsTestNG
{   /**
     * Injects a test specific application context configuration
     */
    @SpringApplicationContext
    public ConfigurableApplicationContext createApplicationContext()
    {  return new ClassPathXmlApplicationContext("applicationContext-test.xml");
    }</code></span></pre>
<pre><span style="color:#0000ff;">     @SpringBean("customDAO")
     private CustomDAO customDAO;</span></pre>
<pre><span style="color:#0000ff;">     //all @Test annotated methods..</span></pre>
<pre><span style="color:#0000ff;">      @Override
      protected void unitilsAfterTestTearDown(java.lang.reflect.Method method)
      {}
}</span></pre>
<p>for which the following would be the test specific Spring&#8217;s application context confguration (applicationContext-test.xml)</p>
<pre><span style="color:#0000ff;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;

 &lt;bean id="entityManagerFactory" &gt;
 &lt;property name="persistenceXmlLocation" value="persistence-test.xml"/&gt;
 &lt;property name="persistenceUnitName" value="customservice-test"/&gt;
 &lt;/bean&gt;

 &lt;bean id="transactionManager"&gt;
 &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
 &lt;/bean&gt;

 &lt;tx:annotation-driven /&gt;

 &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;

 &lt;bean id="customDAO" class="mypackage.CustomDAOImpl"/&gt;
&lt;/beans&gt;</span></pre>
<p>Look specifically at entityManagerFactory bean definition, org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean allows us to load test specific persistence.xml which could allow us to maintain more than onne persistence context for a sample application.<br />
These two definitions extend the Spring&#8217;s JPA capabilities for unit testing DAO on Unitils infrastructure!</p>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/06/29/implementing-a-unitils-dao-testing-infrastructure-for-spring-and-jpa-on-testng/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
