<?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>Vonk's Blog</title>
	<atom:link href="http://blog.larsvonkconsultancy.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.larsvonkconsultancy.nl</link>
	<description>Blogs about Software Development, Agility and all the Rest</description>
	<lastBuildDate>Fri, 31 Jul 2009 13:51:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FitNesse Scenario are the Bomb</title>
		<link>http://blog.larsvonkconsultancy.nl/2009/07/fitnesse-scenario-are-the-bomb/</link>
		<comments>http://blog.larsvonkconsultancy.nl/2009/07/fitnesse-scenario-are-the-bomb/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 13:22:31 +0000</pubDate>
		<dc:creator>Lars Vonk</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[fitnesse]]></category>
		<category><![CDATA[scenarios]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[slim]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://blog.larsvonkconsultancy.nl/?p=89</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://blog.larsvonkconsultancy.nl/2009/07/tdd-tips/">previous blog</a> on TDD I advocated that you should define your test on a high level. One of the reasons why you should use a high level language is that you can use your tests not only for your API but also for for instance your UI. In this blog I will show how you can use the same test pages in FitNesse to test both the API and UI of your system.</p>
<p><span id="more-89"></span></p>
<p>Using <a href="http://fitnesse.org/FitNesse.UserGuide.SliM" onclick="pageTracker._trackPageview('/outgoing/fitnesse.org/FitNesse.UserGuide.SliM?referer=');">Slim</a> Scenario fixtures this can be implemented fairly easy. Scenarios are Slim tables that can be called form other Slim tables. For a step by step tutorial on how to apply Scenarios I recommend watching Bob Martin&#8217;s <a href="http://vimeo.com/3323573" onclick="pageTracker._trackPageview('/outgoing/vimeo.com/3323573?referer=');">screencast</a>. </p>
<p>With a few additions to Bob Martin&#8217;s video you can use that test for both API and UI.</p>
<p>Lets say we have the following BDD style test:</p>
<pre class="brush: plain;">
given a current maximum capacity of 2 and 1 items already planned
then I can lower the maximum capacity to 1
then I can not lower the maximum capacity to 0
</pre>
<p>Using scenarios this would end up in the following FitNesse markup:</p>
<pre class="brush: plain;">
!|scenario|given a current maximum capacity of |maxCapacity| and |itemsPlanned| items already planned|
|set maximum capacity to|@maxCapacity|
|plan|@itemsPlanned|items|

!|scenario|then I can lower the maximum capacity to|newMaxCapacity|
|ensure|set maximum capacity to|@newMaxCapacity|

!|scenario|then I can not lower the maximum capacity to|newMaxCapacity|
|reject|set maximum capacity to|@newMaxCapacity|

!|script|MaxCapacityApiDriver|

!|script|
|given a current maximum capacity of |2| and |1| items already planned|
|then I can lower the maximum capacity to |1|
|then I can not lower the maximum capacity to |0|
</pre>
<p>And the fixture would look like this:</p>
<pre class="brush: java;">
public class MaxCapacityApiDriver {

	private Capacity capacity = new Capacity();

	public boolean setMaximumCapacityTo(int max) {
		try {
			capacity.setMax(max);
			return true;
		} catch(MoreItemsThanCapacityException e) {
			return false;
		}
	}

	public void planItems(int items) {
		for(int x=0; x&lt;items; x++) {
			capacity.plan();
		}
	}
}
</pre>
<p>Now if we look at the example we could also apply this to our maintenance user interface where the admin can actually change the max capacity.</p>
<p>Using selenium-rc this can be implemented fairly easy. I choose to keep the FitNesse pages the same, the only thing I change is the driver that is used. </p>
<p><strong>Step 1. Extract Scenario</strong></p>
<p>we do not want to duplicate the scenarios so we extract the scenarios to a seperate page. We can then include this page using the !include directive in FitNesse.</p>
<p>Our test FitNesse markup now looks like this:</p>
<pre class="brush: plain;">
!include ScenarioPage

!|script|MaxCapacityApiDriver|

!|script|
|given a current maximum capacity of |2| and |1| items already planned|
|then I can lower the maximum capacity to |1|
|then I can not lower the maximum capacity to |0|
</pre>
<p><strong>Step 2. Extract Test</strong></p>
<p>Wait a minute. We also want to reuse our BDD style test. Let&#8217;s do the same trick as we did using the ScenarioPage.</p>
<p>After extracting the Test our FitNesse markup looks like this:</p>
<pre class="brush: plain;">
!include ScenarioPage

!|script|MaxCapacityApiDriver|

!include TestPage
</pre>
<p><strong>Step 3. Implement Driver</strong></p>
<p>Now all we have to do is implement the UI driver.</p>
<pre class="brush: plain;">
!include ScenarioPage

!|script|MaxCapacityUiDriver|

!include TestPage
</pre>
<p>This is how the fixture code could look like using <a href="http://seleniumhq.org/projects/remote-control/" onclick="pageTracker._trackPageview('/outgoing/seleniumhq.org/projects/remote-control/?referer=');">selenium-rc</a>, I left out some plumbing for readability</p>
<pre class="brush: java;">
public class MaxCapacityUiDriver {

	private Selenium selenium;

	public boolean setMaximumCapacityTo(int max) {
		selenium.open(&quot;/capacity/change&quot;);
		selenium.type(&quot;maximum&quot;, String.valueOf(max));
		selenium.click(&quot;changeMaxButton&quot;);
		selenium.waitForPageToLoad(TIMEOUT);
		return selenium.isTextPresent(&quot;successfully changed capacity to: &quot;
				+ max);
	}

	public void planItems(int items) {
		selenium.open(&quot;/items&quot;);
		for (int x = 0; x &lt; items; x++) {
			selenium.click(&quot;planItem&quot;);
			selenium.waitForPageToLoad(TIMEOUT);
		}
	}
}
</pre>
<p>Using FitNesse scenarios and extracting pages to include them is very handy when you want to re-use some tests. Please keep in mind that it is not wise to test your application code through your UI, so apply this carefully. I tend to pick only a few scenarios to see if the UI and API communicate properly.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.larsvonkconsultancy.nl/2009/07/fitnesse-scenario-are-the-bomb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TDD Tips</title>
		<link>http://blog.larsvonkconsultancy.nl/2009/07/tdd-tips/</link>
		<comments>http://blog.larsvonkconsultancy.nl/2009/07/tdd-tips/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 11:52:37 +0000</pubDate>
		<dc:creator>Lars Vonk</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[acceptance testing]]></category>
		<category><![CDATA[fitnesse]]></category>
		<category><![CDATA[user story]]></category>

		<guid isPermaLink="false">http://blog.larsvonkconsultancy.nl/?p=75</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>I am practicing TDD for some years now and it took me a while and some mistakes to fully take advantage of it. Unfortunately I see a lot of people struggling with TDD and making the same mistakes I have made in the past. So here is a summary of what I think are the key aspects of TDD:</p>
