<?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; spring-test</title>
	<atom:link href="http://myblog.shriharisc.com/tag/spring-test/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>Unit testing CXF webservice endpoints using Spring-Test and TestNG</title>
		<link>http://myblog.shriharisc.com/2009/10/09/unit-testing-cxf-webservice-endpoints-using-spring-test-and-testng/</link>
		<comments>http://myblog.shriharisc.com/2009/10/09/unit-testing-cxf-webservice-endpoints-using-spring-test-and-testng/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 16:05:44 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[jee-light]]></category>
		<category><![CDATA[apache-cxf]]></category>
		<category><![CDATA[spring-test]]></category>
		<category><![CDATA[testng]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=127</guid>
		<description><![CDATA[The Spring IOC feature of configurational wiring of POJOs to control and achieve network of business logic frees developers of writing any boilerplate code and eventually of bugs. I would like to explain one such facility with regard to establishing an unit testing infrastructure for writing unit test cases for JAXWS specific web service endpoints [...]]]></description>
			<content:encoded><![CDATA[<p>The Spring IOC feature of configurational wiring of POJOs to control and achieve network of business logic frees developers of writing any boilerplate code and eventually of bugs. I would like to explain one such facility with regard to establishing an unit testing infrastructure for writing unit test cases for JAXWS specific web service endpoints (CXF) using Spring-test module and TestNG unit testing framework.</p>
<p>Lets take a simple example of a web service endpoint exposing a functionality to query a book price, given the ISBN number, given a maven project. This write-up just concentrates on establishing a web service unit testing framework. Following are sequence of steps one could follow to achieve the required infrastructure setup.</p>
<p>1) Change ${basedir}/pom.xml include adding spring-test dependency, and TestNG dependency, with maven-surefire-plugin configuration (assuming CXF dependencies are already present)</p>
<pre class="brush: xml">
&lt;dependency&gt;
 &lt;groupId&gt;org.springframework&lt;/groupId&gt;
 &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
 &lt;version&gt;2.5.6&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.9&lt;/version&gt;
 &lt;classfier&gt;jdk15&lt;/classifier&gt;
 &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
</pre>
<p>2) Add a Spring configuration file (service-test.xml) under ${basedir}/src/test/resources. The CXF&#8217;s JaxWSProxyFactoryBean can be wired to to create a service proxy. Below is the snippet of the configuration file.</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xmlns:cxf=&quot;http://cxf.apache.org/core&quot;
xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                    http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd&quot;&gt;&lt;/span&gt;&lt;/pre&gt;
    &lt;import resource=&quot;classpath:META-INF/cxf/cxf.xml&quot; /&gt;
     &lt;import resource=&quot;classpath:META-INF/cxf/cxf-extension-soap.xml&quot; /&gt;
     &lt;import resource=&quot;classpath:META-INF/cxf/cxf-extension-http.xml&quot; /&gt;

     &lt;!-- Required to load the service endpoint uris --&gt;
     &lt;bean id=&quot;propConfig&quot; class=&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;&gt;
         &lt;property name=&quot;locations&quot;&gt;
            &lt;list&gt;
               &lt;value&gt;classpath:service-test.properties&lt;/value&gt;
             &lt;/list&gt;
         &lt;/property&gt;
     &lt;/bean&gt;

     &lt;bean id=&quot;proxyFactory&quot; class=&quot;org.apache.cxf.jaxws.JaxWsProxyFactoryBean&quot;&gt;
         &lt;property name=&quot;serviceClass&quot; value=&quot;com.schtech.service.endpoint.store.BookPriceService&quot;/&gt;
         &lt;property name=&quot;address&quot; value=&quot;${bookstore.service.endpoint.url}&quot;/&gt;
         &lt;property name=&quot;bus&quot; ref=&quot;cxf&quot; /&gt;
    &lt;/bean&gt;

     &lt;bean id=&quot;serviceClient&quot; class=&quot;com.schtech.service.endpoint.store.BookPriceService&quot; factory-bean=&quot;proxyFactory&quot;
        factory-method=&quot;create&quot;/&gt;
&lt;/beans&gt;
</pre>
<p>3) Implement the TestNG test case to test web service. Here three things have to be noted: (1) ContextConfiguration annotation helps us load<br />
the configuration file. (2) The test case extends AbstractTestNGSpringContextTests to load the context configuration and autowire the service<br />
bean. (3) Autowire annotation on the service endpoint interface initializes with proxy factory created service proxy instance.</p>
<pre class="brush: java">
@ContextConfiguration(locations = {&quot;classpath:service-context.xml&quot;})
public class BookCatalogTest extends AbstractTestNGSpringContextTests
 { @Autowired
   private BookPriceService serviceClient;

   @Test
   public void testBookPrice()
   { String isbn = &quot;978-3-16-148410-0,&quot;;
     Double price  = serviceClient.findBookPrice(isbn);
     assertNotNull(price);
   }
}
</pre>
<p>The infrastructure is ready to be used to test other service endpoints hosted elsewhere. Running mvn test at the ${basedir} prompt would unit test the service endpoints.</p>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/10/09/unit-testing-cxf-webservice-endpoints-using-spring-test-and-testng/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
