<?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>Luminis Software Development &#187; fitnesse</title>
	<atom:link href="http://lsd.luminis.eu/en/tag/fitnesse/feed/" rel="self" type="application/rss+xml" />
	<link>http://lsd.luminis.eu</link>
	<description></description>
	<lastBuildDate>Wed, 28 Dec 2011 20:44:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FitNesse and OSGi</title>
		<link>http://lsd.luminis.eu/en/fitnesse-and-osgi/</link>
		<comments>http://lsd.luminis.eu/en/fitnesse-and-osgi/#comments</comments>
		<pubDate>Tue, 25 May 2010 19:59:38 +0000</pubDate>
		<dc:creator>Angelo van der Sijpt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[acceptance testing]]></category>
		<category><![CDATA[fitnesse]]></category>
		<category><![CDATA[modularity]]></category>
		<category><![CDATA[OSGi]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=901</guid>
		<description><![CDATA[(Nederlands) Recently, I built a demonstrator project connecting FitNesse and OSGi. We show how that can help your project, and how we did it.]]></description>
			<content:encoded><![CDATA[<p>As a demonstrator for a customer, I recently built a set of fixtures that allow <a href="http://www.fitnesse.org">FitNesse</a> acceptance tests to talk to an OSGi framework. <strong>This code is by no means production quality, but merely intended to show the concept and explain the challenges.</strong></p>
<p>I will not explain the details of the acceptance tests here, however, if there&#8217;s one point I would like to get across, it&#8217;s <em>your fixtures should be as narrow as possible</em> to easily accommodate for implementation changes. Study the different <code>UserAdmin</code> fixtures for more details. Also, I assume some familiarity with OSGi.</p>
<h2>FitNesse and OSGi. Why?</h2>
<p>Of course its fun, there is some real benefit to be gained here. While the industry well understands the need for unit- and integration testing, also in a modular context, it becomes more complex to create the necessary link between business and code. Yes, using a modular architecture we can behave in a more agile fashion, but all that agility is no good if the business doesn&#8217;t hop on the train, and explain well what it needs. FitNesse allows the business to explain its goals in business-lingo, while forcing the specification to be precise enough to be executable: if a concept cannot be explained by simple scenarios, something is wrong, but that&#8217;s a different story.</p>
<p>The modular nature of OSGi means that behavior of an application is more emergent than deterministic, making it harder to reason about its correctness: we can prove that our code and bundles are correct (unit tests), that everything works together as it should (integration tests), and that it looks right (user interface tests). However, proving that the business rules (which may well be one of those emergent properties) are handled correctly in a given setting, is another can of worms: we need to connect our acceptance tests to the OSGi framework.</p>
<h2>The big picture</h2>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2010/05/Screen-shot-2010-05-25-at-9.27.41-PM.png"><img src="http://lsd.luminis.nl/wp-content/uploads/2010/05/Screen-shot-2010-05-25-at-9.27.41-PM-300x146.png" alt="FitNesse and OSGi - overview" title="FitNesse and OSGi - overview" width="300" height="146" class="alignnone size-medium wp-image-903" /></a></p>
<p>The solution presented below uses a special &#8216;fixtures&#8217; bundle, which can be deployed along side other bundles in your framework. This bundles exposes an interface (in our case, through an <code>HTTPServlet</code>), which is used by a set of connectors, which in turn are used by FitNesse.</p>
<h2>The details</h2>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2010/05/2010_05_25_21_38_03.png"><img src="http://lsd.luminis.nl/wp-content/uploads/2010/05/2010_05_25_21_38_03-300x212.png" alt="FitNesse and OSGi - detailed" title="FitNesse and OSGi - detailed" width="300" height="212" class="alignnone size-medium wp-image-905" /></a></p>
<p>The ingredients are two parts connector code, one part boiler plate, and one part genuine OSGi-aware fixtures.</p>
<h3>The connectors</h3>
<p>Starting at the level closest to FitNesse, we find a set of fixtures that FitNesse can use. For us, these contain merely boiler plate code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> removeUser<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    doRemoteCall<span style="color: #009900;">&#40;</span>buildRemoteCall<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UserAdmin&quot;</span>, name<span style="color: #009900;">&#41;</span>, <span style="color: #003399;">Void</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This code instructs our <code>RemoteInvoker</code> to do some call to the outside world. For more details, see <code>RemoteInvoker.java</code> in the <code>UserAdminRemoteFixtures</code> project.</p>
<h3>The fixture bundle</h3>
<p>Moving one step closer to our service, and into the OSGi framework, we find a <code>FixtureServlet</code>, whose task it is to receive calls from the <code>RemoteInvoker</code>, and turn them into actual method calls on the fixtures.</p>
<p>The fixtures, then, are almost regular OSGi aware objects. I chose to use the <a href="http://felix.apache.org/site/apache-felix-dependency-manager.html">Apache Felix Dependency Manager</a> for the dependency management of the fixtures. So, for our UserAdmin fixture, the dependencies are</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">manager.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>createService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">setInterface</span><span style="color: #009900;">&#40;</span>UserAdminListener.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">setImplementation</span><span style="color: #009900;">&#40;</span>userAdmin<span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>createServiceDependency<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #006633;">setService</span><span style="color: #009900;">&#40;</span>UserAdmin.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #006633;">setRequired</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here, we state that we have some instance of a fixture <code>userAdmin</code> that registers itself as a <code>UserAdminListener</code> and needs a <code>UserAdmin</code>. How straightforward is that?
</p>
<p>The final step takes us to the actual fixture,</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserAdminFixture <span style="color: #000000; font-weight: bold;">implements</span> UserAdminListener <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">volatile</span> UserAdmin m_userAdmin<span style="color: #339933;">;</span>
...
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addUser<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		m_usersCreatedInLastCall <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		m_userAdmin.<span style="color: #006633;">createRole</span><span style="color: #009900;">&#40;</span>name, Role.<span style="color: #006633;">USER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>which is just another component using a the <code>UserAdmin</code> service.
</p>
<h2>Putting it all together</h2>
<p>All we now need to do is deploy the fixture bundle in our project, and instruct FitNesse to use the remote connector. The zip file at the bottom of this post contains two shell scripts to do exactly that.</p>
<h2>Future work</h2>
<p>As I stated at the top of this story, this is by no means production quality code, but the concepts stand as they are. Given the way FitNesse works, the connectors do not need much extra work, perhaps support for collections. However, we could use</p>
<ul>
<li>a way to reduce the boiler plate code,</li>
<li>a way to ensure that that both side of the fixtures use the same function naming, and</li>
<li>better integration, for instance by only firing up a framework once a FitNesse suite is started.</li>
</ul>
<h2>Let&#8217;s play with it!</h2>
<p>I have built a <a href='http://lsd.luminis.nl/wp-content/uploads/2010/05/FitnesseAndOSGi.zip'>zip file</a> containing everything you need to get started, including a set of scenarios that can run with both a homebrew implementation of a User Admin, and the actual <a href="http://felix.apache.org">Apache Felix User Admin</a>. A Readme gives you more information on getting it all up and running.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.eu/en/fitnesse-and-osgi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