<p><span id="more-75"></span></p>
<p><strong>1. Start with the acceptance tests for your feature.</strong></p>
<p>This is the most important one of all. According to its definition <i>&#8220;In TDD each new feature starts with writing a test&#8221;</i>[1]. Since a feature is always something that the user wants you must, by definition, start with the tests for your user stories. Now-a-days that is called Acceptance Test-Driven Development, but that is just toying with words. It is just TDD as it is meant to be IMHO.<br />
A good way to write your tests is to use examples in BDD style: Given, When, Then. Since examples are concrete they are usually understandable for both User and Programmer. I tend to use <a href="http://fitnesse.org" onclick="pageTracker._trackPageview('/outgoing/fitnesse.org?referer=');">FitNesse</a> as framework to automate these tests right away. <a href="http://vimeo.com/3323573" onclick="pageTracker._trackPageview('/outgoing/vimeo.com/3323573?referer=');">Here</a> is an excellent video tutorial by Bob Martin describing how to create BDD style tests in FitNesse. </p>
<p><strong>2. Refactoring is part of the job.</strong></p>
<p>I see a lot of Red-Green, Red-Green, Red-Green out there. Refactoring is actually the biggest step in the whole TDD cycle IMHO. This is where you do the actual design of your system. You created a test, made it work, now it is time to take a step back and make it right. Maybe this requires a (small) design session in front of a whiteboard with your colleagues, or maybe you can do it on a napkin. It doesn&#8217;t really matter how you do it, as long as you do it. Especially in the first couple of iterations of your project the refactoring step can be quite long in my experience. That is not so hard to grasp since the foundations of your system are created then.<br />
TDD is about helping you to come to a good design for your system. Since the tests are in fact the first clients of your system they help you focus on what your system should do, and how it will be used.</p>
<p><strong>3. Formulate your tests in high-level terms.</strong></p>
<p>I got this tip on the FitNesse maillinglist from Rick Mugridge. This was a real <a href="http://de.wikipedia.org/wiki/Aha-Erlebnis" onclick="pageTracker._trackPageview('/outgoing/de.wikipedia.org/wiki/Aha-Erlebnis?referer=');">A-ha erlebnis</a> for me. It means that you avoid using implementation details in your tests. For instance if you are going to test a UI, the &#8220;wrong way&#8221; to define your test is:</p>
<pre class="brush: plain;">
open page myapp.com
type &quot;Lars&quot; into field &quot;Name&quot;
type &quot;secret&quot; into field &quot;password&quot;
click button &quot;login&quot;
</pre>
<p>The &#8220;right way&#8221; is:</p>
<pre class="brush: plain;">
given a logged in user &quot;Lars&quot; with password &quot;secret&quot;
</pre>
<p>Why is this important?<br />
First of all the &#8220;wrong way&#8221; example is not refactor safe. What if we change the name of the fields, or split it into 2 pages? Then that would require to change our tests. And one of the biggest advantages of (acceptance) tests is that you don&#8217;t need to change them when you do (small) refactorings.<br />
Secondly when you define your tests the &#8220;right way&#8221; they can be used for both UI testing, API testing, SQL testing etc. Since the tests do not expose implementation details, we can use the definition for multiple implementations. Using FitNesse scenario&#8217;s you could simply reuse your test page and just use a different Fixture that implements the actual test in the preferred technology (SQL, Java, Webservice, Selenium etc). In my next blog I&#8217;ll show you how to do that.</p>
<p><strong>4. Keep the database out as long as possible.</strong></p>
<p>When designing your system with TDD you will do a lot of refactorings, especially in the first iterations. I you use a database from scratch that will only slow down the process since databases aren&#8217;t as refactorable as for instance Java code. Secondly in 99% of the applications the database is only a datastorage and the performance impact is not really an issue, meaning the database won&#8217;t impact your design in order to meet those performance criteria. So if it does not contribute to your design why drag it with you all the time? So in the first iterations I tend to use a hashmap or so as database implementation. Now-a-days it is relatively simple to map your object model to a relation model anyway using tools as Hibernate.</p>
<p>So to take full advantage of TDD start out with your User Story tests and define them on a high level (using Given, When, Then). When you made it work, refactor it to a good design. It helps when you keep the database out as long as possible, because databases slow down the refactoring process.</p>
<p>Lars </p>
<p>[1] <a href="http://en.wikipedia.org/wiki/Test-driven_development#1._Add_a_test" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Test-driven_development_1._Add_a_test?referer=');">http://en.wikipedia.org/wiki/Test-driven_development#1._Add_a_test</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.larsvonkconsultancy.nl/2009/07/tdd-tips/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ignoring files on svn:import with subversion</title>
		<link>http://blog.larsvonkconsultancy.nl/2009/05/ignoring-files-on-svnimport-with-subversion/</link>
		<comments>http://blog.larsvonkconsultancy.nl/2009/05/ignoring-files-on-svnimport-with-subversion/#comments</comments>
		<pubDate>Fri, 15 May 2009 07:18:07 +0000</pubDate>
		<dc:creator>Lars Vonk</dc:creator>
				<category><![CDATA[Subversion]]></category>
		<category><![CDATA[ignore]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://lvonk.wordpress.com/?p=65</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Sometimes when I start a project I already have some folder structure and code in place that I want to put into Subversion. However there are also already some files and folders present that I want to ignore on import. Subversion does not provide a way to ignore files on <a href="http://svnbook.red-bean.com/en/1.5/svn-book.html#svn.ref.svn.c.import" onclick="pageTracker._trackPageview('/outgoing/svnbook.red-bean.com/en/1.5/svn-book.html_svn.ref.svn.c.import?referer=');">svn:import</a> using the command line. But by using the <a href="http://svnbook.red-bean.com/en/1.5/svn-book.html#svn.advanced.confarea.opts.config" onclick="pageTracker._trackPageview('/outgoing/svnbook.red-bean.com/en/1.5/svn-book.html_svn.advanced.confarea.opts.config?referer=');">global-ignores</a> feature you can ignore files on svn:import when you follow these steps.<br />
<span id="more-65"></span></p>
<p>1. First locate the Subversion <em>config</em> file. Most probably you will find it at <em>${HOME}/.subversion/config</em>. In the file locate the <em>global-ignores</em> line and add the patterns you wish to exclude from the import, typically these are generated files like <em>.class</em> files etc. For instance in a Maven, Java, Eclipse project you would put: <code>global-ignores = target .classpath .project .settings</code></p>
<p>2. Run <code>svn:import [PATH] URL</code>. Now everything you put in the global-ignores line is excluded from the import.</p>
<p>3.  You still do not have a working copy though since svn:import does not replace the local files with the working copy. To achieve this you can run <code>svn co --force URL [PATH]</code></p>
<p>4. Now the files you put in global-ignores on your local file system are not ignored on your colleagues machine when they do a fresh checkout. So they could be temped to check-in the generated files. To prevent this you need to add the files to the svn:ignore list of the parent folder using the propset (or propedit) command. To achieve this you first need to comment out the global-ignores line in your config file. Then add the generated files to svn:ignore and check the code in.</p>
<p>This way you can check-in new code into subversion without having to manually remove all the generated files first. It would be nice though if Subversion provided a way to ignore files on import and checkout the code in a single command.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.larsvonkconsultancy.nl/2009/05/ignoring-files-on-svnimport-with-subversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Power of ClassPathScanningCandidateComponentProvider</title>
		<link>http://blog.larsvonkconsultancy.nl/2009/01/the-power-of-classpathscanningcandidatecomponentprovider/</link>
		<comments>http://blog.larsvonkconsultancy.nl/2009/01/the-power-of-classpathscanningcandidatecomponentprovider/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 16:26:42 +0000</pubDate>
		<dc:creator>Lars Vonk</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://lvonk.wordpress.com/?p=51</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Recently I found out about Springs <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.html" onclick="pageTracker._trackPageview('/outgoing/static.springframework.org/spring/docs/2.5.x/api/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.html?referer=');">ClassPathScanningCandidateComponentProvider</a>. This class allows you to scan the classpath from a base package at runtime. This is extremely handy in all kind of situations, for instances in testing.<br />
<span id="more-51"></span><br />
As an example scenario I have a secured webapplication, build with <a href="http://wicket.apache.org/" onclick="pageTracker._trackPageview('/outgoing/wicket.apache.org/?referer=');">Wicket</a>. All the <a href="http://wicket.sourceforge.net/apidocs/wicket/markup/html/WebPage.html" onclick="pageTracker._trackPageview('/outgoing/wicket.sourceforge.net/apidocs/wicket/markup/html/WebPage.html?referer=');">WebPage</a>s need to be secured using the <a href="http://cwiki.apache.org/WICKET/acegi-and-wicket-auth-roles.html" onclick="pageTracker._trackPageview('/outgoing/cwiki.apache.org/WICKET/acegi-and-wicket-auth-roles.html?referer=');">wicket-auth-roles</a>. We can test this by creating a junit test using WicketTester and assert that is we want to start a secured page it will actually open the LoginPage. This will work, but it needs to be repeated for all new secure WebPages. This is of course cumbersome and it is highly likely we will forget to add a test for the next WebPage we will create.<br />
Better is to use the power of the ClassPathScanningCandidateComponentProvider. With this class we can simply scan the classpath and look for WebPages in the admin package and check if they are annotated with the @AuthorizeInstantiation annotation.</p>
<pre class="brush: java;">
   @Test
    public void shouldSecureAllPagesInAdminPackageExceptTheLoginPage() throws Exception {
        ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
        provider.addIncludeFilter(new NonSecuredWebPagesFilter(LoginPage.class));
        Set components = provider.findCandidateComponents(&quot;nl.ns.campaigns.admin.web&quot;);
        assertEquals(0, components.size());
    }
</pre>
<p>The idea of this test is that it should not find classes that extend WebPage and that are not annotated with @AuthorizeInstantiation. If we do find one, the test will fail.<br />
The logic match is implemented in a TypeFilter, in this case the custom NonSecuredWebPagesFilter. The code of the TypeFilter looks like this:</p>
<pre class="brush: java;">
    private static final class NonSecuredWebPagesFilter implements TypeFilter {
        private final Class loginPage;
        public NonSecuredWebPagesFilter(Class loginPage) {
            this.loginPage = loginPage;
        }
        public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
            boolean hasAnnotation = false;
            boolean isWebPage = false;
            boolean isLoginPage = false;
            try {
                String className = metadataReader.getClassMetadata().getClassName();
                Class clazz = Class.forName(className);
                isLoginPage = loginPage.equals(clazz);
                isWebPage = WebPage.class.isAssignableFrom(clazz);
                hasAnnotation = clazz.isAnnotationPresent(AuthorizeInstantiation.class);
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException(e);
            }
            return !hasAnnotation &amp;&amp; isWebPage &amp;&amp; !isLoginPage;
        }
    }
