<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Antonio&#039;s Blog</title>
	<atom:link href="http://antoniogoncalves.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://antoniogoncalves.org</link>
	<description>A blog mainly about Java</description>
	<lastBuildDate>Fri, 17 May 2013 20:07:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='antoniogoncalves.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/5dd5107518dc70737e9e52b02a1d369a?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Antonio&#039;s Blog</title>
		<link>http://antoniogoncalves.org</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://antoniogoncalves.org/osd.xml" title="Antonio&#039;s Blog" />
	<atom:link rel='hub' href='http://antoniogoncalves.org/?pushpress=hub'/>
		<item>
		<title>Sony Your Business Is Going Down&#8230; Is It a Reason To Play With Women ?</title>
		<link>http://antoniogoncalves.org/2013/02/21/sony-your-business-is-going-down-is-it-a-reason-to-play-with-women/</link>
		<comments>http://antoniogoncalves.org/2013/02/21/sony-your-business-is-going-down-is-it-a-reason-to-play-with-women/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 14:53:22 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://antoniogoncalves.org/?p=1995</guid>
		<description><![CDATA[This post is not about Java, Java EE or even IT. It is about the state of our world or, to shrink it a bit, the state of advertisement, business&#8230; and women (I had blogged about something similar a few years ago) A few days ago a friend of mine who was skiing at La&#160;&#8230; <a href="http://antoniogoncalves.org/2013/02/21/sony-your-business-is-going-down-is-it-a-reason-to-play-with-women/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1995&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><em>This post is not about Java, Java EE or even IT. It is about the state of our world or, to shrink it a bit, the state of advertisement, business&#8230; and women (<a title="Are students getting brainwashed to become project managers ?" href="http://antoniogoncalves.org/2009/09/20/are-students-getting-brainwashed-to-become-project-managers/">I had blogged about something similar a few years ago</a>)</em></p>
<p>A few days ago a friend of mine who was skiing at <a href="http://www.la-plagne.com/en/winter/winter-holidays.html">La Plagne</a> (France) Tweeted this photo asking &#8220;<a href="https://twitter.com/nromanetti/status/303163299816677377">Am I the only one being shocked about this ?</a>&#8220;. I don&#8217;t know if he had many answers, but clearly, <strong>I was shocked. Shocked as a man, shocked as a dad of a 8 years old girl who will become a woman</strong>. In this photo <a href="http://www.businessweek.com/magazine/what-is-sony-now-11172011.html">Sony</a> makes the parallel between a woman and a <a href="http://en.wikipedia.org/wiki/PlayStation_Vita">play station</a> : <strong>two toys you can play with</strong>.</p>
<p><a href="http://agoncal.files.wordpress.com/2013/02/sonyad.jpg"><img class="aligncenter size-medium wp-image-1997" alt="Sony" src="http://agoncal.files.wordpress.com/2013/02/sonyad.jpg?w=225&#038;h=300" width="225" height="300" /></a></p>
<p>I&#8217;m sure all of us, in our different countries, have seen adverts of <a href="http://www.fordesignworks.com/Graphic-Design/Advertising-Design/Mercedes-Benz-cars--beautiful-women-advertising.html">half-naked</a> <a href="http://www.beautyconfessional.net/porn-advertising">women</a> <a href="http://kise-myblog.blogspot.fr/2007/04/pregnant-womenbeer-ads.html">drinking beer</a> or <a href="http://www.thesmokingjacket.com/entertainment/hot-advertising-commercials">half-naked</a> <a href="http://fashionista-shaynee.blogspot.fr/2010/06/vegetarian-advertisement.html">women</a> <a href="http://gawker.com/359705/does-tom-ford-hate-the-straights">driving</a> a car. This has been going on for decades&#8230; meaning&#8230; it works ! <strong>If you want to sell something ? Just use a naked woman</strong>. Yes, it works, you will sell more yogurts, beers, cars, perfumes .. and make more money. So can we all agree here please ? <strong>Put a naked woman on your advert and you will make more money ! Ok ? Good ! So now let&#8217;s move on !</strong></p>
<p><a href="http://agoncal.files.wordpress.com/2013/02/img_6512.jpg"><img class="aligncenter size-medium wp-image-2005" alt="Ski map" src="http://agoncal.files.wordpress.com/2013/02/img_6512.jpg?w=300&#038;h=225" width="300" height="225" /></a></p>
<p>In the industry I work in (IT), things move very fast, so a recipe that worked in 2000 doesn&#8217;t always work in 2013. That&#8217;s why we need to be fast, swift, agile, and need to innovate to create value (otherwise your business dies). <a href="http://formersonyemployee.blogspot.fr/">Sony</a> has the same problem.  Looks like in the advertising industry they don&#8217;t have this problem, don&#8217;t need to innovate and use the same old good recipe : <strong>naked woman == more business</strong> !</p>
<p><a href="http://www.androidauthority.com/kazuo-hirai-sony-75502/">Sony</a>, it looks like your <a href="http://finance.yahoo.com/q?s=SNE">business</a> is <a href="http://topics.nytimes.com/top/news/business/companies/sony_corporation/index.html">not going too well</a>. Maybe you should innovate, re-structure your company, have new ideas. I know, it&#8217;s difficult. Making business in 2013 is difficult because the competition is huge. But by using this kind of adverts, you look like your are at one inch of closing the company&#8230; and your last trick to come back to business is to <strong>use sexist adverts</strong>. Or maybe you really deserve your &#8220;<a href="http://www.bbc.co.uk/news/business-20449083">junk status</a>&#8220;.</p>
<p><a href="http://agoncal.files.wordpress.com/2013/02/sonystock.png"><img class="aligncenter size-medium wp-image-1998" alt="Sony Stock" src="http://agoncal.files.wordpress.com/2013/02/sonystock.png?w=300&#038;h=154" width="300" height="154" /></a></p>
<p><strong>Women, please, stop creating a world where you&#8217;ll get more and more uncomfortable living in. You don&#8217;t have to get naked for us to eat a yogurt or drive a car. Tell your female friends about it please !</strong></p>
<p><strong>Guys, can we just move on ?</strong></p>
<p>I would like to know the people who created this advert.<strong> If they could spend more time playing with their girlfriends (boyfriends) and wives (husbands) in their private lives, they would not create such crape.</strong> If you don&#8217;t have a partner to play with in your bed at home, bad luck, keep your sexual frustration for you, but do not expose it to everybody.</p>
<p>I&#8217;ll not go into &#8220;<em>BOYCOT SONY&#8217;S PRODUCTS</em>&#8221; because a bunch of idiots damaged the work of thousands of Sony&#8217;s employees. I just want these employees to go back to there managers and say &#8220;hey guys, the company is not in good shape, so instead of spending money in silly adverts, let&#8217;s go back to our original message : innovation&#8221;. <strong>So please Sony, make us dream like you used to</strong> (walkman, discman, floppy disks, compact disc, PlayStation, movie, music, entertainment, computers, flash memory cards, blu-ray disc, cameras, semiconductors&#8230;)&#8230; <strong>or go out of business if you can&#8217;t innovate anymore&#8230; but stop using sexist advertisement !</strong></p>
<h3>References</h3>
<ul>
<li><a href="http://kotaku.com/5960411/how-sony-is-turning-into-a-ghost-in-japan-and-around-the-world">How Sony Is Turning into a Ghost in Japan and Around the World</a></li>
<li><a href="http://www.businessweek.com/magazine/what-is-sony-now-11172011.html">What Is Sony Now?</a></li>
<li><a href="http://www.independent.co.uk/news/business/news/investors-heckle-sir-howard-stringer-at-sonys-annual-meeting-7893712.html">Investors heckle Sir Howard Stringer at Sony&#8217;s annual meeting</a></li>
<li><a href="http://www.cbc.ca/news/business/story/2012/04/10/sony-annual-loss.html">Sony caps worst year ever with $6.4B loss</a></li>
<li><a href="http://www.androidauthority.com/kazuo-hirai-sony-75502/">How Kazuo Hirai plans to save Sony from mediocrity</a></li>
<li><a href="http://www.bbc.co.uk/news/business-20449083">Viewpoint: How Sony slipped back</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1995/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1995/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1995&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2013/02/21/sony-your-business-is-going-down-is-it-a-reason-to-play-with-women/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2013/02/sonyad.jpg?w=225" medium="image">
			<media:title type="html">Sony</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2013/02/img_6512.jpg?w=300" medium="image">
			<media:title type="html">Ski map</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2013/02/sonystock.png?w=300" medium="image">
			<media:title type="html">Sony Stock</media:title>
		</media:content>
	</item>
		<item>
		<title>Test your JAX-RS 2.0 Web Service URIs&#8230; Without Mocks</title>
		<link>http://antoniogoncalves.org/2012/12/19/test-your-jax-rs-2-0-web-service-uris-without-mocks/</link>
		<comments>http://antoniogoncalves.org/2012/12/19/test-your-jax-rs-2-0-web-service-uris-without-mocks/#comments</comments>
		<pubDate>Wed, 19 Dec 2012 15:11:25 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[jax-rs]]></category>
		<category><![CDATA[nomock]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://antoniogoncalves.org/?p=1916</guid>
		<description><![CDATA[After the announcement of the NoMock Movement I had to write another post about integration testing. Here it goes  : how to test your nice RESTful URIs ? Use Case Often you hear that URIs have to be expressive… and you want to test that your URIs are nicely written. How do you do that&#160;&#8230; <a href="http://antoniogoncalves.org/2012/12/19/test-your-jax-rs-2-0-web-service-uris-without-mocks/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1916&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="https://github.com/agoncal/agoncal-sample-jaxrs/tree/master/01-Testing"><img class="size-full wp-image-652 alignright" title="Download the code" alt="" src="http://agoncal.files.wordpress.com/2010/05/download.gif?w=640"   /></a></p>
<p>After the announcement of the <a title="Launching The NoMock Movement" href="http://antoniogoncalves.org/2012/11/27/launching-the-nomock-movement/">NoMock Movement</a> I had to write another post about integration testing. Here it goes  : <strong>how to test your nice RESTful URIs</strong> ?</p>
<h2>Use Case</h2>
<p>Often you hear that URIs have to be expressive… and you want to test that your URIs are nicely written. How do you do that ? Unit testing with mock frameworks such as <a href="https://github.com/mkotsur/restito">Restito</a> or <a href="http://code.google.com/p/rest-assured/">Rest assured</a> ? If you do that you&#8217;ll be mocking the important part of what you really : a web server. Thanks to integration testing, you can just run your RESTful web service in an in memory web container and check that your URIs are correct (useful when you have many RESTful web services and get lost in your URIs)</p>
<h2>JAX-RS 2.0 Client API</h2>
<p>To integration-test URIs I will use the new <a href="http://jcp.org/en/jsr/detail?id=339">JAX-RS 2.0</a> <a href="http://jax-rs-spec.java.net/nonav/2.0-SNAPSHOT/apidocs/javax/ws/rs/client/package-summary.html">Client API</a> and the <a href="http://jersey.java.net/">Jersey</a> implementation. If you haven&#8217;t followed what&#8217;s been happening, here are some news about JAX-RS. At the time of writing this post JAX-RS 2.0 is nearly out and will be in Java EE 7 by Q2 2013. The client API wasn&#8217;t standardized in JAX-RS 1.1 and it&#8217;s one of the novelties in 2.0. It allows you to make HTTP requests to your remote RESTful web services easily. It is a fluent request building API (i.e. using the Builder design pattern) that uses a small number of classes and interfaces which are in the <a href="http://jax-rs-spec.java.net/nonav/2.0-SNAPSHOT/apidocs/javax/ws/rs/client/package-summary.html">javax.ws.rs.client</a> package. The <tt>Client</tt> interface (obtained with the <tt>ClientFactory</tt>) is a builder of <tt>WebTarget</tt> instances. A <tt>WebTarget</tt> represents a distinct URI from which you can invoke requests on to obtain a <tt>Response</tt>. From this <tt>Response</tt> you can check HTTP status, length or cookies but more importantly you can get its content (a.k.a entity, message body or payload) through the <tt>Entity</tt> class.</p>
<p>With that in mind, here are the lines of code to invoke a GET method on a remote RESTful web service located at <a href="http://www.myserver.com/book" rel="nofollow">http://www.myserver.com/book</a> and return a text/plain value:</p>
<pre class="brush: java; title: ; notranslate">
Client client = ClientFactory.newClient();
WebTarget target = client.target(&quot;http://www.myserver.com/book&quot;);
Invocation invocation = target.request(MediaType.TEXT_PLAIN).buildGet();
Response response = invocation.invoke();
</pre>
<p>Thanks to the builder API and some shortcuts, you can write the same behavior in a single line of code:</p>
<pre class="brush: java; title: ; notranslate">
Response response = ClientFactory.newClient().target(&quot;http://www.myserver.com/book&quot;).request(MediaType.TEXT_PLAIN).get();
</pre>
<h2>RESTful Web Service</h2>
<p>Let&#8217;s start with a simple RESTful web service with only GET methods. As you can see below, this service allows you to get a Customer by login (note the regular expression that only allows lowercase) and by ID (regular expression forces to have digits). Then there are two other methods that allow you to search customers by zip code (query param) or name and surname (matrix param).</p>
<pre class="brush: java; highlight: [6,7,14,15,22,30,31]; title: ; notranslate">
@Path(&quot;/customer&quot;)
@Produces(MediaType.APPLICATION_XML)
public class CustomerRestService {

    @GET
    @Path(&quot;{login: [a-z]*}&quot;)
    public Response getCustomerByLogin(@PathParam(&quot;login&quot;) String login) {
        Customer customer = new Customer(&quot;John&quot;, &quot;Smith&quot;, &quot;jsmith@gmail.com&quot;, &quot;1234565&quot;);
        customer.setLogin(login);
        return Response.ok(customer).build();
    }

    @GET
    @Path(&quot;{customerId : \\d+}&quot;)
    public Response getCustomerById(@PathParam(&quot;customerId&quot;) Long id) {
        Customer customer = new Customer(&quot;John&quot;, &quot;Smith&quot;, &quot;jsmith@gmail.com&quot;, &quot;1234565&quot;);
        customer.setId(id);
        return Response.ok(customer).build();
    }

    @GET
    public Response getCustomersByZipCode(@QueryParam(&quot;zip&quot;) Long zip) {
        Customers customers = new Customers();
        customers.add(new Customer(&quot;John&quot;, &quot;Smith&quot;, &quot;jsmith@gmail.com&quot;, &quot;1234565&quot;));
        customers.add(new Customer(&quot;John&quot;, &quot;Smith&quot;, &quot;jsmith@gmail.com&quot;, &quot;1234565&quot;));
        return Response.ok(customers).build();
    }

    @GET
    @Path(&quot;search&quot;)
    public Response getCustomerByName(@MatrixParam(&quot;firstname&quot;) String firstname, @MatrixParam(&quot;surname&quot;) String surname) {
        Customers customers = new Customers();
        customers.add(new Customer(&quot;John&quot;, &quot;Smith&quot;, &quot;jsmith@gmail.com&quot;, &quot;1234565&quot;));
        customers.add(new Customer(&quot;John&quot;, &quot;Smith&quot;, &quot;jsmith@gmail.com&quot;, &quot;1234565&quot;));
        return Response.ok(customers).build();
    }
}
</pre>
<p>How to invoke these methods ?</p>
<ul>
<li><a id="" href="http://localhost:8282/customer/agoncal" target="_blank">/customer/agoncal</a> invokes the <tt>getCustomerByLogin</tt> (GET method and the path parameter only allows lowercases)</li>
<li><a id="" href="http://localhost:8282/customer/1234" target="_blank">/customer/1234</a> invokes <tt>getCustomerById</tt> (GET method and a numerical path parameter)</li>
<li><a id="" href="http://localhost:8282/customer?zip=75012" target="_blank">/customer?zip=75012</a> invokes <tt>getCustomersByZipCode</tt> using <tt>QueryParam</tt></li>
<li><a id="" href="http://localhost:8282/customer/search;firstname=Antonio;surname=Goncalves" target="_blank">/customer/search;firstname=John;surname=Smith</a> invokes <tt>getCustomerByName</tt> using <tt>MatrixParam</tt></li>
</ul>
<p>And if you have a URI like <a id="" href="http://localhost:8282/customer/AGONCAL" target="_blank">/customer/AGONCAL</a> it would be invalid because of the uppercase (the regex only allows lower cases).</p>
<h2>Integration-Testing URIs</h2>
<p>So let&#8217;s test these URIs in an integration test using a real HTTP server.</p>
<pre class="brush: java; highlight: [11,20,21,22,23,26,27]; title: ; notranslate">
public class CustomerRestServiceIT {

    @Test
    public void shouldCheckURIs() throws IOException {

        URI uri = UriBuilder.fromUri(&quot;http://localhost/&quot;).port(8282).build();

        // Create an HTTP server listening at port 8282
        HttpServer server = HttpServer.create(new InetSocketAddress(uri.getPort()), 0);
        // Create a handler wrapping the JAX-RS application
        HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new ApplicationConfig(), HttpHandler.class);
        // Map JAX-RS handler to the server root
        server.createContext(uri.getPath(), handler);
        // Start the server
        server.start();

        Client client = ClientFactory.newClient();

        // Valid URIs
        assertEquals(200, client.target(&quot;http://localhost:8282/customer/agoncal&quot;).request().get().getStatus());
        assertEquals(200, client.target(&quot;http://localhost:8282/customer/1234&quot;).request().get().getStatus());
        assertEquals(200, client.target(&quot;http://localhost:8282/customer?zip=75012&quot;).request().get().getStatus());
        assertEquals(200, client.target(&quot;http://localhost:8282/customer/search;firstname=John;surname=Smith&quot;).request().get().getStatus());

        // Invalid URIs
        assertEquals(404, client.target(&quot;http://localhost:8282/customer/AGONCAL&quot;).request().get().getStatus());
        assertEquals(404, client.target(&quot;http://localhost:8282/customer/dummy/1234&quot;).request().get().getStatus());

        // Stop HTTP server
        server.stop(0);
    }
}
</pre>
<p>The idea is to launch an in-memory HTTP server. Jersey has several extensions so you can use Grizzly or GlassFish. But a very simple test would be to just use the <tt>com.sun.net.httpserver.HttpServer</tt> that comes with the Oracle JDK. As you can see in line 11, the only thing we need to do is to attach a <tt>com.sun.net.httpserver.HttpHandler</tt> with the JAX-RS application configuration (class <tt>ApplicationConfig</tt> not shown here, but you can <a href="https://github.com/agoncal/agoncal-sample-jaxrs/tree/master/01-Testing">download the code</a>). Then you just need to start the in memory web server (<tt>server.start();</tt>), check your valid (return code 200) and invalid (return code 404) URIs and stop the server. That&#8217;s it.</p>
<h2>I Gave a Quick Try at Unit-Test</h2>
<p>I did give a try at unit testing this use case using  <a href="https://github.com/mkotsur/restito">Restito</a>. I have to be honest here, I&#8217;ve quickly looked at the<a href="https://github.com/mkotsur/restito/blob/master/guide.md"> developer&#8217;s guide</a> and after struggling with Maven dependencies (REST Assured, Grizzly, Google Collections&#8230;) I managed to &#8220;unit test&#8221; my use case. I haven&#8217;t looked much into it but the logs from Restito looked a bit weired for a unit test :</p>
<pre class="brush: plain; title: ; notranslate">
org.glassfish.grizzly.http.server.NetworkListener start
org.glassfish.grizzly.http.server.HttpServer start
[HttpServer] Started
org.glassfish.grizzly.http.server.NetworkListener stop
</pre>
<p>So I don&#8217;t know if Restito is really starting Grizzly HTTP server of not, but if it is, it&#8217;s not really mocking much.</p>
<h2>Conclusion</h2>
<p><a href="https://github.com/agoncal/agoncal-sample-jaxrs/tree/master/01-Testing"><img class="size-full wp-image-652 alignright" title="Download the code" alt="" src="http://agoncal.files.wordpress.com/2010/05/download.gif?w=640"   /></a></p>
<p>This integration-test will run in a few milliseconds (on my Mac, 3 secondes on a normal Windows XP box) and you will really check your URIs not mocking anything&#8230; But of course, this is a very simple test. Most of the time you need database access, injection and so on. That&#8217;s when when you bring <a href="http://arquillian.org/">Arquillian</a> into play ;o) Maybe a topic to write about in a future post.</p>
<h2>References</h2>
<ul>
<li><a href="https://github.com/mkotsur/restito">Restito</a></li>
<li><a href="http://code.google.com/p/rest-assured/">Rest Assured</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1916/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1916&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2012/12/19/test-your-jax-rs-2-0-web-service-uris-without-mocks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2010/05/download.gif" medium="image">
			<media:title type="html">Download the code</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2010/05/download.gif" medium="image">
			<media:title type="html">Download the code</media:title>
		</media:content>
	</item>
		<item>
		<title>Let&#8217;s Turn Integration Tests with Maven to a First-Class Citizen</title>
		<link>http://antoniogoncalves.org/2012/12/13/lets-turn-integration-tests-with-maven-to-a-first-class-citizen/</link>
		<comments>http://antoniogoncalves.org/2012/12/13/lets-turn-integration-tests-with-maven-to-a-first-class-citizen/#comments</comments>
		<pubDate>Thu, 13 Dec 2012 14:15:11 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[nomock]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://antoniogoncalves.org/?p=1949</guid>
		<description><![CDATA[I would like to thank Arnaud Heritier who gave me plenty of tips and advices to write this blog. In fact if you want to endorse someone on Maven in LinkedIn, he is the man, not me ;o) If you use Maven in your projects you might wonder what &#8220;Let&#8217;s Turn Integration Tests with Maven into&#160;&#8230; <a href="http://antoniogoncalves.org/2012/12/13/lets-turn-integration-tests-with-maven-to-a-first-class-citizen/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1949&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><em>I would like to thank <a href="https://twitter.com/aheritier">Arnaud Heritier</a> who gave me plenty of tips and advices to write this blog. In fact if you want to endorse someone on Maven in LinkedIn, <a href="http://www.linkedin.com/in/aheritier">he is the man</a>, <a href="https://twitter.com/agoncal/status/278149148681834496">not me</a> ;o)</em></p>
<p>If you use <a href="http://maven.apache.org/">Maven</a> in your projects you might wonder what &#8220;<strong>Let&#8217;s Turn Integration Tests with Maven into a First-Class Citizen</strong>&#8221; means. A bit of introduction on that. Maven is based around the central concept of a <a href="http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference">build lifecycle</a> and if you look at the <a href="http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings">default lifecycle bindings</a>  you see the following phases :</p>
<ul>
<li>process-resources</li>
<li>compile</li>
<li>process-test-resources</li>
<li><strong>test-compile</strong></li>
<li><strong>test</strong></li>
<li>package</li>
<li>install</li>
<li>deploy</li>
</ul>
<p>As you can see, unit tests are central in Maven. Package your project with <tt>mvn package</tt> or deploy it with <tt>mvn deploy</tt> and this will kick the test phase. Why ? Because in the <a href="http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings">default lifecycle bindings</a> of Maven, the test phase is automatically called through the Surefire plugin. The <a href="http://maven.apache.org/surefire/maven-surefire-plugin/">maven-surefire-plugin</a> is designed for running unit tests and if any of the tests fail then it will fail the build immediately.</p>
<p>So where are the integration tests ? Not in the default lifecycle, that&#8217;s for sure. They are handled by a different plugin : Failsafe. The <a href="http://maven.apache.org/surefire/maven-failsafe-plugin/">maven-failsafe-plugin</a> is a fork of Surefire designed to run integration tests (after the package phase, on the integration-test phase). But on the contrary of Surefire, Failsafe is not activate by default, you need to explicitelly add it to you <tt>pom.xml</tt> and attach a phase to it :</p>
<pre class="brush: xml; highlight: [8,9]; title: ; notranslate">
&lt;plugin&gt;
  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
  &lt;version&gt;2.12.4&lt;/version&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;goals&gt;
        &lt;goal&gt;integration-test&lt;/goal&gt;
        &lt;goal&gt;verify&lt;/goal&gt;
      &lt;/goals&gt;
    &lt;/execution&gt;
  &lt;/executions&gt;
&lt;/plugin&gt;
</pre>
<p>The Maven lifecycle has four phases for running integration tests:</p>
<ul>
<li>pre-integration-test: on this phase you can start any required service or do any action (starting a database, a webserver&#8230;)</li>
<li><strong>integration-test</strong>: failsafe will run the test on this phase</li>
<li>post-integration-test: time to shutdown all services</li>
<li>verify: failsafe runs another goal that interprets the results of tests here</li>
</ul>
<p>The Failsafe Plugin has only 2 goals:</p>
<ul>
<li>failsafe:integration-test : runs the integration tests of an application.</li>
<li>failsafe:verify : verifies that the integration tests of an application passed.</li>
</ul>
<p>By default, the Surefire plugin executes <tt>**/Test*.java</tt>, <tt>**/*Test.java</tt>, and <tt>**/*TestCase.java</tt> test classes. The Failsafe plugin will look for <tt>**/IT*.java</tt>, <tt>**/*IT.java</tt>, and <tt>**/*ITCase.java</tt>. So if you are using unit test and integration tests, make sure to put them all in <tt>src/test/java</tt> and use this naming convention.</p>
<p>How does this work ? You <strong>run <tt>mvn test</tt> : unit test are executed</strong>. You run <strong><tt>mvn verify</tt> : unit test and then integration tests are executed</strong>. But if unit test fail, integration tests are not passed. Meaning that, <strong>for Maven, unit tests are more important than integration test</strong>.</p>
<h2>How to seperate unit and integration test ?</h2>
<p>What I really want is to be able to, either run UT or IT or none of them. Something like :</p>
<ul>
<li><tt>mvn install -DskipUTs</tt> : Skips Unit tests</li>
<li><tt>mvn install -DskipITs</tt> : Skips Integration tests</li>
<li><tt>mvn install -DskipTests</tt> : Skips both Unit and Integration Tests</li>
</ul>
<p>Here is a little trick you need to do in your pom.xml (again, thanks <a href="https://twitter.com/aheritier">Arnaud</a>)</p>
<pre class="brush: xml; highlight: [8,9]; title: ; notranslate">
&lt;project&gt;
  ...
  &lt;properties&gt;
    &lt;skipTests&gt;false&lt;/skipTests&gt;
    &lt;skipITs&gt;${skipTests}&lt;/skipITs&gt;
    &lt;skipUTs&gt;${skipTests}&lt;/skipUTs&gt;
  &lt;/properties&gt;

  &lt;build&gt;
    &lt;plugins&gt;

      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.12.4&lt;/version&gt;
        &lt;configuration&gt;
          &lt;skipTests&gt;${skipTests}&lt;/skipTests&gt;
          &lt;skipITs&gt;${skipITs}&lt;/skipITs&gt;
        &lt;/configuration&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;integration-test&lt;/goal&gt;
              &lt;goal&gt;verify&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.12.4&lt;/version&gt;
        &lt;configuration&gt;
          &lt;skipTests&gt;${skipUTs}&lt;/skipTests&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;

    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</pre>
<h2>Conclusion</h2>
<p>Unit testing is at the heart of Maven&#8230; but not integration testing. <strong>With this little trick you can put UT and IT at the same level : you can run either both tests, UT only, IT only or none.</strong> But it would be good to have this behaviour by default, without any configuration. That would mean adding the integration-test phase to the default lifecycle bindings of Maven.</p>
<p>What do you think ? <strong>Shall I start a discussion on the <a href="http://maven.apache.org/mail-lists.html">Maven Mailing List</a> ?</strong> Create a <a href="http://jira.codehaus.org/browse/MNG">JIRA issue</a> ? Shall we put integration tests at the same level of unit test ? Any other idea of how we could integrate both more closely ?</p>
<h2>Référence</h2>
<ul>
<li><a href="http://www.sonatype.com/people/2009/06/integration-tests-with-maven-part-1-failsafe-plugin/">Integration tests with Maven (Part 1)</a></li>
<li><a href="http://www.sonatype.com/people/2009/06/integration-tests-with-maven-part-2-test-coverage-reports/">Integration Tests with Maven (Part 2)</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1949/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1949/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1949&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2012/12/13/lets-turn-integration-tests-with-maven-to-a-first-class-citizen/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>
	</item>
		<item>
		<title>I&#8217;ve been awarded one of 100th people who will move IT forward in France for 2013</title>
		<link>http://antoniogoncalves.org/2012/12/06/ive-been-awarded-one-of-100th-people-who-will-move-it-forward-in-france-for-2013/</link>
		<comments>http://antoniogoncalves.org/2012/12/06/ive-been-awarded-one-of-100th-people-who-will-move-it-forward-in-france-for-2013/#comments</comments>
		<pubDate>Thu, 06 Dec 2012 16:00:17 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://antoniogoncalves.org/?p=1920</guid>
		<description><![CDATA[Sometimes life is about surprises. The other day I received an email from a friend saying &#8220;hey, congratulation, you&#8217;ve been awarded one of 100th people who will move IT forward in 2013&#8220;. Of course, I didn&#8217;t understand his email and didn&#8217;t reply. A few days later I received a more official email from the French&#160;&#8230; <a href="http://antoniogoncalves.org/2012/12/06/ive-been-awarded-one-of-100th-people-who-will-move-it-forward-in-france-for-2013/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1920&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://antoniogoncalves.org/2012/12/06/ive-been-awarded-one-of-100th-people-who-will-move-it-forward-in-france-for-2013/01cover/" rel="attachment wp-att-1921"><img class="alignright size-medium wp-image-1921" alt="01 Informatique" src="http://agoncal.files.wordpress.com/2012/12/01cover.jpg?w=216&#038;h=300" height="300" width="216" /></a>Sometimes life is about surprises. The other day I received an email from a friend saying &#8220;hey, congratulation, <strong>you&#8217;ve been awarded one of 100th people who will move IT forward in 2013</strong>&#8220;. Of course, I didn&#8217;t understand his email and didn&#8217;t reply. A few days later I received a more official email from the French IT magazine <a href="http://www.01net.com/">01 Informatique</a> who said the same thing. Attached to the email was a <a href="http://fr.scribd.com/doc/115440076/Les-100-du-Numerique">20 pages long PDF</a> with the same title. I opened it, browsed it, and found my name.</p>
<p>This weekly IT magazine has a palmares once a year where <strong>they elect people who they think will influence IT for the coming year</strong>. I still don&#8217;t really know how they elect people, which criteria they take into account or who votes. Anyway, I was a bit surprised when I saw my name in these 100 influential people where you find the french minister <a href="https://twitter.com/fleurpellerin">Fleur Pellerin</a>, <a href="https://twitter.com/Xavier75">Xavier Niel</a> (Free), <a href="https://twitter.com/rafigaro">Rafi Haladjian</a> (Sen.se), <a href="https://twitter.com/miguelvaldes">Miguel Valdes Faura</a> (Bonitasoft), <a href="https://twitter.com/olesovhnet">Octave Klaba</a> (OVH) and plenty of people from Bull, IBM, Dassault, Orange, Cloudwatt, Atos&#8230;</p>
<p>So here I am in the middle of all these names. And what do they have to say about me ? Here is a translation of <strong><a href="http://fr.scribd.com/doc/115440076/Les-100-du-Numerique">the magazine you can find here</a></strong> :</p>
<p><a href="http://antoniogoncalves.org/2012/12/06/ive-been-awarded-one-of-100th-people-who-will-move-it-forward-in-france-for-2013/01article/" rel="attachment wp-att-1922"><img class="alignleft size-medium wp-image-1922" alt="01article" src="http://agoncal.files.wordpress.com/2012/12/01article.jpg?w=273&#038;h=300" height="300" width="273" /></a><em>&#8220;Antonio Goncalves, Devoxx France.</em><br />
<em> This Java specialist is a <strong>star among developers</strong>. He has written two books on the subject and his blog <a href="http://www.antoniogoncalves.org">antoniogoncalves.org</a> has become a reference. Regularly, we see him at the Paris JUG, which he leads, or on the JBoss community website. Today <strong>this young man of 40 years</strong> is also the creator of Devoxx France, the conference for passionate developers held for the first time in Paris in April 2012&#8243;.</em></p>
<p>First, I would like to thank <a href="http://www.01net.com/">01 Informatique</a> who say I am a young man&#8230; even if I&#8217;m 40. It&#8217;s always good to know that you are young (in a job where companies don&#8217;t want senior developers). Second, I would like to thank them again for saying I&#8217;m a star. I&#8217;ve always consider <a href="http://en.wikipedia.org/wiki/John_Coltrane">John Coltrane</a>, <a href="http://en.wikipedia.org/wiki/Thelonious_Monk">Thelonious Monk</a>, <a href="http://en.wikipedia.org/wiki/Miles_Davis">Miles Davis</a> or <a href="http://fr.wikipedia.org/wiki/George_Gershwin">George Gershwin</a> to be stars. I wonder if my star has the same value of theirs ;o)  Oh, and by the way, what the hell this thing about JBoss community website in the article ?</p>
<p><strong>Anyway, I&#8217;m sure my mum will be happy to know that I will be one of the 100th most influencial IT people in France in 2013</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1920/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1920/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1920&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2012/12/06/ive-been-awarded-one-of-100th-people-who-will-move-it-forward-in-france-for-2013/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2012/12/01cover.jpg?w=216" medium="image">
			<media:title type="html">01 Informatique</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2012/12/01article.jpg?w=273" medium="image">
			<media:title type="html">01article</media:title>
		</media:content>
	</item>
		<item>
		<title>Launching The NoMock Movement</title>
		<link>http://antoniogoncalves.org/2012/11/27/launching-the-nomock-movement/</link>
		<comments>http://antoniogoncalves.org/2012/11/27/launching-the-nomock-movement/#comments</comments>
		<pubDate>Tue, 27 Nov 2012 14:56:14 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[arquillian]]></category>
		<category><![CDATA[nomock]]></category>

		<guid isPermaLink="false">http://antoniogoncalves.org/?p=1890</guid>
		<description><![CDATA[Everything started when Eve said &#8216;No&#8216; when God told her not to eat the fruit. Then my daughter said &#8216;No&#8216; when I told her to clean her room. Then we had a bunch of guys saying &#8216;No&#8216; to SQL. Then I read Is there such a thing as the NoMock movement?&#8230; And today I&#8217;m saying&#160;&#8230; <a href="http://antoniogoncalves.org/2012/11/27/launching-the-nomock-movement/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1890&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://agoncal.files.wordpress.com/2012/11/nomock1.png"><img class="alignright size-full wp-image-1914" style="margin-right:5px;" title="NoMock Movement" alt="NoMock Movement" src="http://agoncal.files.wordpress.com/2012/11/nomock1.png?w=640"   /></a>Everything started when Eve said &#8216;<em>No</em>&#8216; when God told her not to eat the fruit. Then my daughter said &#8216;<em>No</em>&#8216; when I told her to clean her room. Then we had a bunch of guys saying &#8216;<em>No</em>&#8216; to SQL. Then I read <a href="http://henk53.wordpress.com/2012/09/11/is-there-such-a-thing-as-the-nomock-movement/">Is there such a thing as the NoMock movement?</a>&#8230; And today I&#8217;m saying <strong>let&#8217;s launch the NoMock Movement</strong> ( &#8216;<em>No</em>&#8216; meaning <em>Not Only </em>of course ;o)</p>
<p>Have you ever felt uncomfortable surrounded by a group of people who all agree and you don&#8217;t ? Feels strange doesn&#8217;t it. You think &#8216;<em>what&#8217;s wrong with me ?</em>&#8216;. That&#8217;s exactly what I felt all these years with <em>Unit Testing</em> and <em>Mocking</em>. Everybody was unit testing, everybody was mocking&#8230; and I was questioning the relevance of so much mocking. Through my customers&#8217; projects I&#8217;ve seen everything from zero test coverage to complex unit tests with more mocks than code to test. But everybody agreed that mocking was the way to go, so I did the same (BTW, thank you <a href="http://code.google.com/p/mockito/">Mockito</a> for showing me the way, your framework rocks).</p>
<p>Then <em>in memory databases</em> arrived (but some were still mocking DB access). Then <em>in memory web servers</em> arrived (but some were still mocking HTTP requests). Then Microsoft decided to do a 64 bits OS so we could have more memory. Then <em>in memory containers</em> arrived (but some where still mocking container services). Then <strong><a href="http://arquillian.org/">Arquillian</a></strong> arrived. So while everybody was mocking I took all these new tools and started to write more and more integration tests, less unit tests and less mocks.</p>
<p>So now I&#8217;m officially launching the <strong>NoMock </strong><b>Movement</b> (&#8216;Not Only Mocks Movement&#8217;). This movement is for people stopping being ashamed of not mocking every single aspect of their code and starting to write more integration tests. Join the movement, don&#8217;t be ashamed and repeat after me : <strong>Stop mocking, start testing !</strong></p>
<p>What are the concrete actions of this movement ? For now it&#8217;s just buying the <strong><a href="http://nomock.org">nomock.org</a></strong> domain name and pointing it to my own website (isn&#8217;t that arrogant !) and then I&#8217;ll see what to do with it when I have some free time (a GitHub site where everybody can aggregate resources about integration testing would be good, so you can all contribute). I&#8217;ve also created the <a href="https://twitter.com/nomockmov">NoMockMov Twitter account</a> and will use it to promote integration testing (by re-tweeting any useful article/blog/resource).</p>
<p>And now, go back to coding (real code)</p>
<h4>References :</h4>
<ul>
<li><a href="http://henk53.wordpress.com/2012/09/11/is-there-such-a-thing-as-the-nomock-movement/">Is there such a thing as the NoMock movement?</a></li>
<li><a href="http://bill.burkecentral.com/2012/05/01/mocks-are-a-mockery/">Mocks are a Mockery</a></li>
<li><a href="https://www.youtube.com/watch?v=Xu5EhKVZdV8">Stop Mocking, Start Testing</a></li>
<li><a href="http://www.infoq.com/articles/dan-allen-arquillian-framework">Dan Allen on Arquillian Testing Framework</a></li>
<li><a title="WYTIWYR : What You Test Is What You Run" href="http://antoniogoncalves.org/2012/01/16/wytiwyr-what-you-test-is-what-you-run/">What You Test Is What You Run</a></li>
</ul>
<p><em>Disclaimer : of course I use unit tests and mocks, I&#8217;m just saying that today we can also use integration tests.</em></p>
<p><em>Disclaimer bis : Take a laugh, not everything in life has to be taken seriously ;o)</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1890/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1890/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1890&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2012/11/27/launching-the-nomock-movement/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2012/11/nomock1.png" medium="image">
			<media:title type="html">NoMock Movement</media:title>
		</media:content>
	</item>
		<item>
		<title>So now I am a NightHacker ;o)</title>
		<link>http://antoniogoncalves.org/2012/11/20/so-now-i-am-a-nighthacker-o/</link>
		<comments>http://antoniogoncalves.org/2012/11/20/so-now-i-am-a-nighthacker-o/#comments</comments>
		<pubDate>Tue, 20 Nov 2012 15:43:06 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[java ee 7]]></category>

		<guid isPermaLink="false">http://antoniogoncalves.org/?p=1872</guid>
		<description><![CDATA[Stephen Chin had this crazy idea of touring Europe on its way to Devoxx, and interview people. He called it the &#8220;Hacking Tour – The Road to Devoxx&#8220;. On his way from Italy he crossed France, stopped over to interview several people and then he arrived in Paris to interview me as well as the&#160;&#8230; <a href="http://antoniogoncalves.org/2012/11/20/so-now-i-am-a-nighthacker-o/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1872&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="https://twitter.com/steveonjava">Stephen Chin</a> had this crazy idea of touring Europe on its way to <a href="http://www.devoxx.com">Devoxx</a>, and interview people. He called it the &#8220;<a href="http://steveonjava.com/nighthacking-tour-the-road-to-devoxx/">Hacking Tour – The Road to Devoxx</a>&#8220;. On his way from Italy he crossed France, stopped over to interview several people and then he arrived in Paris to interview me as well as the Parisian Java community (<a href="www.parisjug.org">Paris JUG</a>, <a href="jduchess.org/duchess-france/">JDuchess</a>, <a href="http://code-story.net/">Code Story</a>). Unfortunately, everything went wrong (network issues mostly) so we had to postpone the interview at Devoxx the following week. Here it is :</p>
<p><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='http://www.youtube.com/embed/xKciaIPuaSc?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span></p>
<p>In this interview I talk about the <a href="http://www.parisjug.org">Paris JUG</a>, <a href="http://www.devoxx.fr">Devoxx France</a>, but mostly about my life as a <strong>Java EE 7 hacker</strong>. Yes, Java EE 7 will be out in April 2013 (in 6 months) so every spec is in Early Draft, the reference implementations are in Alpha or Beta and there is few documentation and blogs. Being expert member of Java EE 7 (<a href="http://jcp.org/en/jsr/detail?id=342">JSR 342</a>), Java EE 7 is a topic that takes a lot of my time lately. In this interview I mostly talk about things that you expect will be working&#8230; but they won&#8217;t (not always easy to have all the spec leads agree and integrate well). But I also show some code that will make your life easier ;o)</p>
<p>Again, thank you <a href="https://twitter.com/steveonjava">Stephen Chin</a> for the interview. You can check out his <a href="http://www.flickr.com/photos/steveonjava/sets/72157631683138022/with/8135689767/">photos</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1872/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1872/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1872&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2012/11/20/so-now-i-am-a-nighthacker-o/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>
	</item>
		<item>
		<title>No, you don&#8217;t need to mock your SOAP Web Service to test it</title>
		<link>http://antoniogoncalves.org/2012/10/24/no-you-dont-need-to-mock-your-soap-web-service-to-test-it/</link>
		<comments>http://antoniogoncalves.org/2012/10/24/no-you-dont-need-to-mock-your-soap-web-service-to-test-it/#comments</comments>
		<pubDate>Wed, 24 Oct 2012 14:56:13 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[nomock]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://antoniogoncalves.org/?p=1854</guid>
		<description><![CDATA[A short blog about a topic I was discussing last week with a customer: testing SOAP Web Services. If you follow my blog you would know by now that I&#8217;m not a fan of unit testing in MOCK environments. Not because I don&#8217;t like it or I have religious believes that don&#8217;t allow me to use JUnit and&#160;&#8230; <a href="http://antoniogoncalves.org/2012/10/24/no-you-dont-need-to-mock-your-soap-web-service-to-test-it/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1854&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="https://github.com/agoncal/agoncal-book-javaee7/tree/master/chapter21/chapter21-service"><img class="size-full wp-image-652 alignright" title="Download the code" alt="" src="http://agoncal.files.wordpress.com/2010/05/download.gif?w=640"   /></a><br />
A short blog about a topic I was discussing last week with a customer: <strong>testing SOAP Web Services</strong>. If you follow my blog you would know by now that I&#8217;m not a fan of unit testing in MOCK environments. Not because I don&#8217;t like it or I have religious believes that don&#8217;t allow me to use <a href="http://www.junit.org/">JUnit</a> and <a href="http://code.google.com/p/mockito/">Mockito</a>. It&#8217;s just because with the work I do (mostly <a href="http://en.wikipedia.org/wiki/Java_ee">Java EE</a> using application servers) my code runs in a managed environment (i.e. containers) and when I start mocking all the container&#8217;s services, it becomes cumbersome and useless. Few months ago I wrote a post about <a title="WYTIWYR : What You Test Is What You Run" href="http://antoniogoncalves.org/2012/01/16/wytiwyr-what-you-test-is-what-you-run/">integration testing with Arquillian</a>. But you don&#8217;t always need <a href="http://arquillian.org/">Arquillian</a> to test inside a container because today, most of the containers are light and run in-memory. Think of an in-memory database. An in-memory web container. An in-memory <a href="http://docs.oracle.com/javaee/6/api/javax/ejb/embeddable/EJBContainer.html">EJB container</a>.</p>
<p>So first, let&#8217;s write a SOAP Web Service. I&#8217;m using the one I use on my <a href="http://antoniogoncalves.org/category/books/">book</a> : a SOAP Web Service that validates a credit card. If you look at the code, there is nothing special about it (the credit card validation algorithm is a dummy one: even numbers are valid, odd are invalid). Let&#8217;s start with the interface :</p>
<pre class="brush: java; highlight: [3]; title: ; notranslate">
import javax.jws.WebService;

@WebService
public interface Validator {
    public boolean validate(CreditCard creditCard);
}
</pre>
<p>Then the SOAP Web Service implementation :</p>
<pre class="brush: java; highlight: [1]; title: ; notranslate">
@WebService(endpointInterface = &quot;org.agoncal.book.javaee7.chapter21.Validator&quot;)
public class CardValidator implements Validator {

  public boolean validate(CreditCard creditCard) {

    Character lastDigit = creditCard.getNumber().charAt(creditCard.getNumber().length() - 1);

    return Integer.parseInt(lastDigit.toString()) % 2 != 0;
  }
}
</pre>
<p>What do you need to test this SOAP Web Service ? Nothing ! The code above is just a POJO so you can write a unit test that checks the validation algorithm. Something as follow :</p>
<pre class="brush: java; highlight: [6]; title: ; notranslate">
public class CardValidatorTest {

  @Test
  public void shouldCheckCreditCardValidity() {

    CardValidator cardValidator = new CardValidator();

    CreditCard creditCard = new CreditCard(&quot;12341234&quot;, &quot;10/10&quot;, 1234, &quot;VISA&quot;);

    assertFalse(&quot;Credit card should be valid&quot;, cardValidator.validate(creditCard));
    creditCard.setNumber(&quot;12341233&quot;);
    assertTrue(&quot;Credit card should not be valid&quot;, cardValidator.validate(creditCard));
  }
}
</pre>
<p>In this unit test I instantiate the CardValidator class and invoke the validate method. This is acceptable, but what if your SOAP Web Serivce uses <a href="http://www.mkyong.com/webservices/jax-ws/jax-ws-soap-handler-in-server-side/">Handlers</a> ? What if it overrides mapping with the webservice.xml deployment descriptor ? Uses the<a href="http://docs.oracle.com/javaee/6/api/javax/xml/ws/WebServiceContext.html"> WebServiceContext</a> ? In short, what if your SOAP Web Service uses containers&#8217; services ? Unit testing becomes useless. So let&#8217;s test your SOAP Web Service inside the container and write an the integration test. For that we can use an in-memory web container. And I&#8217;m not just talking about a GlassFish, JBoss or Tomcat, but something as simple as the web container that come with the SUN&#8217;s JDK. Sun&#8217;s implementation of Java SE 6 includes a <a href="https://blogs.oracle.com/michaelmcm/entry/http_server_api_in_java">light-weight HTTP server</a> API and implementation : <a href="http://docs.oracle.com/javase/6/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/package-summary.html">com.sun.net.httpserver</a>.</p>
<blockquote><p>Note that this default HTTP server is in a com.sun package. So this might not be portable depending on the version of your JDK. Instead of using the default HTTP server it is also possible to plug other implementations as long as they provide a <em>Service Provider Implementation</em> (SPI) for example <a href="http://docs.codehaus.org/display/JETTY/J2se6HttpServerSPI">Jetty&#8217;s J2se6HttpServerSPI</a>.</p></blockquote>
<p>So this is how an integration test using an in memory web container can look like :</p>
<pre class="brush: java; highlight: [6]; title: ; notranslate">
public class CardValidatorIT {

  @Test
  public void shouldCheckCreditCardValidity() throws MalformedURLException {
    // Publishes the SOAP Web Service
    Endpoint endpoint = Endpoint.publish(&quot;http://localhost:8080/cardValidator&quot;, new CardValidator());
    assertTrue(endpoint.isPublished());
    assertEquals(&quot;http://schemas.xmlsoap.org/wsdl/soap/http&quot;, endpoint.getBinding().getBindingID());

    // Data to access the web service
    URL wsdlDocumentLocation = new URL(&quot;http://localhost:8080/cardValidator?wsdl&quot;);
    String namespaceURI = &quot;http://chapter21.javaee7.book.agoncal.org/&quot;;
    String servicePart = &quot;CardValidatorService&quot;;
    String portName = &quot;CardValidatorPort&quot;;
    QName serviceQN = new QName(namespaceURI, servicePart);
    QName portQN = new QName(namespaceURI, portName);

    // Creates a service instance
    Service service = Service.create(wsdlDocumentLocation, serviceQN);
    Validator cardValidator = service.getPort(portQN, Validator.class);

    // Invokes the web service
    CreditCard creditCard = new CreditCard(&quot;12341234&quot;, &quot;10/10&quot;, 1234, &quot;VISA&quot;);

    assertFalse(&quot;Credit card should be valid&quot;, cardValidator.validate(creditCard));
    creditCard.setNumber(&quot;12341233&quot;);
    assertTrue(&quot;Credit card should not be valid&quot;, cardValidator.validate(creditCard));

    // Unpublishes the SOAP Web Service
    endpoint.stop();
    assertFalse(endpoint.isPublished());
  }
}
</pre>
<p><a href="https://github.com/agoncal/agoncal-book-javaee7/tree/master/chapter21/chapter21-service"><img class="size-full wp-image-652 alignright" title="Download the code" alt="" src="http://agoncal.files.wordpress.com/2010/05/download.gif?w=640"   /></a><br />
The Endpoint.publish() method uses by default the light-weight HTTP server implementation that is included in Sun&#8217;s Java SE 6. It publishes the SOAP Web Service and starts listening on URL <a href="http://localhost:8080/cardValidator" rel="nofollow">http://localhost:8080/cardValidator</a>. You can even go to http://localhost:8080/cardValidator?wsdl to see the generated WSDL. The integration test looks for the WSDL document, creates a service using the WSDL information, gets the port to the SOAP Web Service and then invokes the validate method. The method Endpoint.stop() stops the publishin of the service and shutsdown the in-memory web server.</p>
<p>Again, you should be careful as this integration test uses the default HTTP server which is in a com.sun package and therefore not portable.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1854/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1854/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1854&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2012/10/24/no-you-dont-need-to-mock-your-soap-web-service-to-test-it/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2010/05/download.gif" medium="image">
			<media:title type="html">Download the code</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2010/05/download.gif" medium="image">
			<media:title type="html">Download the code</media:title>
		</media:content>
	</item>
		<item>
		<title>I need you for Logging API Spec Lead !</title>
		<link>http://antoniogoncalves.org/2012/09/06/i-need-you-for-logging-api-spec-lead/</link>
		<comments>http://antoniogoncalves.org/2012/09/06/i-need-you-for-logging-api-spec-lead/#comments</comments>
		<pubDate>Thu, 06 Sep 2012 12:05:42 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java ee 7]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://antoniogoncalves.org/?p=1818</guid>
		<description><![CDATA[If you are interested by Java EE development and roadmap you might have read recently that the Cloud feature in Java EE 7 has been delayed. As I&#8217;ve already expressed in the Java EE 7 expert group mailing list, I&#8217;m happy about this news because I feel standardizing cloud in EE 7 was way too early. But&#160;&#8230; <a href="http://antoniogoncalves.org/2012/09/06/i-need-you-for-logging-api-spec-lead/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1818&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-1834" title="I need you for Logging API Spec Lead" src="http://agoncal.files.wordpress.com/2012/09/ineedyou2.gif?w=640" alt=""   />If you are interested by Java EE development and roadmap you might have read recently that the <a href="https://blogs.oracle.com/theaquarium/entry/java_ee_7_roadmap">Cloud feature in Java EE 7 has been delayed</a>. As I&#8217;ve already expressed in the <a href="http://java.net/projects/javaee-spec/lists/jsr342-experts/archive/2012-08/message/14">Java EE 7 expert group mailing list</a>, I&#8217;m happy about this news because I feel standardizing cloud in EE 7 was way too early. But I&#8217;m also sad. Sad because we&#8217;ve spent a lot of time discussing Cloud, PaaS, multi-tenancy&#8230; and not concentrating on other topics. And one topic that I have in mind is <strong>logging !</strong> <strong>Shouldn&#8217;t we standardize a Logging API ?</strong></p>
<p>Few months ago I was struggling (again) with logging configuration in JBoss 7.x. I was so depressed that I wrote to the Java EE 7 expert group : <a href="http://java.net/projects/javaee-spec/lists/users/archive/2012-03/message/45">Logs. Should we finally do something ?</a> (you should read it, there are valuable opinions expressed by the members). As a developer I&#8217;ve used all the possible logging Java frameworks for the last 12 years and I still struggle with logging in 2012. How many logging frameworks do we have ? Look at the list :</p>
<ul>
<li><a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/util/logging/package-summary.html">JUL</a> : the good old <tt>java.util.logging</tt> API that is included in our JDK. Bad luck, it is there and nobody uses it</li>
<li><a href="http://logging.apache.org/log4j/1.2/">Log4j</a> : widely used, Log4j hasn&#8217;t really been updated lately (<em>update : <a href="http://logging.apache.org/log4j/2.x/">the team is working on a 2.0 version</a></em>)</li>
<li><a href="http://commons.apache.org/logging/">Commons Logging</a> : How many more Apache logging frameworks do you want ?</li>
<li><a href="http://www.slf4j.org/">SLF4J</a> : if you are not sure which logging API to use, well, use an abstraction (hum, abstraction, we love abstraction)</li>
<li><a href="http://logback.qos.ch/">Logback</a> : the successor of Log4J (successor ? really ?)</li>
<li><a href="http://www.tinylog.org/">TinyLog</a> : because all these frameworks are too big, we need to use a tiny one</li>
<li><a href="http://java-source.net/open-source/logging">And many many many more Java logging frameworks</a></li>
</ul>
<p>I&#8217;m not a log expert and I&#8217;m sure all these frameworks exist for good reasons (I&#8217;m trying to be politically correct here), but for god sake, we just need to write logs. I don&#8217;t want to do a benchmark of all the logging APIs to make up my mind. I don&#8217;t want to have to relearn a new logging framework each time a new version of my application server is out (yes, JBoss 7 uses its own <a href="http://docs.jboss.org/seam/3/3.1.0.Final/reference/en-US/html/solder-logging.html">JBoss Logging API</a>). To be honest, instead of all saying &#8220;using <tt>System.out.println</tt> is bad&#8221; we should have encouraged it and let Java SE redirect the messages to files (using external configuration). This way our code would be full of <tt>System.out.println("message")</tt> or <tt>System.out.println(WARNING, "message")</tt> and we would have avoided all the logging frameworks. Anyway, this is the situation we&#8217;re in.</p>
<h2>Let&#8217;s standardize a logging API</h2>
<p>Standardizing too soon is bad&#8230; but we&#8217;ve been doing logs for more than a decade now. We have a big expertise in logging, we could even take some ideas of other languages. <strong>So it&#8217;s time to standardize logging</strong>. Let&#8217;s not do the same mistake as <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/util/logging/package-summary.html">JUL</a>  and only standardize an API. Then, we could let all the known frameworks to implement it and fight about better performances or functionalities. Today, logging portability is a nightmare, enough. With a standard API we could also have some tooling and descent log viewers coming on board.</p>
<h2>Integrate this logging API in Java EE (and other specs)</h2>
<p>If all the Java EE specs (EJB, JPA, JAX-RS, CDI&#8230;) use this standard API and impose it to the implementations, we could then easily change the level of logs in a standard way on our applications by using a simple package naming convetion :</p>
<pre class="brush: plain; title: ; notranslate">
javax.ejb.level = debug         // EJB spec
javax.persistence.level = debug // JPA spec
org.weld.level = debug          // CDI implementation (Weld)
my.app.level = debug            // My application
</pre>
<p>And who knows, <a href="http://mreinhold.org/blog/late-for-the-train">when modularization arrives</a> we could get rid of <tt>java.util.logging</tt> and have a new <tt>javax.logging</tt> module in Java SE (and choose the implementation).</p>
<h2>Think to the future</h2>
<p>If we had a <strong>Logging API 1.0 specification</strong>, then, when multi-tenancy comes along, we could have a Logging API <strong>1.1</strong> which handles it (wouldn&#8217;t it be nice to have multi-tenant logs with no effort ?). Another idea would be to play with staging. <a href="http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/#configuration-project-stage">JSF 2.0 introduced staging</a> and it might be spread all over Java EE. If that&#8217;s the case, we could simply use default logging : DEBUG for development, WARNING for production&#8230; That would simplify configuration.</p>
<h2>Do you feel like being a spec lead ?</h2>
<p>No, it&#8217;s not because I write this blog post that I want to be a spec lead. I&#8217;m not the right person, I&#8217;ve never implemented a logging framework, I&#8217;m just a user of theses APIs. So if you feel you know the topic well, if you know people who could help you by being part of your expert group (if you want, I could even join this expert group), then do it. Entering the JCP is not a piece of cake, you need to do a bit of administration to have your JSR approved, but it&#8217;s doable.  You would need a bit of time, but it&#8217;s doable. Even if you start now I&#8217;m not sure there will be enough time to take the Java EE 7 train, but the JCP has some examples of quick JSRs.</p>
<h2><strong>So, who wants to be a Logging API Spec Lead ? Do you think it&#8217;s a good idea to standardize a Logging API ?</strong></h2>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1818/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1818&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2012/09/06/i-need-you-for-logging-api-spec-lead/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2012/09/ineedyou2.gif" medium="image">
			<media:title type="html">I need you for Logging API Spec Lead</media:title>
		</media:content>
	</item>
		<item>
		<title>Yet Another Petstore !</title>
		<link>http://antoniogoncalves.org/2012/06/25/yet-another-petstore/</link>
		<comments>http://antoniogoncalves.org/2012/06/25/yet-another-petstore/#comments</comments>
		<pubDate>Mon, 25 Jun 2012 21:26:26 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[javaee6]]></category>
		<category><![CDATA[petstore]]></category>

		<guid isPermaLink="false">http://antoniogoncalves.org/?p=1783</guid>
		<description><![CDATA[Do you remember the good old Java Petstore ? It was a sample application created by Sun for its Java BluePrints program. The Java Petstore was designed to illustrate how J2EE (and then Java EE) could be used to develop an eCommerce web application. Yes, the point of the Petstore is to sell pets online.&#160;&#8230; <a href="http://antoniogoncalves.org/2012/06/25/yet-another-petstore/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1783&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="https://github.com/agoncal/agoncal-application-petstore-ee6"><img class="size-full wp-image-652 alignright" title="Download the code" src="http://agoncal.files.wordpress.com/2010/05/download.gif?w=640" alt=""   /></a><br />
Do you remember the good old Java <a href="http://java.sun.com/developer/releases/petstore/">Petstore</a> ? It was a sample application created by Sun for its <a href="http://www.oracle.com/technetwork/java/javaee/blueprints/index.html">Java BluePrints</a> program. The Java Petstore was designed to illustrate how J2EE (and then Java EE) could be used to develop an eCommerce web application. Yes, the point of the Petstore is to sell pets online.</p>
<p>The Petstore had a huge momentum and we started to see plenty of <em>Petstore-like</em> applications flourish (the idea was to build an entire application with a certain technology). But let&#8217;s face it, the J2EE version was far too complex and was using plenty of (today outdated) <a href="http://java.sun.com/blueprints/corej2eepatterns/">design patterns</a>. When I wrote my <a href="http://www.eyrolles.com/Informatique/Livre/java-ee5-9782212120387">Java EE 5 book</a> back in 2006 (sorry, it&#8217;s written in French), I decided to write a Petstore-like application in Java EE 5 but much simpler. <strong>But again, it&#8217;s out-dated today</strong>.</p>
<p>Later on I wrote a book about <a href="http://www.apress.com/9781430228899">Java EE 6</a>and felt there was a need to have an updated Petstore so we could discover new patterns and APIs. Unfortunately Sun/Oracle didn&#8217;t do it&#8230; so I&#8217;ve decided to do it myself (with some help from my friends <a href="https://twitter.com/#!/antoine_sd">Antoine Sabot-Durand</a>, <a href="https://twitter.com/#!/blep">Brice Leporini</a>, Hervé Le Morvan). I&#8217;ve updated my <a href="https://github.com/agoncal/agoncal-application-petstore-ee6">YAPS Petstore</a> to follow <a href="http://jcp.org/en/jsr/detail?id=316">Java EE 6</a> and all its goodies (<a href="http://jcp.org/en/jsr/detail?id=299">CDI</a>, <a href="http://jcp.org/en/jsr/detail?id=318">EJB Lite</a>, <a href="http://jcp.org/en/jsr/detail?id=311">REST interface</a>, <a href="http://jcp.org/en/jsr/detail?id=303">Bean Validation</a>).</p>
<p style="text-align:center;"><a href="https://github.com/agoncal/agoncal-application-petstore-ee6"><img class="aligncenter size-full wp-image-1784" title="Download the code of the YAPS Petstore" src="http://agoncal.files.wordpress.com/2012/06/yapspetstore.jpg?w=640" alt=""   /></a></p>
<p>The goals of this sample is to :</p>
<ul>
<li><strong>use Java EE 6 and just Java EE 6</strong> : no external framework or dependency (I even use <tt>java.util.logging</tt> API ;o)</li>
<li><strong>make it simple</strong> : no complex business algorithm, but I use most of the Java EE 6 APIs, the point is to bring Java EE 6 technologies together to create an eCommerce website</li>
</ul>
<p>If you want to use a different web interface (PrimeFaces, pure HTML, Android&#8230;), external frameworks, add some sexy alternative JVM language… feel free to <a href="https://github.com/agoncal/agoncal-application-petstore-ee6">fork the code</a> and do so. But I won&#8217;t do it because I want this EE 6 Petstore to remain simple and to stick to Java EE 6.</p>
<p><a href="https://github.com/agoncal/agoncal-application-petstore-ee6"><img class="size-full wp-image-652 alignright" title="Download the code" src="http://agoncal.files.wordpress.com/2010/05/download.gif?w=640" alt=""   /></a><br />
The only external frameworks that I&#8217;ve used are <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a> (so my JSF pages don&#8217;t look too ugly) and <a href="http://arquillian.org/">Arquillian</a> for integration testing. My goal is to be able to deploy this <a href="https://github.com/agoncal/agoncal-application-petstore-ee6">Yaps Petstore</a> on different application servers. For now it&#8217;s mostly <a href="http://glassfish.java.net/">GlassFish</a>, <a href="http://www.jboss.org/">JBoss</a> but some work is also happening on <a href="https://github.com/rmannibucau/agoncal-application-petstore-ee6">TomEE</a> and I&#8217;ll try to port it later on <a href="http://www.caucho.com/resin-application-server/">Resin</a>, Weblogic, Websphere&#8230;. and who knows, do some performance benchmark of the same application but on different servers.</p>
<p>My next task is to deploy this Yaps Petstore on <a href="http://www.cloudbees.com/">CloudBees</a>&#8230; stay tuned. In the meantime, give it a try and let me know what you think.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1783/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1783&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2012/06/25/yet-another-petstore/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2010/05/download.gif" medium="image">
			<media:title type="html">Download the code</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2012/06/yapspetstore.jpg" medium="image">
			<media:title type="html">Download the code of the YAPS Petstore</media:title>
		</media:content>

		<media:content url="http://agoncal.files.wordpress.com/2010/05/download.gif" medium="image">
			<media:title type="html">Download the code</media:title>
		</media:content>
	</item>
		<item>
		<title>How to get the JPQL/SQL String From a CriteriaQuery in JPA ?</title>
		<link>http://antoniogoncalves.org/2012/05/24/how-to-get-the-jpqlsql-string-from-a-criteriaquery-in-jpa/</link>
		<comments>http://antoniogoncalves.org/2012/05/24/how-to-get-the-jpqlsql-string-from-a-criteriaquery-in-jpa/#comments</comments>
		<pubDate>Thu, 24 May 2012 14:27:25 +0000</pubDate>
		<dc:creator>agoncal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[eclipselink]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[openjpa]]></category>

		<guid isPermaLink="false">http://agoncal.wordpress.com/?p=1756</guid>
		<description><![CDATA[I.T. is full of complex things that should (and sometimes could) be simple. Getting the JQPL/SQL String representation for a JPA 2.0 CriteriaQuery is one of them. By now you all know the JPA 2.0 Criteria API : a type safe way to write a JQPL query. This API is clever in the way that you&#160;&#8230; <a href="http://antoniogoncalves.org/2012/05/24/how-to-get-the-jpqlsql-string-from-a-criteriaquery-in-jpa/">Read&#160;more</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1756&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I.T. is full of complex things that should (and sometimes could) be simple. Getting the JQPL/SQL String representation for a JPA 2.0 <a href="http://docs.oracle.com/javaee/6/api/javax/persistence/criteria/CriteriaQuery.html">CriteriaQuery</a> is one of them.</p>
<p>By now you all know the <a href="http://docs.oracle.com/javaee/6/tutorial/doc/gjitv.html">JPA 2.0 Criteria API</a> : a type safe way to write a JQPL query. This API is clever in the way that you don&#8217;t use Strings to build your query, but is quite verbose&#8230; and sometimes you get lost in dozens of lines of Java code, just to write a simple query. <strong>You get lost in your CriteriaQuery</strong>, you don&#8217;t know why your query doesn&#8217;t work, and <strong>you would love to debug it</strong>. But how do you debug it ? Well, one way would be by just displaying the JPQL and/or SQL representation. Simple, isn&#8217;t it ? Yes, but JPA 2.0 <a href="http://grepcode.com/file/maven.glassfish.org/content/repositories/eclipselink/org.eclipse.persistence/javax.persistence/2.0.2/javax/persistence/Query.java#Query">javax.persistence.Query</a> doesn&#8217;t have an API to do this. You then need to rely on the implementation&#8230; meaning, the code is different if you use <a href="http://www.eclipse.org/eclipselink/">EclipseLink</a>, <a href="http://www.hibernate.org/">Hibernate</a> or <a href="http://openjpa.apache.org/">OpenJPA</a>.</p>
<h1>The CriteriaQuery we want to debug</h1>
<p>Let&#8217;s say you have a simple <tt>Book</tt> entity and you want to retrieve all the books sorted by their id. Something like <strong><tt>SELECT b FROM Book b ORDER BY b.id DESC</tt></strong>. How would you write this with the CriteriaQuery ? Well, something like these 5 lines of Java code :</p>
<pre class="brush: java; highlight: [5]; title: ; notranslate">
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery&lt;Book&gt; q = cb.createQuery(Book.class);
Root&lt;Book&gt; b = q.from(Book.class);
q.select(b).orderBy(cb.desc(b.get(&quot;id&quot;)));
TypedQuery&lt;Book&gt; findAllBooks = em.createQuery(q);
</pre>
<p>So imagine when you have more complex ones. Sometimes, you just get lost, it gets buggy and you would appreciate to have the JPQL and/or SQL String representation to find out what&#8217;s happening. You could then even unit test it.</p>
<h1>Getting the JPQL/SQL String Representations for a Criteria Query</h1>
<p>So let&#8217;s use an API to get the JPQL/SQL String representations of a CriteriaQuery (to be more precise, the <a href="http://grepcode.com/file/maven.glassfish.org/content/repositories/eclipselink/org.eclipse.persistence/javax.persistence/2.0.2/javax/persistence/TypedQuery.java#TypedQuery">TypedQuery</a> created from a <a href="http://grepcode.com/file/maven.glassfish.org/content/repositories/eclipselink/org.eclipse.persistence/javax.persistence/2.0.2/javax/persistence/criteria/CriteriaQuery.java#CriteriaQuery">CriteriaQuery</a>). The bad news is that there is no standard JPA 2.0 API to do this. You need to use the implementation API hoping the implementation allows it (thank god that&#8217;s (nearly) the case for the 3 main JPA ORM frameworks). The good news is that the <a href="http://docs.oracle.com/javaee/6/api/javax/persistence/Query.html">Query</a> interface (and therefore <a href="http://docs.oracle.com/javaee/6/api/javax/persistence/TypedQuery.html">TypedQuery</a>) has an <a href="http://docs.oracle.com/javaee/6/api/javax/persistence/Query.html#unwrap(java.lang.Class)">unwrap</a> method. This method returns the provider&#8217;s query API implementation. Let&#8217;s see how you can use it with <a href="http://www.eclipse.org/eclipselink/">EclipseLink</a>, <a href="http://www.hibernate.org/">Hibernate</a> and <a href="http://openjpa.apache.org/">OpenJPA</a>.</p>
<h2>EclipseLink</h2>
<p><a href="http://www.eclipse.org/eclipselink/">EclipseLink</a>&#8216;s Query representation is the <a href="http://grepcode.com/file/maven.glassfish.org/content/repositories/eclipselink/org.eclipse.persistence/eclipselink/2.1.1/org/eclipse/persistence/jpa/JpaQuery.java#JpaQuery">org.eclipse.persistence.jpa.JpaQuery</a> interface and the <a href="http://grepcode.com/file/maven.glassfish.org/content/repositories/eclipselink/org.eclipse.persistence/eclipselink/2.1.1/org/eclipse/persistence/internal/jpa/EJBQueryImpl.java#EJBQueryImpl">org.eclipse.persistence.internal.jpa.EJBQueryImpl</a> implementation.  This interface gives you the wrapped native query (<a href="http://grepcode.com/file/maven.glassfish.org/content/repositories/eclipselink/org.eclipse.persistence/eclipselink/2.1.1/org/eclipse/persistence/queries/DatabaseQuery.java#DatabaseQuery">org.eclipse.persistence.queries.DatabaseQuery</a>) with two very handy methods : <tt>getJPQLString()</tt> and <tt>getSQLString()</tt>. Unfortunatelly the <tt>getJPQLString()</tt> method will not translate a CriteriaQuery into JPQL, it only works for queries originally written in JPQL (dynamic or named query). The <tt>getSQLString()</tt> method relies on the query being &#8220;prepared&#8221;, meaning you have to run the query once before getting the SQL String representation.</p>
<pre class="brush: java; title: ; notranslate">
findAllBooks.unwrap(JpaQuery.class).getDatabaseQuery().getJPQLString(); // doesn't work for CriteriaQuery
findAllBooks.unwrap(JpaQuery.class).getDatabaseQuery().getSQLString();
</pre>
<h2>Hibernate</h2>
<p><a href="http://www.hibernate.org/">Hibernate</a>&#8216;s Query representation is <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-core/4.1.1.Final/org/hibernate/Query.java#Query">org.hibernate.Query</a>. This interface has several implementations and the very useful method that returns the SQL query string : <tt>getQueryString()</tt>. I couldn&#8217;t find a method that returns the JPQL representation, if I&#8217;ve missed something, please let me know.</p>
<pre class="brush: java; title: ; notranslate">
findAllBooks.unwrap(org.hibernate.Query.class).getQueryString()
</pre>
<h2>OpenJPA</h2>
<p><a href="http://openjpa.apache.org/">OpenJPA</a>&#8216;s Query representation is <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.openjpa/openjpa-persistence/2.2.0/org/apache/openjpa/persistence/QueryImpl.java#QueryImpl">org.apache.openjpa.persistence.QueryImpl</a> and also has a <tt>getQueryString()</tt> method that returns the SQL (not the JPQL). It delegates the call to the internal <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.openjpa/openjpa-kernel/2.2.0/org/apache/openjpa/kernel/Query.java#Query">org.apache.openjpa.kernel.Query</a> interface. I couldn&#8217;t find a method that returns the JPQL representation, if I&#8217;ve missed something, please let me know.</p>
<pre class="brush: java; title: ; notranslate">
findAllBooks.unwrap(org.apache.openjpa.persistence.QueryImpl.class).getQueryString()
</pre>
<h1>Unit testing</h1>
<p>Once you get your SQL String, why not unit test it ? Hey, but I don&#8217;t want to test my ORM, why would I do that ? Well, it happens that I&#8217;ve discovered a but in the new releases of OpenJPA by unit testing a query&#8230; so, there is a use case for that. Anyway, this is how you could do it :</p>
<pre class="brush: java; title: ; notranslate">
assertEquals(&quot;SELECT b FROM Book b ORDER BY b.id DESC&quot;, findAllBooksCriteriaQuery.unwrap(org.apache.openjpa.persistence.QueryImpl.class).getQueryString());
</pre>
<h1>Conclusion</h1>
<p>As you can see, it&#8217;s not that simple to get a String representation for a TypedQuery. Here is a digest of the three main ORMs :</p>
<table border="1">
<tbody>
<tr>
<td>ORM Framework</td>
<td>Query implementation</td>
<td>How to get the JPQL String</td>
<td>How to get the SPQL String</td>
</tr>
<tr>
<td>EclipseLink</td>
<td><a href="http://grepcode.com/file/maven.glassfish.org/content/repositories/eclipselink/org.eclipse.persistence/eclipselink/2.1.1/org/eclipse/persistence/jpa/JpaQuery.java#JpaQuery">JpaQuery</a></td>
<td>getDatabaseQuery().getJPQLString()*</td>
<td>getDatabaseQuery().getSQLString()**</td>
</tr>
<tr>
<td>Hibernate</td>
<td><a href="http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-core/4.1.1.Final/org/hibernate/Query.java#Query">Query</a></td>
<td>N/A</td>
<td>getQueryString()</td>
</tr>
<tr>
<td>OpenJPA</td>
<td><a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.openjpa/openjpa-persistence/2.2.0/org/apache/openjpa/persistence/QueryImpl.java#QueryImpl">QueryImpl</a></td>
<td>getQueryString()</td>
<td>N/A</td>
</tr>
</tbody>
</table>
<p><em>(*) Only possible on a dynamic or named query. Not possible on a CriteriaQuery</em><br />
<em> (**) You need to execute the query first, if not, the value is null</em></p>
<p>To illustrate all that I&#8217;ve written simple test cases using <a href="http://www.eclipse.org/eclipselink/">EclipseLink</a>, <a href="http://www.hibernate.org/">Hibernate</a> and <a href="http://openjpa.apache.org/">OpenJPA</a> that you can <a href="https://github.com/agoncal/agoncal-sample-jpa-querystring">download from GitHub</a>. Give it a try and let me know.</p>
<h1>And what about having an API in JPA 2.1 ?</h1>
<p>For a developers&#8217; point of view it would be great to have two methods in the <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate.javax.persistence/hibernate-jpa-2.0-api/1.0.0.Final/javax/persistence/Query.java#Query">javax.persistence.Query</a> (and therefore <a href="http://grepcode.com/file/maven.glassfish.org/content/repositories/eclipselink/org.eclipse.persistence/javax.persistence/2.0.2/javax/persistence/TypedQuery.java#TypedQuery">javax.persistence.TypedQuery</a>) interface that would be able to easily return the JPQL and SQL String representations, e.g : <tt>Query.getJPQLString()</tt> and <tt>Query.getSQLString()</tt>. Hey, that would be the perfect time to have it in <a href="http://jcp.org/en/jsr/detail?id=338">JPA 2.1</a> that will be shipped in less than a year. Now, as an implementer, this might be tricky to do, I would love to ear your point of view on this.</p>
<p>Anyway, I&#8217;m going to post an email to the <a href="http://java.net/projects/jpa-spec/">JPA 2.1 Expert Group</a>&#8230; just in case we can have this in the next version of JPA ;o)</p>
<h1>References</h1>
<ul>
<li><a href="http://efreedom.com/Question/1-6412774/Get-SQL-String-JPQLQuery">http://efreedom.com/Question/1-6412774/Get-SQL-String-JPQLQuery</a></li>
<li><a href="http://old.nabble.com/Cannot-get-the-JPQL---SQL-String-of-a-CriteriaQuery-td33882629.html">http://old.nabble.com/Cannot-get-the-JPQL&#8212;SQL-String-of-a-CriteriaQuery-td33882629.html</a></li>
<li><a href="http://paddyweblog.blogspot.fr/2010/04/some-examples-of-criteria-api-jpa-20.html">http://paddyweblog.blogspot.fr/2010/04/some-examples-of-criteria-api-jpa-20.html</a></li>
<li><a href="http://www.altuure.com/2010/09/23/jpa-criteria-api-by-samples-part-i/">http://www.altuure.com/2010/09/23/jpa-criteria-api-by-samples-part-i/</a></li>
<li><a href="http://www.altuure.com/2010/09/23/jpa-criteria-api-by-samples-%E2%80%93-part-ii/">http://www.altuure.com/2010/09/23/jpa-criteria-api-by-samples-%E2%80%93-part-ii/</a></li>
<li><a href="http://www.jumpingbean.co.za/blogs/jpa2-criteria-api">http://www.jumpingbean.co.za/blogs/jpa2-criteria-api</a></li>
<li><a href="http://wiki.eclipse.org/EclipseLink/FAQ/JPA#How_to_get_the_SQL_for_a_Query.3F">http://wiki.eclipse.org/EclipseLink/FAQ/JPA#How_to_get_the_SQL_for_a_Query.3F</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/agoncal.wordpress.com/1756/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/agoncal.wordpress.com/1756/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=antoniogoncalves.org&#038;blog=7143934&#038;post=1756&#038;subd=agoncal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://antoniogoncalves.org/2012/05/24/how-to-get-the-jpqlsql-string-from-a-criteriaquery-in-jpa/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1fc6aa04011b2f0f9721df913b0fd415?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">agoncal</media:title>
		</media:content>
	</item>
	</channel>
</rss>
