<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2titles.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemtitles.css"?><rss 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/" version="2.0">

<channel>
	<title>Raptor - Agile java consultants</title>
	
	<link>http://www.raptorconsultants.com</link>
	<description>Spring, Webflow, CAS and all other Java stuff</description>
	<lastBuildDate>Sat, 25 Feb 2012 13:12:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/raptor-spring" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="raptor-spring" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">raptor-spring</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://feeds.feedburner.com/raptor-spring" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2Fraptor-spring" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
		<title>Distributed agile teams</title>
		<link>http://www.raptorconsultants.com/agile/distributed-teams/</link>
		<comments>http://www.raptorconsultants.com/agile/distributed-teams/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 15:32:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://www.raptorconsultants.com/?p=311</guid>
		<description><![CDATA[For some years we've been using business partners who are located offsite, often in different countries and timezones however our own development teams have always been based together. This is now changing ...]]></description>
			<content:encoded><![CDATA[<p>For some years we&#8217;ve been using business partners who are located offsite, often in different countries and timezones however our own development teams have always been based together. This is now changing &#8230;</p>
<p>For the past few months we&#8217;ve been working with scrum teams who are based in the UK, the US, Eastern Europe and Latin America. In general it&#8217;s been a great success but we have certainly learnt things along the way and I thought it would be useful to share these experiences. We used Martin Fowler&#8217;s <a class="blue_link" href="http://martinfowler.com/articles/agileOffshore.html">model </a>as a starting point for our own system and this proved to be very effective. We adopted pretty much all of Martin&#8217;s recommendations and I would highly recommend his article to anyone looking to implement their own distributed agile model.</p>
<p>Firstly let&#8217;s look at our logical team structure:</p>
<p><a rel="attachment wp-att-313" href="http://www.raptorconsultants.com/agile/distributed-teams/attachment/team_structure/"><img class="aligncenter size-medium wp-image-313" title="Logical team structure" src="http://www.raptorconsultants.com/wp-content/uploads/2011/03/team_structure-590x308.png" alt="Logical team structure diagram" width="590" height="308" /></a></p>
<p>As can be seen, we use functional teams with component guardians providing the technical oversight of the application tiers. From a geographic perspective we have product owners based in the UK and US, architects and scrum masters based in the UK, US, Argentina and Estonia and scrum teams in the UK, Argentina and Estonia. Support elements are largely based in the UK and US.</p>
<p>We spent a fair amount of time working out the best geographic team distribution but in the end we came to one conclusion:</p>
<p><strong style="color:black">Timezone is the most important factor, everything else can be overcome</strong></p>
<p>As a refinement of that broad statement we can say that product owners and scrum masters must be in the same timezone as their respective scrum teams, however none of them need to be situated in the same physical office. This gave us a logical structure &#8211; UK based product owners would work with scrum teams in Estonia (only a 2 hour difference) and US product owners would work with teams in Argentina (again only a 2 hour difference). We then had to decide whether to situate scrum masters with the scrum teams or with the product owner. On balance we found it better to situate them with the product owner because technical people were able to collaborate online easier than non-technical people.</p>
<h3>Make full use of online tools</h3>
<p>Technology has evolved so much over the past years that it&#8217;s now possible to do pretty much everything online in a collaborate environment. Some specific tools that are worthy of mention include:</p>
<p><a class="blue_link" href="http://www.skype.com">Skype</a> &#8211; Probably the most useful tool we use, being able to talk to people face to face has really revolutionized the way we work. Skype has also allowed us to build a social community across borders &#8230; we can point the webcam out of the window to show other team members the horrible weather, or the not so horrible girl walking outside.</p>
<p><a class="blue_link" href="http://www.atlassian.com">Atlassian tools</a> &#8211; We&#8217;ve used JIRA for some time but we&#8217;ve recently adopted the other Atlassian tools (Greenhopper, Confluence, Fisheye, Crucible) &#8211; There was certainly a learning curve, especially for Greenhopper which does not directly map to scrum in the way VersionOne does for example. It was worth the effort though because we now keep everything online. I was never a great fan of post it notes (being a tidy person) but Greenhopper seems to give us the same flexibility with more control</p>
<p><a class="blue_link" href="http://www.gotomeeting.com">GoToMeeting/Webex </a>- Being able to share a screen proved useful for technical and non-technical people. The product owners were able to illustrate things whilst the technies could adopt a pseudo pair-programming approach &#8211; they would share their computers and ask someone else to look at a problem they were facing.</p>
<p><a class="blue_link" href="http://aws.amazon.com">Amazon web services</a> &#8211; One challenge we faced was where to situate our development and test servers, how could we offer a small team in Argentina the same infrastructure as our much larger UK team? The solution was to allow teams (even individual developers) to spin up servers as and when needed.  AWS allowed us to offer a full performance test infrastructure to every team involved in the project.  It also helped to overcome the head office/regional office mentality in which developers in the head office can get &#8220;special treatment&#8221; from the engineering guys who are based alongside them.</p>
<h3>What else did we learn?</h3>
<ul class="multi_line_bullets">
<li>Don&#8217;t rely on email &#8211; It&#8217;s very easy to slip into long email threads which become unmanageable, we also found that people were hesitant to ask questions which they thought may have been answered in a previous email. They would spend 15 minutes searching through their email history and if they did find the answer it was often out of date.  Much better to ping someone on IM &#8220;can I ask you someting?&#8221; then call them using Skype</li>
<li>Watch IM &#8211; chat can be addictive but in our experience it&#8217;s not as effective as a call &#8230; most people can talk quicker than they type and IM is inherently asynchronous &#8211; you can&#8217;t interrupt someone when all you see is &#8220;Dave is typing &#8230;&#8221;</li>
<li>Share your screen, don&#8217;t check in bad code &#8211; Developers were often tempted to check in unfinished code so they could share it with their colleagues. Although source control should be used for collaboration it&#8217;s not a dumping ground.  Screen sharing was the answer</li>
<li>Keep an online calendar showing key dates including public holidays &#8211; Initially we were caught out when a guy in the US would sit waiting on information from someone in Argentina, not realizing it was a public holiday. Google calendar works well for this purpose</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.raptorconsultants.com/agile/distributed-teams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TestNG vs JUnit</title>
		<link>http://www.raptorconsultants.com/uncategorized/testng-junit/</link>
		<comments>http://www.raptorconsultants.com/uncategorized/testng-junit/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 17:38:49 +0000</pubDate>
		<dc:creator>Raptor Team</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[testng]]></category>

		<guid isPermaLink="false">http://www.raptorconsultants.com/?p=260</guid>
		<description><![CDATA[For years JUNit was the dominant player in the unit testing world, it could be described as the father of Unit testing frameworks as other frameworks like NUnit and PHPUnit were based on it. Most of us cut our testing teeth on it but is there a better alternative available today? We believe there is. [...]]]></description>
			<content:encoded><![CDATA[<p>For years JUNit was the dominant player in the unit testing world, it  could be described as the father of Unit testing frameworks as other  frameworks like NUnit and PHPUnit were based on it. Most of us cut our  testing teeth on it but is there a better alternative available today?  We believe there is.</p>
<p>TestNG (the NG stands for Next Generation) offers the same  features as JUnit but also offers some significant enhancements that are  lacking in JUnit. A detailed comparison of the two frameworks can be  found in this excellent blog <a href="http://www.mkyong.com/unittest/junit-4-vs-testng-comparison">post</a>. In our experience the most usable features of TestNG are test groups, parametrized testing and thread support. </p>
<h3>Test Groups</h3>
<p>Take this scenario &#8230; we have a  traditional multi tiered web application with anaemic domain classes and  stateless services. Having changed a service we want to run our unit  tests but we don&#8217;t necessarily want to run all our domain tests because  the domain classes should not be affected by a change in the service  tier. We could create two test suites, one for the service tests and one  for the domain tests but TestNG offers us test groups, basically tags  that we can assign to individual tests (not just test classes).</p>
<pre class="brush: java; title: ; notranslate">
@Test(groups = &quot;service&quot;)
public void testMyCode() { ... }
</pre>
<p>We can then tell maven to execute tests with a particular tag &#8230;</p>
<pre class="brush: xml; title: ; notranslate">
 &lt;plugin&gt;
 &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
 &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
 &lt;configuration&gt;
 &lt;groups&gt;${groups}&lt;/groups&gt;
 &lt;/configuration&gt;
 &lt;/plugin&gt;
</pre>
<p>$mvn -Dgroups=&#8221;service&#8221;</p>
<p>The TestNG ecliupse plugin also offers a simple way of executing tests with a particular tag:</p>
<h3>Paramaterized testing</h3>
<p>Writing  good unit tests is only half the battle, maintaining them is equally  challenging. One way to reduce the amount of boilerplate code is to  write paramaterized tests. JUnit offers paramaterized support but it&#8217;s  not clean. We need to create a static method which returns a collection  of paramaters, create instance variables to hold the current paramaters,  then implement a constructor which ties the static method and the  instance variables together:</p>
<pre class="brush: java; title: ; notranslate">
@RunWith(value = Parameterized.class)
public class JunitTest6 {

 private int number;

 public JunitTest6(int number) {
 this.number = number;
 }

 @Parameters
 public static Collection&lt;Object[]&gt; data() {
 Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } };
 return Arrays.asList(data);
 }

 @Test
 public void pushTest() {
 System.out.println(&quot;Parameterized Number is : &quot; + number);
 }
}
</pre>
<p>In contrast TestNG&#8217;s approach is much cleaner:</p>
<pre class="brush: java; title: ; notranslate">
public class TestNGTest {

 @DataProvider(&quot;numbers&quot;)
 public Object[][] getNumbers() {
 Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } };
 return data;
 }

 @Test(dataProvider=&quot;numbers&quot;)
 public void pushTest(int number) {
 System.out.println(&quot;Parameterized Number is : &quot; + number);
 }
}
</pre>
<p>The distinction between JUnit and TestNG becomes even more apparent when we need to support multiple groups of paramaters:</p>
<pre class="brush: java; title: ; notranslate">
public class TestNGTest {

 @DataProvider(&quot;numbers&quot;)
 public Object[][] getNumbers() {
 Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } };
 return data;
 }

 @DataProvider(&quot;names&quot;)
 public Object[][] getNames(){
 Object[][] data = new Object[][] { { &quot;fred&quot; }, { &quot;harry&quot; }, { &quot;bob&quot; }, { &quot;alice&quot; } };
 return data;
 }

 @Test(dataProvider=&quot;numbers&quot;)
 public void pushNumers(int number) {
 System.out.println(&quot;Parameterized Number is : &quot; + number);
 }

 @Test(dataProvider=&quot;names&quot;)
 public void pushStrings(String name) {
 System.out.println(&quot;Parameterized name is : &quot; + name);
 }

}
</pre>
<p>JUnit&#8217;s big limitation is that it only support a single dataprovider method which must set up all parameters for all tests.</p>
<h3>XML Driven paramaters</h3>
<p>TestNG also allows us to specify our parameters in an XML file which is often more readable:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE suite SYSTEM &quot;&lt;a href=&quot;http://beust.com/testng/testng-1.0.dtd&quot; target=&quot;_blank&quot;&gt;http://beust.com/testng/testng-1.0.dtd&lt;/a&gt;&quot; &gt;
 &lt;suite name=&quot;a&quot;&gt;
 &lt;test name=&quot;testing&quot;&gt;

 &lt;parameter name=&quot;numbers&quot; value=&quot;1&quot;/&gt;
 &lt;parameter name=&quot;numbers&quot; value=&quot;2&quot;/&gt;
 &lt;parameter name=&quot;numbers&quot; value=&quot;3&quot;/&gt;

 &lt;classes&gt;
 &lt;class name=&quot;com.fsecure.demo.testng.TestNGTest6_0&quot; /&gt;
 &lt;/classes&gt;

 &lt;/test&gt;
 &lt;/suite&gt;