</pre>
<p>Since the LoginPage does not have to be annotated we exclude it from our search. Only WebPages that are not annotated are returned due to this TypeFilter.</p>
<p>Scanning the classpath has become a piece of cake using the ClassPathScanningCandidateComponentProvider and I am sure there are many more usecases for this class.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.larsvonkconsultancy.nl/2009/01/the-power-of-classpathscanningcandidatecomponentprovider/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Shaving a yak and where kaizen comes from</title>
		<link>http://blog.larsvonkconsultancy.nl/2008/12/shaving-a-yak-and-where-kaizen-comes-from/</link>
		<comments>http://blog.larsvonkconsultancy.nl/2008/12/shaving-a-yak-and-where-kaizen-comes-from/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 08:48:03 +0000</pubDate>
		<dc:creator>Lars Vonk</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[lean]]></category>
		<category><![CDATA[twi]]></category>

		<guid isPermaLink="false">http://lvonk.wordpress.com/?p=34</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.xebia.com/2008/04/10/dont-shave-that-yak/" onclick="pageTracker._trackPageview('/outgoing/blog.xebia.com/2008/04/10/dont-shave-that-yak/?referer=');">Yak shaving</a> can lead to useless work, but sometimes it can lead to very interesting facts&#8230; like finding out where <a href="http://en.wikipedia.org/wiki/Kaizen" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Kaizen?referer=');">Kaizen</a> comes from.<br />
