<?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>Developers blog &#187; Code</title>
	<atom:link href="http://www.realdevelopers.com/blog/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.realdevelopers.com/blog</link>
	<description>realdevelopers.com</description>
	<lastBuildDate>Wed, 14 Sep 2011 21:38:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Testing in C#</title>
		<link>http://www.realdevelopers.com/blog/code/testing-in-c</link>
		<comments>http://www.realdevelopers.com/blog/code/testing-in-c#comments</comments>
		<pubDate>Wed, 03 Aug 2011 16:47:21 +0000</pubDate>
		<dc:creator>astro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[subclassing]]></category>
		<category><![CDATA[virtual]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1447</guid>
		<description><![CDATA[I want to test a method of a class &#8220;Service&#8221;



public void AddDrawing&#40;Converter conv, Drawing drw&#41; &#123;


&#160; &#160;&#91;&#8230;&#93;


&#160; &#160;conv.AddDrawing&#40;drw&#41;;


&#160; &#160;&#91;&#8230;&#93;


&#125;



The problem is, that Converter provides no way to determine which drawings have been added. So I tried the following, like I would have done in Java &#8211; subclass the Converter and add the needed methods.




public class [...]]]></description>
			<content:encoded><![CDATA[<p>I want to test a method of a class &#8220;Service&#8221;</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw4">void</span> AddDrawing<span class="br0">&#40;</span>Converter conv, Drawing drw<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#91;</span>&#8230;<span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;conv.<span class="me1">AddDrawing</span><span class="br0">&#40;</span>drw<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#91;</span>&#8230;<span class="br0">&#93;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The problem is, that Converter provides no way to determine which drawings have been added. So I tried the following, like I would have done in Java &#8211; subclass the Converter and add the needed methods.<br />
<span id="more-1447"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> TestConverter : Converter <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw2">private</span> readonly List&lt;Drawing&gt; _drawings = <span class="kw2">new</span> List&lt;Drawing&gt;<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> AddDrawing<span class="br0">&#40;</span>Drawing drw<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _drawings.<span class="me1">Add</span><span class="br0">&#40;</span>drw<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw2">public</span> List&lt;Drawing&gt; GetDrawings<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> _drawings;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>But I can&#8217;t override the AddDrawing-Method, because it&#8217;s not marked as virtual in the super class (and I can&#8217;t change the super class). Now what?</p>
<p>I chose to factor out the conv.AddDrawing(drw) part of the original method in a new method &#8220;AddToConverter&#8221;, create a TestService class and override the new method there similar to how I planned to do in the TestConverter. Leads to more methods that need to have less restricted access than I&#8217;d like to&#8230; bäh.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/testing-in-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>#region</title>
		<link>http://www.realdevelopers.com/blog/code/region</link>
		<comments>http://www.realdevelopers.com/blog/code/region#comments</comments>
		<pubDate>Wed, 03 Aug 2011 16:44:35 +0000</pubDate>
		<dc:creator>astro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Code Quality]]></category>
		<category><![CDATA[region]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1451</guid>
		<description><![CDATA[Finally I found a case, where I really like C# regions: to structure unit tests. Usually there is more than one test per method and finding the place, where the testing of one method starts and the other ends is quite annoying.
In all other classes I still think that the only use of regions is [...]]]></description>
			<content:encoded><![CDATA[<p>Finally I found a case, where I really like C# regions: to structure unit tests. Usually there is more than one test per method and finding the place, where the testing of one method starts and the other ends is quite annoying.</p>
<p>In all other classes I still think that the only use of regions is to find which parts of a class should be extracted into a new class <img src='http://www.realdevelopers.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/region/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>page-break-after in Firefox</title>
		<link>http://www.realdevelopers.com/blog/code/page-break-after-in-firefox</link>
		<comments>http://www.realdevelopers.com/blog/code/page-break-after-in-firefox#comments</comments>
		<pubDate>Wed, 12 Jan 2011 11:41:26 +0000</pubDate>
		<dc:creator>astro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[style sheets]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1366</guid>
		<description><![CDATA[Lately, we&#8217;ve been playing around with stylesheets for print and directly ran into some problems. 
This snippet in Firefox



&#60;div style=&#34;page-break-after: always&#34;&#62;


&#160; &#160;&#60;!&#8211; first page &#8211;&#62;


&#60;/div&#62;


&#60;div style=&#34;page-break-after: always&#34;&#62;


&#160; &#160;&#60;!&#8211; second page &#8211;&#62;


&#60;/div&#62;



only prints exactly one page (that means it even stops in the middle of a line when the page is full).

However, using 



html, body {


&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, we&#8217;ve been playing around with stylesheets for print and directly ran into some problems. </p>
<p>This snippet in Firefox</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;div</span> <span class="re0">style</span>=<span class="st0">&quot;page-break-after: always&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="coMULTI">&lt;!&#8211; first page &#8211;&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;div</span> <span class="re0">style</span>=<span class="st0">&quot;page-break-after: always&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp;<span class="sc3"><span class="coMULTI">&lt;!&#8211; second page &#8211;&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>only prints exactly one page (that means it even stops in the middle of a line when the page is full).<br />
<span id="more-1366"></span></p>
<p>However, using </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">html, body {</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; overflow:visible !important</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
</ol>
</div>
<p>instead of </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">html, body {</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; overflow:auto !important</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
</ol>
</div>
<p>solved the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/page-break-after-in-firefox/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Decoded Conference</title>
		<link>http://www.realdevelopers.com/blog/code/decoded-conference</link>
		<comments>http://www.realdevelopers.com/blog/code/decoded-conference#comments</comments>
		<pubDate>Sun, 31 Oct 2010 16:14:43 +0000</pubDate>
		<dc:creator>astro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Culture]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Product Design]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[decoded]]></category>
		<category><![CDATA[facet search]]></category>
		<category><![CDATA[information design]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1331</guid>
		<description><![CDATA[Last Saturday I visitied decoded, a conference dedicated to the beautiful things one can do with code. Topics ranged from art projects over open source hardware to more serious topics like visualization of data.
All talks were awesome (and I totally want an arduino for Christmas), but the one that kept me researching and having new [...]]]></description>
			<content:encoded><![CDATA[<p>Last Saturday I visitied <a href="http://decoded-conference.com/">decoded</a>, a conference dedicated to the beautiful things one can do with code. Topics ranged from art projects over <a href="http://www.arduino.cc/">open source hardware</a> to more serious topics like visualization of data.</p>
<p>All talks were awesome (and I totally want an arduino for Christmas), but the one that kept me researching and having new ideas was the one of Moritz Stefaner about visualizing information. He has some really inspiring websites (<a href="http://moritz.stefaner.eu/">here</a> and <a href="http://well-formed-data.net/">here</a>). I especially liked his <a href="http://moritz.stefaner.eu/downloads/papers/DynTax_Ch_UI.pdf">contribution</a> to the book &#8220;Dynamic Taxonomies and Faceted Search&#8221; &#8211; it&#8217;s about search, visualization and it even has formulas. What more could one want?<span id="more-1331"></span></p>
<p>The organizor of the conference promised to upload videos of the talks, I&#8217;ll post an update once they are available (most are in german, though)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/decoded-conference/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy builders in Grails taglibs</title>
		<link>http://www.realdevelopers.com/blog/code/groovy-builders-in-grails-taglibs</link>
		<comments>http://www.realdevelopers.com/blog/code/groovy-builders-in-grails-taglibs#comments</comments>
		<pubDate>Sat, 19 Jun 2010 10:08:56 +0000</pubDate>
		<dc:creator>Helga</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[MarkupBuilder]]></category>
		<category><![CDATA[taglib]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1187</guid>
		<description><![CDATA[Did you ever want to use builders in your grails taglib and wondered why the approach mentioned in the grails documentation doesn&#8217;t work at all? Here is what I found out after a lot of trial and error and digging in the MarkupBuilder, BuilderSupport and GroovyPagTagBody sources. Let&#8217;s stick with the example from the documentation [...]]]></description>
			<content:encoded><![CDATA[<p>Did you ever want to use builders in your grails taglib and wondered why the approach mentioned in the <a href="http://grails.org/Dynamic%20Tag%20Libraries#Markup%20building%20in%20tags">grails documentation</a> doesn&#8217;t work at all? Here is what I found out after a lot of trial and error and digging in the MarkupBuilder, BuilderSupport and GroovyPagTagBody sources. Let&#8217;s stick with the example from the documentation and correct it until it works (the impatient can scroll down):</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span class="kw2">def</span></a> dialog = <span class="br0">&#123;</span> attrs, body -&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span class="kw2">def</span></a> markup = <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span class="kw2">new</span></a> groovy.<span class="me1">xml</span>.<span class="me1">MarkupBuilder</span><span class="br0">&#40;</span>out<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; markup <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; div<span class="br0">&#40;</span><span class="st0">&#8216;class&#8217;</span>: <span class="st0">&#8216;dialog&#8217;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; body<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="br0">&#125;</span> <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><span id="more-1187"></span></p>
<p>The first small remark is about line 3: <code>markup{//doSomething}</code> is similiar to <code>markup.call({//doSomething})</code>. BuilderSupport intercepts all method calls and MarkupBuilder produces xml tags from these method calls. So this will lead to an enclosing <code>&lt;call&gt;</code> tag. Surely not what we want.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span class="kw2">def</span></a> dialog = <span class="br0">&#123;</span> attrs, body -&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span class="kw2">def</span></a> markup = <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span class="kw2">new</span></a> groovy.<span class="me1">xml</span>.<span class="me1">MarkupBuilder</span><span class="br0">&#40;</span>out<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; markup.<span class="me1">div</span><span class="br0">&#40;</span><span class="st0">&#8216;class&#8217;</span>: <span class="st0">&#8216;dialog&#8217;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; body<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span> <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Now let&#8217;s have a closer look at the body parameter. This is a GroovyPageTagBody, a special Closure which captures output using a special Writer (GroovyPageTageWriter). These bodies are usually called by various GroovyPage.invokeTag methods (see another following article on how to investigate groovy pages rendering) and return either a StreamCharBuffer (a special Writable and CharSequence) or the result of the closure evaluation, which is also Writable or a CharSequence if we are lucky.</p>
<p>So what is the right way to pass a CharSequence to the builder if we want our MarkupBuilder to use it as tag content? This will not work:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span class="kw2">def</span></a> markup = <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span class="kw2">new</span></a> groovy.<span class="me1">xml</span>.<span class="me1">MarkupBuilder</span><span class="br0">&#40;</span>out<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">markup.<span class="me1">div</span><span class="br0">&#40;</span><span class="st0">&#8216;class&#8217;</span>: <span class="st0">&#8216;dialog&#8217;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;some text&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The String will be evaluated, but as it&#8217;s not in a method call, our MarkupBuilder doesn&#8217;t know what to do with it. There are two possibilities to do it right:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span class="kw2">def</span></a> markup = <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span class="kw2">new</span></a> groovy.<span class="me1">xml</span>.<span class="me1">MarkupBuilder</span><span class="br0">&#40;</span>out<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">markup.<span class="me1">div</span><span class="br0">&#40;</span><span class="st0">&#8216;class&#8217;</span>: <span class="st0">&#8216;dialog&#8217;</span>, <span class="st0">&quot;some text&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">markup.<span class="me1">div</span><span class="br0">&#40;</span><span class="st0">&#8216;class&#8217;</span>: <span class="st0">&#8216;dialog&#8217;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; mkp.<span class="me1">yield</span> <span class="st0">&quot;some text&quot;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>If we now replace &#8220;some text&#8221; with our GroovyPageTagBody call, we are nearly done. But wait, there&#8217;s one more thing. mkp (short for <code>markup.getMkp()</code>) returns a MarkupBuilderHelper (since Groovy 1.6.6, prior it was the builder itself). Instead of <code>mkp.yield("some text")</code> we could also use the yield method of the MarkupBuilder itself: <code>yield("some text", true)</code>. But, hey, what means <code>true</code>? It&#8217;s the XML escaping of the text, which is also done if we pass the text as last parameter to the builder method (as in line 2 above). If we expect our body to contain markup, we should omit escaping. Of course there is also a helper method for that and our corrected example now finally looks right:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span class="kw2">def</span></a> dialog = <span class="br0">&#123;</span> attrs, body -&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span class="kw2">def</span></a> markup = <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span class="kw2">new</span></a> groovy.<span class="me1">xml</span>.<span class="me1">MarkupBuilder</span><span class="br0">&#40;</span>out<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; markup.<span class="me1">div</span><span class="br0">&#40;</span><span class="st0">&#8216;class&#8217;</span>: <span class="st0">&#8216;dialog&#8217;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; mkp.<span class="me1">yieldUnescaped</span> body<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span> <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>One last remark: Prior to Groovy 1.7.2 MarkupBuilderHelpers yield and yieldUnescaped methods were duplicated in MarkupBuilder itself, so the mkp prefix could be omitted. This is no longer true. You have to either fall back to the ugly boolean parameter or use the helpers pretty named methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/groovy-builders-in-grails-taglibs/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Grails ControllerUnitTest vs. GrailsUnitTest</title>
		<link>http://www.realdevelopers.com/blog/code/grails-controllerunittest-vs-grailsunittest</link>
		<comments>http://www.realdevelopers.com/blog/code/grails-controllerunittest-vs-grailsunittest#comments</comments>
		<pubDate>Fri, 21 May 2010 16:36:59 +0000</pubDate>
		<dc:creator>astro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[greenmail]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1084</guid>
		<description><![CDATA[Grails claims that it encourages writing test &#8211; for example, a test class is created every time you create a controller or domain. However, working on my first Grails project I find it quite confusing which kind of test supports what.
For example, we use GreenMail in our testing environment. To check for sent mails, we [...]]]></description>
			<content:encoded><![CDATA[<p>Grails claims that it encourages writing test &#8211; for example, a test class is created every time you create a controller or domain. However, working on my first Grails project I find it quite confusing which kind of test supports what.</p>
<p>For example, we use <a href="http://www.icegreen.com/greenmail/">GreenMail</a> in our testing environment. To check for sent mails, we have to use GrailsUnitTests, even if we are testing a Controller, because the content of mails is always empty in ControllerUnitTests.</p>
<p>Checking view names or redirects in those two types of tests is also slightly different:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">//ControllerUnitTest</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">assert</span> controller.<span class="me1">modelAndView</span>.<span class="me1">view</span> == <span class="st0">&quot;send&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">assert</span> controller.<span class="me1">redirectArgs</span>.<span class="me1">controller</span> == <span class="st0">&quot;delivery&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//GrailsUnitTests</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">assert</span> controller.<span class="me1">modelAndView</span>.<span class="me1">view</span> == <span class="st0">&quot;Message/send&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">assert</span> controller.<span class="me1">response</span>.<span class="me1">redirectUrl</span> == <span class="st0">&quot;/delivery&quot;</span></div>
</li>
</ol>
</div>
<p>This is pretty annoying and I hope it will be unified in future versions of Grails.<span style="display:none;"><span id="more-1084"></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/grails-controllerunittest-vs-grailsunittest/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tracking pages without IDs</title>
		<link>http://www.realdevelopers.com/blog/code/tracking_pages_without_ids</link>
		<comments>http://www.realdevelopers.com/blog/code/tracking_pages_without_ids#comments</comments>
		<pubDate>Wed, 12 May 2010 13:19:12 +0000</pubDate>
		<dc:creator>astro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1111</guid>
		<description><![CDATA[Per default, Google Analytics tracks the whole URL. As a lot of our URLs contain some parameters or IDs, and we&#8217;re not interessted in tracking them, we needed to find a way to truncate them. As Grails unfortunately does not provide methods to access the current view and controller (which is basically what we&#8217;d like [...]]]></description>
			<content:encoded><![CDATA[<p>Per default, Google Analytics tracks the whole URL. As a lot of our URLs contain some parameters or IDs, and we&#8217;re not interessted in tracking them, we needed to find a way to truncate them. As Grails unfortunately does not provide methods to access the current view and controller (which is basically what we&#8217;d like to track) in GSPs, we used this code:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">pageTracker._trackPageview<span class="br0">&#40;</span>$<span class="br0">&#123;</span>request.<span class="me1">getServletPath</span><span class="br0">&#40;</span><span class="br0">&#41;</span> &#8211; <span class="st0">&#8216;/grails/&#8217;</span> &#8211; <span class="st0">&#8216;.dispatch&#8217;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Not as clean as we&#8217;d like to have it, so suggestions are welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/tracking_pages_without_ids/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>request.addHeader()</title>
		<link>http://www.realdevelopers.com/blog/code/request-addheader</link>
		<comments>http://www.realdevelopers.com/blog/code/request-addheader#comments</comments>
		<pubDate>Fri, 16 Apr 2010 16:27:01 +0000</pubDate>
		<dc:creator>astro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[mock]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1087</guid>
		<description><![CDATA[Sometimes the easiest way is the right one &#8211; after a considerable time of research, trial and error we figured out, how to pretend to be a certain browser in a grails tests:



controller.request.addHeader&#40;&#34;USER-AGENT&#34;, &#34;mozilla&#34;&#41;



The information is stored in the request header, so the obvious solution to add an user-agent-header worked. That we didn&#8217;t even consider this [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes the easiest way is the right one &#8211; after a considerable time of research, trial and error we figured out, how to pretend to be a certain browser in a grails tests:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">controller.<span class="me1">request</span>.<span class="me1">addHeader</span><span class="br0">&#40;</span><span class="st0">&quot;USER-AGENT&quot;</span>, <span class="st0">&quot;mozilla&quot;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>The information is stored in the request header, so the obvious solution to add an user-agent-header worked. That we didn&#8217;t even consider this solution at first is maybe a sign that testing in grails seldom does what you expect&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/request-addheader/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Joys of the JVM</title>
		<link>http://www.realdevelopers.com/blog/code/joys-of-the-jvm</link>
		<comments>http://www.realdevelopers.com/blog/code/joys-of-the-jvm#comments</comments>
		<pubDate>Wed, 14 Apr 2010 10:57:26 +0000</pubDate>
		<dc:creator>shikhar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1065</guid>
		<description><![CDATA[We are using Groovy on Grails for an incubator project, which is incredibly refreshing! Groovy as a dynamic language with optional type annotations doesn&#8217;t quite rock my boat though. With static type checking the types you define are an essential element of design. I like to point out that Groovy&#8217;s creator wrote:
“I can honestly say [...]]]></description>
			<content:encoded><![CDATA[<p>We are using Groovy on Grails for an incubator project, which is incredibly refreshing! Groovy as a dynamic language with optional type annotations doesn&#8217;t quite rock my boat though. With static type checking the types you define are an essential element of design. I like to point out that <a href="http://macstrac.blogspot.com/2009/04/scala-as-long-term-replacement-for.html">Groovy&#8217;s creator wrote</a>:</p>
<blockquote><p>“I can honestly say if someone had shown me the <a href="http://www.artima.com/shop/programming_in_scala">Programming in Scala</a> book by by Martin Odersky, Lex Spoon &#038; Bill Venners back in 2003 I&#8217;d probably have never created Groovy.”<span id="more-1065"></span></p></blockquote>
<p>That book incidentally is highly recommended. Some might be put off by the operator-heavy syntax but it is simply a matter of getting familiar with it. The language itself is quite tiny &#8211; the defining goal is for Scala to be a <a href="http://www.artima.com/scalazine/articles/scalable-language.html"><em>scalable language</em></a>. For example, the language didn&#8217;t have to grow to accommodate Erlang-style actors, but they could be implemented as a library. The type system is very well thought-out and feels like what Java should have been. And it is so easy to mix OO and functional programming (without having to <a href="http://www.realdevelopers.com/blog/archives/643">fight the language</a>!)</p>
<p>Lots of web folk are proclaiming the death of Java (not likely to happen for a long, long time); but the JVM ecosystem is flourishing. With Groovy, Scala and Clojure there are great options for leveraging existing libraries and interacting with legacy code. So pick a flavor and dig in!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/joys-of-the-jvm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Testing filters in grails</title>
		<link>http://www.realdevelopers.com/blog/code/testing-filters-in-grails</link>
		<comments>http://www.realdevelopers.com/blog/code/testing-filters-in-grails#comments</comments>
		<pubDate>Tue, 13 Apr 2010 16:37:07 +0000</pubDate>
		<dc:creator>astro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[functional test]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://www.realdevelopers.com/blog/?p=1047</guid>
		<description><![CDATA[Grails supports filters, which are applied to each action &#8211; before or after executing the action or after rendering. The scope of those filters can be constrained by a regex-like syntax to a subset of all actions.
That&#8217;s a pretty neat method to check for authentication, incorrect parameters etc. Unfortunately, filters are not applied during unit [...]]]></description>
			<content:encoded><![CDATA[<p>Grails supports <a href="http://www.grails.org/Filters">filters</a>, which are applied to each action &#8211; before or after executing the action or after rendering. The scope of those filters can be constrained by a regex-like syntax to a subset of all actions.</p>
<p>That&#8217;s a pretty neat method to check for authentication, incorrect parameters etc. Unfortunately, filters are not applied during unit or integration tests &#8211; you need functional tests that simulate http-requests and responses to verify they are doing the right thing. </p>
<p>Grails does not support functional tests directly, you need a plugin (we chose &#8220;functional-test&#8221;):<span id="more-1047"></span></p>
<pre>grails install-plugin functional-test (install)
grails createFunctionalTest AuthenticationFilters (create test)
grails functional-tests (run test)</pre>
<p>There are a couple of annoying things regarding functional tests:</p>
<ul>
<li>takes forever (more than one minute)</li>
<li>when checking for contentsContains you only see that it didn&#8217;t match, but not what the content was</li>
<li>you&#8217;re not able to see the output of println for simple debugging</li>
</ul>
<p>On top of that it didn&#8217;t work when one installs the plugin and someone else in the team does an svn update &#8211; only after calling run-app twice.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.realdevelopers.com/blog/code/testing-filters-in-grails/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