</pre>
<pre class="brush: java; title: ; notranslate">
 @Test(dataProvider=&quot;numbers&quot;)
 public void pushTest(int number) {
 System.out.println(&quot;Parameterized Number is : &quot; + number);
 }
</pre>
<h3>Testing threads</h3>
<p>Anyone who has written a high performance application will have dealt with threads and thread pools. Some libraries (e.g. Spring Security) use threads behind the scenes. Our code may well run under a single thread of execution but what happens when it&#8217;s being hit by 10 concurrent threads? </p>
<p>Let&#8217;s take some naive code:</p>
<pre class="brush: java; title: ; notranslate">
package com.test;

public class NaiveClass {

	private int value = 0;

	public void increment(int amount) {
		value += amount;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

}
</pre>
<p>And our JUnit test:</p>
<pre class="brush: java; title: ; notranslate">
package com.test;

import static org.junit.Assert.*;
import java.util.Random;

import org.junit.Before;
import org.junit.Test;

public class TestNaiveClass {

	private NaiveClass classUnderTest;
	private Random generator;

	@Before
	public void setup() {
		classUnderTest = new NaiveClass();
		generator = new Random();
	}

	@Test
	public void testNaiveClass() {
		int startValue = generator.nextInt(100);
		int incrementValue = generator.nextInt(100);
		classUnderTest.setValue(startValue);
		classUnderTest.increment(incrementValue);
		int expected = startValue + incrementValue;
		assertEquals(expected, classUnderTest.getValue());
	}
}
</pre>
<p>and the result &#8230;</p>
<p><a href="http://www.raptorconsultants.com/uncategorized/testng-junit/attachment/testnaiveclass/" rel="attachment wp-att-276"><img src="http://www.raptorconsultants.com/wp-content/uploads/2010/08/testNaiveClass.jpg" alt="" title="Test results" width="318" height="195" class="aligncenter size-full wp-image-276" /></a></p>
<p>We know our code is flaky but no matter how many times we run the test it will always pass &#8230; not good!</p>
<p>Of course our test runs in a single thread so we can&#8217;t test thread safety. We need to fire off multiple threads:</p>
<pre class="brush: java; title: ; notranslate">
package com.test;

import static org.junit.Assert.assertEquals;

import java.util.Random;

import org.junit.Test;

public class TestNaiveClassThreaded {