<span id="more-34"></span><br />
My colleague Machiel Groeneveld asked my to review a paper he is writing on Lean. Amongst other things he mentiones Standard Work as a possible improvement on the current way we do Agile projects. Although Standard Work sounds pretty obvious I decided to google around and see what literature was available about this practice. (the first step in shaving the yak&#8230;)<br />
The google result led me to <a href="http://www.twisummit.com/Why%20Standard%20Work%20is%20not%20Standard.pdf" onclick="pageTracker._trackPageview('/outgoing/www.twisummit.com/Why_20Standard_20Work_20is_20not_20Standard.pdf?referer=');">this </a> paper from Jim Huntzinger about Standard Work. In that paper Training within Industry (TWI) is extensively discussed. I never heard of TWI but it took my attention and I decided to read more about it (step 2 in the yak shaving).<br />
According to wikipedia <a href="http://en.wikipedia.org/wiki/Training_Within_Industry" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Training_Within_Industry?referer=');">TWI</a> was introduced during WWII by the US Department of War. It consist of 4 programs (I suggest you read the above wikipedia link if you want all details of these programs):</p>
<p>- Job Instructions<br />
- Job Methods<br />
- Job Relations<br />
- Program Developement</p>
<p>Job Methods is the one that took my attention. Wikipedia states that Job Methods is</p>
<blockquote><p>
a course that taught workers to objectively evaluate the efficiency of their jobs and to methodically evaluate and suggest improvements. The course also worked with a job breakdown, but students were taught to analyze each step and determine if there were sufficient reason to continue to do it in that way by asking a series of pointed questions. If they determined some step could be done better by Eliminating, Combining, Rearranging, or Simplifying, they were to develop and apply the new method by selling it to the &#8220;boss&#8221; and co-workers, obtaining approval based on Safety, Quality, Quantity, and Cost, standardizing the new method, and giving &#8220;credit where credit is due.&#8221;
</p></blockquote>
<p>That sounds a lot like Kaizen doesn&#8217;t it? Although TWI was abandoned after the war in the US, its practices were well received and adapted by the Japanese and the Toyota Motor Corporation in particular.</p>
<p>If you want to read more about TWI and the apparent revival it is going through you can read all about it here: http://www.twi-institute.com/. Especially for the Agilist among us it sounds very familiar.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.larsvonkconsultancy.nl/2008/12/shaving-a-yak-and-where-kaizen-comes-from/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generating sql files in Maven using hibernate tools</title>
		<link>http://blog.larsvonkconsultancy.nl/2008/12/generating-sql-files-in-maven-using-hibernate-tools/</link>
		<comments>http://blog.larsvonkconsultancy.nl/2008/12/generating-sql-files-in-maven-using-hibernate-tools/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 21:42:01 +0000</pubDate>
		<dc:creator>Lars Vonk</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[hbm2ddl]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://lvonk.wordpress.com/?p=27</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Hibernate&#8217;s SessionFactory has some very powerful functions available like generating your tables from your hbm files using the <a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/configuration-optional.html" onclick="pageTracker._trackPageview('/outgoing/www.hibernate.org/hib_docs/v3/reference/en/html/configuration-optional.html?referer=');">hbm2ddl.auto</a> property. This is very handy for laptop testing where you can let hibernate generate your complete scheme on the fly.<br />
Although useful on your laptop, it is probably not want you want to do in a real environment. Luckily <a href="http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html_single/" onclick="pageTracker._trackPageview('/outgoing/docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html_single/?referer=');">hibernate tools</a> provides generating sql files via an Ant task. But if you are using Maven like me how can we integrate this in our build?</p>
<p><span id="more-27"></span></p>
<p>The answer is the <a href="http://maven.apache.org/plugins/maven-antrun-plugin/" onclick="pageTracker._trackPageview('/outgoing/maven.apache.org/plugins/maven-antrun-plugin/?referer=');">maven-antrun-plugin</a>. This plugin allows you to integrate ant tasks in Maven builds. To get the sql files we first create the Ant build.xml that will call the Ant task provided in the hibernate tools</p>
<pre class="brush: xml;">[/xml]
<project name="spark">
	<taskdef classname="org.hibernate.tool.ant.HibernateToolTask" name="hibernatetool" classpath="${test_classpath}" />

	<target name="generate-sql">

		<delete dir="${output_dir}" quiet="true"/>
		<mkdir dir="${output_dir}"/>
		<hibernatetool destdir="${output_dir}">

			<configuration propertyfile="${hibernate_testdir}/hibernate-for-sql-generation.properties">
			    <fileset dir="${hibernate_dir}">
			    	<include name="*.hbm.xml"/>
				</fileset>
			</configuration>
			<hbm2ddl export="false" outputfilename="create-tables.sql" />

		</hibernatetool>
	</target>
</project>
[xml]</pre>
</pre>
<p>In the above xml I declared the hibernatetool task via taskdef. Secondly, I created a target called <code>generate-sql</code> that I am going to call from the Maven build. The hibernatetool and hbm2ddl tasks are documented on the hibernate tools page, so checkout that if you need more info on how to configure.<br />
As you can see I am using <code>${}</code> properties. These are passed in from the Maven configuration. The file <code>hibernate-for-sql-generation.properties</code> contains the Dialect that Hibernate will use to generate the sql file.</p>
<p>Next is the relevant part of the pom.xml. Since I don't want to generate the sql each time I do a Maven build, I added it into a profile:</p>
<pre class="brush: xml;">[/xml]
<profile>
	<id>generate-sql</id>
	<build>
<plugins>
<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<version>1.3</version>
				<executions>
					<execution>
						<id>generate-sql</id>
<phase>compile</phase>
						<configuration>
							<tasks>
<property name="test_classpath" refid="maven.test.classpath" />
<property name="hibernate_dir" value="${basedir}/src/main/resources/hibernate" />
<property name="hibernate_testdir" value="${basedir}/src/test/resources" />
<property name="output_dir" value="${basedir}/target/database" />
								<ant antfile="${basedir}/build.xml">
									<target name="generate-sql" />
								</ant>
							</tasks>
								</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</profile>
[xml]</pre>
<p>The really interesting part starts from the <em>execution</em> tag. In here I tell the maven-antrun-plugin what to do. As you can see I pass in, amongst other things, the Maven test classpath. The classpath is needed by Ant to locate the <code>org.hibernate.tool.ant.HibernateToolTask</code>. Since I pass in the test classpath I added the hibernatetools jar as a dependency with scope test in the pom.xml.</p>
<p>When you now run <code>mvn compile -Pgenerate-sql </code> it will generate a sql file in the directory <code>target/database</code>. With some minor adjustments you are ready to use the generated file for creating your tables on all environments.</p>
<p>Lars</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.larsvonkconsultancy.nl/2008/12/generating-sql-files-in-maven-using-hibernate-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maven and Jetty: A Perfect fit</title>
		<link>http://blog.larsvonkconsultancy.nl/2008/11/maven-and-jetty-a-perfect-fi/</link>
		<comments>http://blog.larsvonkconsultancy.nl/2008/11/maven-and-jetty-a-perfect-fi/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 21:50:14 +0000</pubDate>
		<dc:creator>Lars Vonk</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://lvonk.wordpress.com/?p=5</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin" onclick="pageTracker._trackPageview('/outgoing/docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin?referer=');">jetty-maven-plugin</a> is a real life saver when it comes to developing web applications. In the past I had such horrible experiences with the eclipse WTP plugin that I banned it from my toolset forever.<br />
For a year now I use the jetty-maven-plugin and it makes developing so much easier. In this blog I will give an overview how you can setup your development environment using Maven and Jetty.<br />
<span id="more-5"></span><br />
When developing webapps on my local machine I set myself the following requirements:</p>
<p>1. I want to be able to edit classes and views (Wicket html files or jsp&#8217;s) and see the results in the browser fast without having to build a war file and manually redeploy.<br />
2. I want to be able to switch between an in memory database, typically a Hsqldb and the real target database (Oracle). Since I am using Hibernate as ORM I also need to be able to switch settings like the <i>hibernate.dialect</i> property to match my database.<br />
3. The WAR file produced should also run on the target application server, JBoss in my case.</p>
<p>Let&#8217;s see how Jetty fulfills these requirements.</p>
<p>The example project consist of a webapplication using Spring, Hibernate and Wicket. The target platform is JBoss with an Oracle database.</p>
<p>To get started we first need to add the jetty-maven-plugin in the pom.xml of the war project.</p>
<pre class="brush: xml;">[/xml]
<plugin>
  <artifactId>jetty-maven-plugin</artifactId>
	<groupId>org.mortbay.jetty</groupId>
	<version>7.0.0pre3</version>
	<configuration>
		<contextPath>/example-app</contextPath>
		<scanIntervalSeconds>3</scanIntervalSeconds>
		<connectors>
			<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8090</port>
				<host>0.0.0.0</host>
			</connector>
		</connectors>
	</configuration>
</plugin>
[xml]</pre>
<p>That&#8217;s it. When running <i>mvn jetty:run</i> the webapplication is available under http://localhost:8090/example-app. For a complete reference of all possible configuration settings I suggest you read <a href="http://jetty.mortbay.org/jetty/maven-plugin/run-mojo.html" onclick="pageTracker._trackPageview('/outgoing/jetty.mortbay.org/jetty/maven-plugin/run-mojo.html?referer=');">http://jetty.mortbay.org/jetty/maven-plugin/run-mojo.html</a></p>
<p><b>Fast redeploying.</b><br />
In my experience, I have no evidence, Jetty is the fastest starting servlet container out there, especially when you compare it with full blown application servers such as JBoss. JBoss is perfect for production and acceptance environments but when developing I have different needs. This is where Jetty gets a big plus.<br />
Regarding redeploying: By default the jetty-maven-plugin automatically reloads/redeploys the webapplication whenever it detects a change. You can use the <i>scanIntervalSeconds</i> and <i>scanTargets</i> configuration properties to tweak change detection. Downside of this automatic reloading is that it will always reload, even if you are just developing for a couple of minutes and save changes in between. Not only does this consume unnecessary resources, it will eventually lead to full PermGen space which results in an OOME.<br />
A way to counter this is to set the <a href="http://jetty.mortbay.org/jetty/maven-plugin/run-mojo.html#reload" onclick="pageTracker._trackPageview('/outgoing/jetty.mortbay.org/jetty/maven-plugin/run-mojo.html_reload?referer=');">reload</a> option of the jetty-maven-plugin to <i>manual</i>. Now reloading will only occur on a linefeed (hitting enter) in the console where you started jetty.</p>
<p><b>Switching databases</b><br />
When developing a webapplication I want to be flexible. I want to be able to connect to a fast in memory database, to the target database and to a database that is for instance on a test machine. How can we achieve this with jetty? In my case I have two local databases: a Hsql database and an Oracle database installed on a VMWare image.<br />
Since my Spring context uses a JNDI configured datasource I need to add those in Jetty as well. For this you need to create set the <i>jettyEnvXml</i> property in the jetty-maven-plugin. This property points to the jetty configuration file, called <a href="http://docs.codehaus.org/display/JETTY/jetty-env.xml" onclick="pageTracker._trackPageview('/outgoing/docs.codehaus.org/display/JETTY/jetty-env.xml?referer=');">jetty-env.xml</a>, containing the datasource in our case. But we also need to be able to switch hibernate dialect. Since we are using Spring we have the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html" onclick="pageTracker._trackPageview('/outgoing/static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html?referer=');"><i>PropertyPlaceHolderConfigurer</i></a> in our applicationContext in <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html#SYSTEM_PROPERTIES_MODE_OVERRIDE" onclick="pageTracker._trackPageview('/outgoing/static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html_SYSTEM_PROPERTIES_MODE_OVERRIDE?referer=');">SYSTEM_PROPERTIES_MODE_OVERRIDE</a> mode. This means that system properties override values defined in the applicationContext or the property file (if any). Together with Maven&#8217;s profiles we can now configure the jetty-maven-plugin so we can switch databases as needed.</p>
<p>The relevant parts of our pom now look like this:</p>
<pre class="brush: xml;">[/xml]
...
<plugin>
  <artifactId>jetty-maven-plugin</artifactId>
	<groupId>org.mortbay.jetty</groupId>
	<version>7.0.0pre3</version>
	<configuration>
		<contextPath>/example-app</contextPath>
		<reload>manual</reload>
                <jettyEnvXml>${jetty.env.file}</jettyEnvXml>
		<connectors>
			<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8090</port>
				<host>0.0.0.0</host>
			</connector>
		</connectors>
		<systemProperties>
			<systemProperty>
				<name>hibernate.dialect</name>
				<value>${hibernate.dialect}</value>
			</systemProperty>
		</systemProperties>
	</configuration>
</plugin>
...
<profiles>
<profile>
		<id>jetty-oracle</id>
<properties>
			<jetty.env.file>${basedir}/src/test/resources/jetty-env-oracle.xml</jetty.env.file>
			<hibernate.dialect>org.hibernate.dialect.Oracle10gDialect</hibernate.dialect>
		</properties>
	</profile>
<profile>
		<id>jetty-hsql</id>
<properties>
			<jetty.env.file>${basedir}/src/test/resources/jetty-env-hsqldb.xml</jetty.env.file>
			<hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
		</properties>
	</profile>
</profiles>
[xml]</pre>
<p>The contents of the jetty-env-hsqldb.xml is as follows:</p>
<pre class="brush: xml;">[/xml]
<?xml version="1.0"  encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="wac" class="org.mortbay.jetty.webapp.WebAppContext">
	<New id="example" class="org.mortbay.jetty.plus.naming.Resource">
		<Arg>jdbc/example</Arg>
		<Arg>
			<New class="org.apache.commons.dbcp.BasicDataSource">
				<Set name="driverClassName">org.hsqldb.jdbcDriver</Set>
				<Set name="url">jdbc:hsqldb:mem:test</Set>
				<Set name="username">sa</Set>
				<Set name="password"></Set>
			</New>
		</Arg>
	</New>
</Configure>
[xml]</pre>
<p>Via this configuration we are able to switch between Oracle and Hsqldb by specifying the profile at the commandline. For example <i>mvn jetty:run -Pjetty-hsql</i> in case we want the Hsqldb.</p>
<p><b>Servlet container compatibility</b><br />
We are almost there. As said before, the example application is using a JNDI configured datasource and refers to it in the applicationContext using a jee:jndi lookup:</p>
<pre class="brush: xml;">[/xml]
<jee:jndi-lookup id="exampleDataSource" jndi-name="java:comp/env/jdbc/example"/>
[xml]</pre>
<p>When deploying the produced WAR file in JBoss it gives an error saying that <i>jdbc is not bound<i>. To get the application up and running in JBoss as well you to follow the steps as described in <a href="http://forums.sun.com/thread.jspa?threadID=626778" onclick="pageTracker._trackPageview('/outgoing/forums.sun.com/thread.jspa?threadID=626778&amp;referer=');">http://forums.sun.com/thread.jspa?threadID=626778</a>. This is caused by the fact that not all servlet containers have the same way of registering jndi values.</p>
<p><b>Conclusion</b><br />
Jetty and Maven go well together. The jetty-maven-plugin provides an easy way to use Jetty in development and enough flexibility to switch for instance databases when developing. I gihly recommend using the jetty-maven-plugin when developing. But make sure you check that the WAR file also runs on your target application server on a daily basis.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.larsvonkconsultancy.nl/2008/11/maven-and-jetty-a-perfect-fi/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