	private final NaiveClass classUnderTest = new NaiveClass();
	private final Random generator = new Random();

	@Test
	public void testNaiveClass() {
		for (int i=0; i&lt;100; i++) {
			ThreadedTest threadTest = new ThreadedTest();
			Thread t = new Thread(threadTest);
			t.start();
		}
	}

	class ThreadedTest implements Runnable {

		@Override
		public void run() {
			try {
				int startValue = generator.nextInt(100);
				int incrementValue = generator.nextInt(100);
				classUnderTest.setValue(startValue);
				Thread.sleep(100);
				classUnderTest.increment(incrementValue);
				int expected = startValue + incrementValue;
				assertEquals(expected, classUnderTest.getValue());
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
		}

	}
}
</pre>
<p>This should fail &#8230;</p>
<p><a href="http://www.raptorconsultants.com/uncategorized/testng-junit/attachment/testthreaded/" rel="attachment wp-att-279"><img src="http://www.raptorconsultants.com/wp-content/uploads/2010/08/testThreaded.jpg" alt="This test should fail ... what&#039;s wrong?" title="Test results" width="319" height="165" class="aligncenter size-full wp-image-279" /></a></p>
<p>Our test still passes! Something strange is happening here &#8230; the threads should sleep for 10 seconds but our test passes immediately. The problem lies with JUnit&#8217;s TestRunner which doesn&#8217;t support threads &#8230; it fires off threads then returns immediately. We can easily prove this:</p>
<pre class="brush: java; title: ; notranslate">
package com.test;

import static org.junit.Assert.fail;

import org.junit.Test;

public class TestFail {

	@Test
	public void testNaiveClass() {
		for (int i=0; i&lt;100; i++) {
			ThreadedTest threadTest = new ThreadedTest();
			Thread t = new Thread(threadTest);
			t.start();
		}
	}

	class ThreadedTest implements Runnable {

		@Override
		public void run() {
			fail();
		}

	}
}
</pre>
<p>This test always passes!</p>
<h3>TestNG supports threads</h3>
<p>In contrast TestNG offers explicit support for threads. We can easily verify that our NaiveClass isn&#8217;t thread safe by writing a simple test:</p>
<pre class="brush: java; title: ; notranslate">
package com.test;

import static org.testng.Assert.assertEquals;

import java.util.Random;

import org.testng.annotations.Test;

public class TestNaiveClassTestNG {

	private final NaiveClass classUnderTest = new NaiveClass();
	private final Random generator = new Random();

	@Test(threadPoolSize=10, invocationCount=100)
	public void testNaiveClass() throws Exception {
		int startValue = generator.nextInt(100);
		int incrementValue = generator.nextInt(100);
		classUnderTest.setValue(startValue);
		Thread.sleep(10);
		classUnderTest.increment(incrementValue);
		int expected = startValue + incrementValue;
		assertEquals(classUnderTest.getValue(), expected);
	}
}
</pre>
<p>TestNG will create 10 threads and execute the test 100 times. As we can see the test fails because multiple threads are modifying the instance variable &#8230;</p>
<p><a href="http://www.raptorconsultants.com/uncategorized/testng-junit/attachment/testng/" rel="attachment wp-att-280"><img src="http://www.raptorconsultants.com/wp-content/uploads/2010/08/TestNG.jpg" alt="TestNG allows us to test if our code is thread safe" title="TestNG Test Results" width="323" height="352" class="aligncenter size-full wp-image-280" /></a></p>
<h3>Conclusion</h3>
<p>We believe TestNG offers some significant enhancements over JUnit and from what we have seen there are no drawbacks &#8230; it really is the Next Generation testing framework!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raptorconsultants.com/uncategorized/testng-junit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Free presentation – private clouds for agile teams</title>
		<link>http://www.raptorconsultants.com/cloud/private-clouds-for-agile-teams/</link>
		<comments>http://www.raptorconsultants.com/cloud/private-clouds-for-agile-teams/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 10:19:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cloud]]></category>

		<guid isPermaLink="false">http://www.raptorconsultants.com/?p=243</guid>
		<description><![CDATA[On the 29th July Toby Hobson will be delivering a free presentation on private clouds and how they can be employed to dramatically improve the productivity of agile development teams]]></description>
			<content:encoded><![CDATA[<p>On 29th July Toby Hobson will be delivering a free presentation on private clouds at the <a href="http://skillsmatter.com/" style="color:blue">Skillsmatter </a>exchange in London:</p>
<p>Cloud technology has been around for some time but it’s generally been confined to large public clouds like Amazon and Google app engine. The world is changing &#8230; organizations are now starting to build their own clouds to support their agile teams.</p>
<p>In this talk Toby Hobson will give an overview of cloud technology before exploring the benefits and pitfalls of private cloud technology for agile development teams. The talk will conclude with a comparison of the commercial and open source technologies on the market today. Topics addressed will include:</p>
<ul class="bullets">
<li>Why infrastructure is the Achilles heel of agile development</li>
<li>How clouds can empower development teams</li>
<li>Development teams as customers</li>
<li>Current trends</li>
<li>Dealing with legacy systems</li>
</ul>
<p>Technologies covered will include:</p>
<p>XEN, KVM, VM Ware, Eucalyptus/Ubuntu Enterprise cloud, 3Tera and OpenQRM along with an overview of Amazon&#8217;s private cloud offering</p>
<p>More information can be found on the Skillsmatter <a href="http://skillsmatter.com/event/agile-scrum/private-clouds-for-agile-teams" style="color:blue">site</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.raptorconsultants.com/cloud/private-clouds-for-agile-teams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rapid development with JRebel</title>
		<link>http://www.raptorconsultants.com/uncategorized/jrebel/</link>
		<comments>http://www.raptorconsultants.com/uncategorized/jrebel/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 13:18:57 +0000</pubDate>
		<dc:creator>Raptor Team</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.raptorconsultants.com/?p=193</guid>
		<description><![CDATA[We&#8217;re big fans of Zero Turnaround&#8217;s JRebel product and we thought we should tell you all about it. We&#8217;re not in any way affiliated with the vendor, we&#8217;re just happy users. For those of you who don&#8217;t know about JRebel it&#8217;s a JVM agent that allows developers to change code on the fly without needing [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re big fans of Zero Turnaround&#8217;s <a href="http://www.zeroturnaround.com/jrebel/">JRebel</a> product and we thought we should tell you all about it. We&#8217;re not in any way affiliated with the vendor, we&#8217;re just happy users.</p>
<p>For those of you who don&#8217;t know about JRebel it&#8217;s a JVM agent that allows developers to change code on the fly without needing to rebuild and redeploy their apps. Sounds like hotswap? well actually it&#8217;s much more advanced than traditional jvm hot swap because it allows you to modify the structure of classes on the fly so you can add and remove methods, fields etc. It also has some neat plugins like the spring plugin which lets us add beans on the fly (hot swap definitely won&#8217;t let you do that!)</p>
<p>We&#8217;ve found that fast turnaround really helps us to improve the quality of our code. Take this scenario &#8230; you want to test a small change (e.g. adding a field to a JSP) but every time you change something it take 2 mins for your app to start up. What happens? you don&#8217;t make and test changes in isolation because it&#8217;s too painful so you end up changing lots of stuff and hope it all works!</p>
<p>The tool not only allows us to be more productive, it also brings a little bit of happiness into our day &#8230; there&#8217;s nothing more frustrating that waiting for your app server to restart.</p>
<p>Give it a go &#8230; you may be surprised!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raptorconsultants.com/uncategorized/jrebel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Grails vs Roo</title>
		<link>http://www.raptorconsultants.com/spring/grails-vs-roo/</link>
		<comments>http://www.raptorconsultants.com/spring/grails-vs-roo/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 14:59:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[roo]]></category>

		<guid isPermaLink="false">http://www.raptorconsultants.com/?p=159</guid>
		<description><![CDATA[We're great fans of Grails so we were excited when we heard about Roo but how do the two stack up against each other?]]></description>
			<content:encoded><![CDATA[<p>We’re great fans of Grails so we were very excited when we heard about Roo. Both frameworks promise rapid application development but Roo claims to have no runtime overhead. Can it live up to the hype?</p>
<p>Whilst Grails and Roo both aim to simplify the developer’s life they approach it in different ways. Grails is built on top of groovy and adds a lot of “magic” at runtime whereas Roo is essentially a code generation utility.</p>
<h3>Performance</h3>
<p>The benefit of compile time code generation is of course performance. A Roo powered application will almost always be faster than a Grails powered app but the performance “hit” associated with Grails is not as great as people sometimes think.</p>
<p>When we have run into performance problems in Grails the bottleneck in invariably a couple of methods or closures which perform computationally expensive calculations. Groovy implicitly uses BigIntegers for division which imposes a big performance hit. Extracting such calculations to static java methods which use floats often speeds up execution time by as much as 90%. Another area where Grails performance is lacking is the rendering engine behind the GSPs and specifically the way tag libraries are used. Switching to another rendering engine can significantly improve performance.</p>
<p>Both Roo and Grails can be tweaked to improve performance without making changes to the code base. Judicious use of caching and transaction management will give significant performance increases for both platforms. The use of transactions is especially significant for grails apps because by default grails will try to create a transaction for every request which is far from ideal.</p>
<p>So in summary out of the box grails is considerably slower than a Roo powered app but with a bit of tweaking we have found that grails apps can come very close to &#8220;traditional&#8221; java ones and certainly acceptable for all but the most demanding of applications.</p>
<h3>Skills</h3>
<p>To make the best use of Grails a developer must have a good grasp of Groovy whereas Roo is pure java so there is no need to learn another language. This shouldn’t be underestimated, I believe that any experienced Spring developer will have no trouble learning Groovy &#8230; the question is do you have the time to learn Groovy. Top developers are in high demand and getting time off to study something new is often easier said than done!</p>
<p>Grails and groovy is not hard but to become proficient you do need to spend a fair amount of time with real world examples. If you are a java developer and you have the chance to work on a grails project I would say jump at it &#8230; you’ll love it!</p>
<p>In contract a competent java developer can be up to speed and developing productive Roo apps in days. The code that is generated will look familiar and you’ll feel confident to experiment to get the best results. Roo is also ideally suited to more junior developers who may not be comfortable with some of the more “esoteric” features of groovy and grails but just want a framework that will save them a bit of time.</p>
<h3>Availability of libraries/plugins</h3>
<p>Roo is built on top of Maven so dependency management is a breeze and there is an extensive library of code available. In contrast grails relies on plugins which have a limited availablity. Grails can be used with Maven but it&#8217;s a painful experience and not something we would recommend. This is an area where Roo wins hands down. Ide support for grails projects is also lacking, even Spring own ide (STS) doesn&#8217;t have a specific groovy editor and debugging a grails application is not for the faint hearted. Grails generates a lot of code at runtime so the code you see in your debugger bears little relation to the code actually running. This can be a major headache but careful use of breakpoints and logging statements can ease the pain somewhat.</p>
<h3>Maintenance</h3>
<p>We’re not big fans of code generation tools, my own view is that if you find yourself writing or generating a lot of boilerplate code and config there is something wrong with the structure of your application. The core spring framework has been moving towards convention over configuration in recent releases, annotation driven controllers are the best example of this. Roo builds on this but it’s nowhere near Grails in terms of ease of maintenance. We are still amazed at just how little code we need to write to deliver a fully functional Grails powered app.</p>
<p>We have not yet developed and maintained any production grade Roo apps but my guess is that it could actually act as an impediment to the long term success of the project. I say this because I suspect developers who may be under pressure with tight deadlines will tend to rely on the code generation rather than thinking how they can structure the application to minimize code duplication.</p>
<h3>Conclusion</h3>
<p>Grails and Roo are both great frameworks. The framework you choose will depend on your need for performance vs maintainability but ultimately I think the big factor will the level of skills in your team. An advanced developer will be able to develop amazing Grails apps that are far more maintainable than those developed using Roo. Junior developers will be able to develop a basic grails app but the moment you hit performance or threading issues you’ll need to climb quite a high wall. Roo can be used by developers of all levels to boost their productivity.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raptorconsultants.com/spring/grails-vs-roo/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Custom spring authorization</title>
		<link>http://www.raptorconsultants.com/spring/authorization-2/</link>
		<comments>http://www.raptorconsultants.com/spring/authorization-2/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 17:42:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[authorization]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.raptorconsultants.com/?p=89</guid>
		<description><![CDATA[Explains how to go beyond Spring's standard role based authorization to control access based on IP address, time of the day or anything!]]></description>
			<content:encoded><![CDATA[<p>Spring security is immensely powerful and flexible but it can seem a bit daunting to those who are new to the framework. Version 2.0 simplified things greatly by introducing the security namespace and RoR style convention over configuration however there is a downside to this simplification &#8230; the framework creates and configures many beans behind the scenes and it’s not immediately obvious how to change the default behavior. In this short post I will explain how Spring’s authorization mechanism works behind the scenes.</p>
<p>The  most basic spring security configuration looks something like this:</p>
<pre class="brush: xml; title: ; notranslate">&lt;http auto-config='true'&gt;
  &lt;intercept-url pattern=&quot;/**&quot; access=&quot;ROLE_USER&quot; /&gt;
&lt;/http&gt;
</pre>
<p>This configuration tells spring to restrict access to the application to  only those users who have the role of “ROLE_USER”. Behind the scenes  spring creates and wires up several beans that all play a role in the  authorization process. I&#8217;m going to assume that we are protecting web urls (known as FilterInvocation&#8217;s in Spring) but I&#8217;ll cover method level security in a later post</p>
<p>Before we start let&#8217;s have a look at the key collaborators involved in spring authorization:</p>
<p style="text-align: left;"><a href="http://www.raptorconsultants.com/wp-content/uploads/2010/06/spring-authorization.png"><img class="aligncenter size-medium wp-image-103" title="spring authorization" src="http://www.raptorconsultants.com/wp-content/uploads/2010/06/spring-authorization-590x215.png" alt="" width="590" height="215" /></a></p>
<h3>DelegatingFilterProxy</h3>
<p style="text-align: left;">You will most likely have defined and mapped an instance of the DelegatingFilterProxy in your web.xml. This proxy allows Spring to create a number of filters needed for authentication and authorization. One such filter which is relevant to url authorization is the FilterSecurityInterceptor</p>
<h3>FilterSecurityInterceptor</h3>
<p style="text-align: left;">This is the primary entry point for url authorization, it intercepts requests and passes control to the AccessDecisionManager</p>
<h3>AccessDecisionManager (Interface)</h3>
<p style="text-align: left;">This is the primary interface responsible for Authorization. As the name implies Implementors are responsible for deciding whether to grant or deny access to a particular resource (known as a secure object in Spring). In the context of web based url security the secure object will be an instance of the FilterInvocation class. AccessDecisionManager’s key method is</p>
<pre class="brush: java; title: ; notranslate">void decide(Authentication authentication, Object secureObject,
 ConfigAttributeDefinition config)
 throws AccessDeniedException, InsufficientAuthenticationException</pre>
<p>The authentication represents the principle (or “user”) accessing the system, the secureObject will be an instance of FilterInvocation. The config is basically a collection of name/value pairs that are passed to the class if they are needed.</p>
<p>Out of the box spring will create an instance of the AccessDecisionManager which supports role based authorization. We can write our own implementation if we need some custom behavior. Lets say we want to restrict access to admin user&#8217;s with particular IP addresses:</p>
<pre class="brush: java; title: ; notranslate">package com.test.security;

import java.util.Collection;

import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.authentication.InsufficientAuthenticationException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.FilterInvocation;

public class NaiveAccessDecisionManager implements AccessDecisionManager {

 public void decide(Authentication authentication, Object secureObject,
     Collection attributes) throws AccessDeniedException,
     InsufficientAuthenticationException {

   // The supports method ensures we are dealing with FilterInvocations
   //  so we can safely cast the secure object
   FilterInvocation invocation = (FilterInvocation) secureObject;
   WebAuthenticationDetails requestDetails = (WebAuthenticationDetails) authentication.getDetails();

   if (&quot;/secret.do&quot;.equals(invocation.getRequestUrl())) {
     boolean authorized = false;

     // only allow access if the user has the admin role a
     // and is within the correct IP range
     for (GrantedAuthority authority : authentication.getAuthorities()) {
       if (&quot;ROLE_ADMIN&quot;.equals(authority.getAuthority()) &amp;&amp; requestDetails.getRemoteAddress().startsWith(&quot;192.168.0&quot;)) {
         authorized = true;
       }
     }

     if (!authorized) {
       throw new AccessDeniedException(&quot;go away&quot;);
     }
   }
 }

 public boolean supports(Class clazz) {
   // This manager should be used for FilterInvocations (authorizing web
   // requests)
   return FilterInvocation.class.isAssignableFrom(clazz);
 }

 public boolean supports(ConfigAttribute config) {
   return true;
 }

}</pre>
<p>We now need to tell spring to use our manager:</p>
<pre class="brush: xml; title: ; notranslate">&lt;bean:bean id=&quot;naiveAccessDecisionManager&quot; class=&quot;com.test.security.NaiveAccessDecisionManager&quot; /&gt;
&lt;pre&gt;&lt;pre&gt;
&lt;http auto-config=&quot;true&quot; access-decision-manager-ref=&quot;naiveAccessDecisionManager&quot;&gt;
 &lt;!-- no need for interceptor element here because our accessDecisionManager has this hard coded --&gt;
&lt;/http&gt;</pre>
<p>That would work but it&#8217;s not very nice.  For one thing we&#8217;re reimplementing spring&#8217;s role based access control which doesn&#8217;t make sense. It can also become messy if we have conditional logic</p>
<p>To simplify things Spring offers us the concept of &#8220;voters&#8221; which are polled by an AccessDecisionManager.</p>
<h3>AccessDecisionVoter (interface)</h3>
<p>Let&#8217;s have a quick look at the key method in the AccessDecisionVoter interface:</p>
<pre class="brush: java; title: ; notranslate">int vote(Authentication authentication, Object secureObject, ConfigAttributeDefinition config);</pre>
<p>Voter&#8217;s can be chained together by an AccessDecisionManager to build complex authorization strategies. The way an AccessDecisionManager handles &#8220;votes&#8221; depends on it&#8217;s type; the Unanimous AccessDecisionManager requires all voters to say yes before allowing access. In contrast the Affirmative AccessDecisionManager just needs any one of the voters to say yes. Spring offers several concrete implementations of the AccessDecisionVoter, the most common of which is the RoleVoter.</p>
<h3>A real world example</h3>
<p>We recently did some work for a media company whose licensing and rights policy meant that they could only display content to users in the UK. We chose to implement a custom voter which would try to geolocate the visitors IP address and allow access if it was reported as being UK based:</p>
<pre class="brush: java; title: ; notranslate">
package com.x;

public class IPVoter implements AccessDecisionVoter {

  public int vote(Authentication authentication, Object secureObject, Collection&lt;ConfigAttribute&gt; attributes) {

    if (authentication.getDetails() == null) {
      return AccessDecisionVoter.ACCESS_DENIED;
    }

    WebAuthenticationDetails details = (WebAuthenticationDetails) authentication.getDetails();
    String remoteIPAddress = details.getRemoteAddress();
    if (StringUtils.isBlank(remoteIPAddress)) {
      return AccessDecisionVoter.ACCESS_DENIED;
    }

    // checks the IP address using Quova
    return validateIPAddress(remoteIPAddress);
  }

  public boolean supports(ConfigAttribute att) {
    return true;
  }

  public boolean supports(Class clazz) {
    return FilterInvocation.class.isAssignableFrom(clazz);
  }
}</pre>
<p>We then needed to wire up our new voter along with Spring&#8217;s RoleVoter:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;bean id=&quot;accessDecisionManager&quot; class=&quot;org.springframework.security.vote.UnanimousBased&quot;&gt;
  &lt;property name=&quot;decisionVoters&quot;&gt;
    &lt;list&gt;
      &lt;bean class=&quot;org.springframework.security.vote.RoleVoter&quot; /&gt;
      &lt;bean class=&quot;com.x.ipVoter&quot;&gt;
        &lt;property name=&quot;quova&quot; ref=&quot;quova&quot; /&gt;
      &lt;/bean&gt;
    &lt;/list&gt;
&lt;/bean&gt;

&lt;security:http access-decision-manager-ref=&quot;accessDecisionManager&quot;&gt;
...
&lt;/security&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.raptorconsultants.com/spring/authorization-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic page generated in 0.364 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-02-25 14:46:18 -->

