<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ted Vinke&#039;s Blog</title>
	<atom:link href="http://tedvinke.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://tedvinke.wordpress.com</link>
	<description>Java, technology and stuff</description>
	<lastBuildDate>Thu, 25 Aug 2011 10:44:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='tedvinke.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/733caa03241dc7863cf6fb46a0286715?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Ted Vinke&#039;s Blog</title>
		<link>http://tedvinke.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://tedvinke.wordpress.com/osd.xml" title="Ted Vinke&#039;s Blog" />
	<atom:link rel='hub' href='http://tedvinke.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Partial mocking with PowerMock</title>
		<link>http://tedvinke.wordpress.com/2011/08/25/partial-mocking-with-powermock/</link>
		<comments>http://tedvinke.wordpress.com/2011/08/25/partial-mocking-with-powermock/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 10:43:53 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[powermock]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=249</guid>
		<description><![CDATA[I love PowerMock! For those who don't know it, quoting their site, "PowerMock is a Java framework that allows you to unit test code normally regarded as untestable". While not one of its unique selling points, because EasyMock allows you to do basically the same, I'll show an example here of partially mocking a class in PowerMock.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=249&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://code.google.com/p/powermock/" target="_blank">PowerMock</a>! For those who don&#8217;t know it, quoting their site, &#8220;PowerMock is a Java framework that allows you to unit test code normally regarded as untestable&#8221;.</p>
<p>While not one of its unique selling points, because EasyMock allows you to do basically the same, here&#8217;s an example of <em>partially</em> mocking a class in PowerMock.</p>
<p>Given class <em>CustomerService</em>:</p>
<pre class="brush: java;">
class CustomerService {

	public void add(Customer customer) {
		if (someCondition) {
			subscribeToNewsletter(customer);
		}
	}

	void subscribeToNewsletter(Customer customer) {
		// ...subscribing stuff
	}
}
</pre>
<p>So you want to test the <em>add()</em> method for actually invoking <em>subscribeToNewsletter()</em> and do NOT want to execute the logic from <em>subscribeToNewsletter()</em> in this test &#8211; e.g. since you&#8217;re already unit testing <em>subscribeToNewsletter()</em> somewhere else.</p>
<p>Then you create a PARTIAL mock of <em>CustomerService</em>, giving a list of methods you want to mock.</p>
<pre class="brush: java;">
CustomerService customerService = PowerMock.createPartialMock(CustomerService.class, &quot;subscribeToNewsletter&quot;);
customerService.subscribeToNewsletter(anyObject(Customer.class));

replayAll();

customerService.add(createMock(Customer.class));
</pre>
<p>So <em>add()</em> within the <em>CustomerService</em> mock is the REAL thing you want to test and for the method<em> subscribeToNewsletter()</em> you now can write an expectation as usual.</p>
<p>Disclaimer:</p>
<ul>
<li><a href="http://code.google.com/p/powermock/wiki/MockPartial" target="_blank">Mocking partially</a> like this only works with PUBLIC or DEFAULT methods. So for this one, I actually had to change <em>subscribeToNewsletter()</em> from PRIVATE to DEFAULT visibility to make it testable &#8211; which possible might not be desirable in all cases.</li>
<li>Using a string &#8220;subscribeToNewsletter&#8221; which matches an actual method name is not very refactoring safe. Preferable you should at least a constant to discriminate from being any ordinary string. Anyway, your unit test will break sooner or later anyway if this method changes name &#8211; and you&#8217;ll know <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
</ul>
<p>For further reading, where PowerMock really excels is <a href="http://code.google.com/p/powermock/wiki/MockStatic" target="_blank">mocking of static methods</a> and <a href="http://code.google.com/p/powermock/wiki/MockPrivate" target="_blank">private methods</a>.</p>
<br />Filed under: <a href='http://tedvinke.wordpress.com/category/java/'>Java</a>, <a href='http://tedvinke.wordpress.com/category/web-development/'>Web Development</a> Tagged: <a href='http://tedvinke.wordpress.com/tag/mock/'>mock</a>, <a href='http://tedvinke.wordpress.com/tag/powermock/'>powermock</a>, <a href='http://tedvinke.wordpress.com/tag/testing/'>testing</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/249/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=249&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2011/08/25/partial-mocking-with-powermock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>
	</item>
		<item>
		<title>2010 in review</title>
		<link>http://tedvinke.wordpress.com/2011/01/02/2010-in-review/</link>
		<comments>http://tedvinke.wordpress.com/2011/01/02/2010-in-review/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 13:18:09 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Noppes]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=243</guid>
		<description><![CDATA[The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here&#8217;s a high level summary of its overall blog health: The Blog-Health-o-Meter™ reads Fresher than ever. Crunchy numbers A Boeing 747-400 passenger jet can hold 416 passengers. This blog was viewed about 6,300 times in 2010. That&#8217;s about 15 full [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=243&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here&#8217;s a high level summary of its overall blog health:</p>
<p><img style="border:1px solid #ddd;background:#f5f5f5;padding:20px;" src="http://s0.wp.com/i/annual-recap/meter-healthy3.gif" alt="Healthy blog!" width="250" height="183" /></p>
<p>The <em>Blog-Health-o-Meter™</em> reads Fresher than ever.</p>
<h2>Crunchy numbers</h2>
<p><a href="http://tedvinke.files.wordpress.com/2009/05/david-hasselhof-paper.jpg"><img style="max-height:230px;float:right;border:1px solid #ddd;background:#fff;margin:0 0 1em 1em;padding:6px;" src="http://tedvinke.files.wordpress.com/2009/05/david-hasselhof-paper.jpg?w=288" alt="Featured image" /></a></p>
<p>A Boeing 747-400 passenger jet can hold 416 passengers.  This blog was viewed about <strong>6,300</strong> times in 2010.  That&#8217;s about 15 full 747s.</p>
<p>&nbsp;</p>
<p>In 2010, there were <strong>7</strong> new posts, growing the total archive of this blog to 19 posts. There were <strong>18</strong> pictures uploaded, taking up a total of 4mb. That&#8217;s about 2 pictures per month.</p>
<p>The busiest day of the year was July 1st with <strong>139</strong> views. The most popular post that day was <a style="color:#08c;" href="http://tedvinke.wordpress.com/2010/07/01/gorm-and-hibernate-session-factory/">GORM and Hibernate&#8217;s session factory</a>.</p>
<h2>Where did they come from?</h2>
<p>The top referring sites in 2010 were <strong>grailstutorials.com</strong>, <strong>dzone.com</strong>, <strong>grails.org</strong>, <strong>observatoriodegrails.com</strong>, and <strong>pedrocorreia.net</strong>.</p>
<p>Some visitors came searching, mostly for <strong>handen en voeten geven</strong>, <strong>eclipse repository registry initialization</strong>, <strong>david hasselhoff</strong>, <strong>grails form validation</strong>, and <strong>initializing java tooling</strong>.</p>
<h2>Attractions in 2010</h2>
<p>These are the posts and pages that got the most views in 2010.</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">1</div>
<p><a style="margin-right:10px;" href="http://tedvinke.wordpress.com/2010/07/01/gorm-and-hibernate-session-factory/">GORM and Hibernate&#8217;s session factory</a> <span style="color:#999;font-size:8pt;">July 2010</span><br />
4 comments</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">2</div>
<p><a style="margin-right:10px;" href="http://tedvinke.wordpress.com/2010/03/02/grails-remote-jquery-form-validation/">Grails remote jQuery form validation</a> <span style="color:#999;font-size:8pt;">March 2010</span><br />
2 comments</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">3</div>
<p><a style="margin-right:10px;" href="http://tedvinke.wordpress.com/2010/06/21/eclipse-initializing-java-tooling-hangs/">Eclipse &#8220;Initializing Java Tooling&#8221; hangs</a> <span style="color:#999;font-size:8pt;">June 2010</span></p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">4</div>
<p><a style="margin-right:10px;" href="http://tedvinke.wordpress.com/2010/06/09/separating-and-securing-grails-controllers/">Separating and securing Grails controllers</a> <span style="color:#999;font-size:8pt;">June 2010</span><br />
1 comment</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">5</div>
<p><a style="margin-right:10px;" href="http://tedvinke.wordpress.com/2009/05/05/the-do-it-yourself-posable-paper-of-david-hasselhoff/">The Do-It-Yourself Posable Paper of David Hasselhoff</a> <span style="color:#999;font-size:8pt;">May 2009</span></p>
<br />Filed under: <a href='http://tedvinke.wordpress.com/category/noppes/'>Noppes</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/243/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=243&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2011/01/02/2010-in-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>

		<media:content url="http://s0.wp.com/i/annual-recap/meter-healthy3.gif" medium="image">
			<media:title type="html">Healthy blog!</media:title>
		</media:content>

		<media:content url="http://tedvinke.files.wordpress.com/2009/05/david-hasselhof-paper.jpg?w=288" medium="image">
			<media:title type="html">Featured image</media:title>
		</media:content>
	</item>
		<item>
		<title>Hibernate class metadata through Spring</title>
		<link>http://tedvinke.wordpress.com/2010/12/16/hibernate-class-metadata-through-spring/</link>
		<comments>http://tedvinke.wordpress.com/2010/12/16/hibernate-class-metadata-through-spring/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 09:45:10 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=236</guid>
		<description><![CDATA[Hibernate's metadata API is a very powerful aid in getting the runtime information you might possibly need on your datamodel. This post explains how to use Hibernate's ClassMetadata to retrieve the table name for a given entity.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=236&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On a Spring-Hibernate project I&#8217;m working on we use a custom way of filling and clearing specific database tables in unit tests. Yes, something like <a href="http://www.dbunit.org">DbUnit</a> but ofcourse completely hand-made, tailored to our situation <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  In a TestNG testcase we do something like this:</p>
<pre class="brush: java;">
@BeforeMethod
public void setUp() {
	DatabaseFiller.fillTable(&quot;UserAccounts&quot;, &quot;useraccounts.txt&quot;);
}

@AfterMethod
public void tearDown() {
	DatabaseFiller.clearTable(&quot;UserAccounts&quot;);
}
</pre>
<p>It bugged a little bit, that in this testcase e.g. we&#8217;re testing operations on the User entity (e.g.<em> User.class</em>) &#8211; which for database specific reasons was mapped to a &#8220;UserAccounts&#8221; table &#8211; but we still have to find the actual table name for ourselves. There are many reasons to map explicitly to a certain table name: prevent database reserved keywords (&#8220;user&#8221; is often reserved), enforce a naming convention (&#8220;tbl_user&#8221;), etc. If no specifics have been set for Hibernate it will take its own naming convention, else one could indicate the desired name through the <em>javax.persistence.Table</em> annotation &#8211; if using JPA.<span id="more-236"></span></p>
<p>Our User entity is described like this:</p>
<pre class="brush: java;">
@Entity
@Table(name = &quot;UserAccounts&quot;)
public class User {
...
</pre>
<p>which results in a &#8220;UserAccounts&#8221; table being used by the underlying provider &#8211; instead of the default naming convention.</p>
<p>The issue is that with a lot of entities a developer can not guess from the entity itself what table is being used actually. He can guess, due to clear company development guidelines, a table name based on the entity name, but he only knows for sure if looking at the code. In our example, clearing tables based on the table name can break if &#8211; for whatever reason &#8211; an entity is renamed and no specific table name was set. Ofcourse, renaming database tables can break a lot more than just the clearing of it in a unit test &#8211; it usually doesn&#8217;t happen very often and if it does, it needs to be done with care.</p>
<p>Next to that, it&#8217;s just an inconvenience for the developer having to look up the table name when he already knows the entity he wants to clear from the system. Woudn&#8217;t it be great to point to the entity itself? Hence, let us introduce a better solution using Hibernate metadata!</p>
<p>Hibernate metadata is all about the accessing the <a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/metadata/package-summary.html">Hibernate runtime metamodel</a>, including collections and entities. The ClassMetadata interface allows access to an entity&#8217;s identifier, name, properties and versioning information &#8211; which is thus perfectly capable of telling us the table name. This metadata is retrieved for an entity through <em>Hibernate&#8217;s session factory</em>, which for instance can be exposed like this in our Spring configuration:</p>
<pre class="brush: xml;">
&lt;bean id=&quot;sessionFactory&quot; factory-bean=&quot;entityManagerFactory&quot; factory-method=&quot;getSessionFactory&quot; /&gt;
</pre>
<p>Our earlier used Database class can be wired together with this session factory &#8211; if also loaded as a Spring bean and pointing to the session factory bean. Here&#8217;s an example &#8211; which for brevity omits the getters and setters.</p>
<pre class="brush: java;">
public class DatabaseFiller {

    @PersistenceContext
    private EntityManager entityManager;

    private SessionFactory sessionFactory;
</pre>
<p>We can now modify it with a method which returns the table name for an entity class:</p>
<pre class="brush: java;">
/**
 * Return the table name used by Hibernate for given &lt;code&gt;persistentClass&lt;/code&gt;.
 *
 * @param persistentClass
 *            The class of the entity
 * @return the table name
 * @throws NullPointerException
 *             if the &lt;code&gt;persistentClass&lt;/code&gt; is null
 * @throws IllegalArgumentException
 *             if the &lt;code&gt;persistentClass&lt;/code&gt; has no class metadata to get the table name from
 */
public String getTableName(Class persistentClass) {
	if (persistentClass == null) {
		throw new NullPointerException(&quot;persistent class&quot;);
	}

	ClassMetadata classMetadata = sessionFactory.getClassMetadata(persistentClass);
	if (classMetadata == null) {
		throw new IllegalArgumentException(&quot;No class metadata.&quot;);
	}

	if (classMetadata instanceof AbstractEntityPersister) {
		return ((AbstractEntityPersister) classMetadata).getTableName();
	} else {
		throw new RuntimeException(&quot;Unknown implementation.&quot;);
	}
}
</pre>
<p>Ofcourse, you can do whatever you want if things fail, return <em>null</em> instead of an exception for instance. Using Spring it&#8217;s only more easy to hook up the required beans, but it&#8217;s not a prerequisite.</p>
<p>Now we can alter our <em>DatabaseFiller.clearTable</em> method to accept a class,  internally lookup the table name and perform the same logic it always does. The developer isn&#8217;t bothered anymore to lookup the table name him or herself which is basically the point of this excercise.</p>
<pre class="brush: java;">
@AfterMethod
public void tearDown() {
	DatabaseFiller.clearTable(User.class);
}
</pre>
<p>To summarize, Hibernate&#8217;s <a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/metadata/package-summary.html">metadata API</a> is a very powerful aid in getting the runtime information you might possibly need on your datamodel.</p>
<br />Filed under: <a href='http://tedvinke.wordpress.com/category/java/'>Java</a>, <a href='http://tedvinke.wordpress.com/category/web-development/'>Web Development</a> Tagged: <a href='http://tedvinke.wordpress.com/tag/hibernate/'>hibernate</a>, <a href='http://tedvinke.wordpress.com/tag/spring/'>spring</a>, <a href='http://tedvinke.wordpress.com/tag/testing/'>testing</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/236/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=236&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2010/12/16/hibernate-class-metadata-through-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>
	</item>
		<item>
		<title>GORM and Hibernate&#8217;s session factory</title>
		<link>http://tedvinke.wordpress.com/2010/07/01/gorm-and-hibernate-session-factory/</link>
		<comments>http://tedvinke.wordpress.com/2010/07/01/gorm-and-hibernate-session-factory/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 08:27:08 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Grails & Groovy]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[gorm]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[hibernate]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=212</guid>
		<description><![CDATA[Peter Ledbrook wrote an excellent introduction article about Grails ORM a.k.a. GORM in which the importance of Hibernate and the usage of sessions are highlighted. A quote: Hibernate is a session-based ORM framework. A session is retrieved from Hibernate&#8217;s SessionFactory (org.hibernate.SessionFactory) which implements a design pattern that ensures that only one instance of the session [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=212&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Peter Ledbrook wrote an <a href="http://blog.springsource.com/2010/06/23/gorm-gotchas-part-1/" target="_blank">excellent introduction article</a> about Grails ORM a.k.a. GORM in which the importance of Hibernate and the usage of sessions are highlighted. A quote:</p>
<blockquote><p><strong>Hibernate is a session-based ORM framework.</strong></p></blockquote>
<p>A session is retrieved from Hibernate&#8217;s SessionFactory (<code>org.hibernate.SessionFactory</code>) which implements a design pattern that ensures that only one instance of the  session is used per thread. GORM uses this factory to get the session &#8211; and so should you if you ever need the true power of executing raw SQL in your Grails application!</p>
<p>An example of executing SQL yourself:</p>
<pre class="brush: java;">
 	String sql = &quot;some update SQL&quot;
	Session session = sessionFactory.openSession()
 	Connection c = session.connection()
	try {
		try {
			Statement s = c.createStatement()
			s.executeUpdate sql
		}
		catch (all e) {
			log.warn &quot;Error executing statement $sql ($e)&quot;
		}
	}
	finally {
		session.close()
		c.close()
	}
</pre>
<p>Essential is to have the session factory auto-injected into your class, by putting the following somewhere on top:</p>
<pre class="brush: java;">
    def sessionFactory
</pre>
<br />Filed under: <a href='http://tedvinke.wordpress.com/category/grails-groovy/'>Grails &amp; Groovy</a>, <a href='http://tedvinke.wordpress.com/category/web-development/'>Web Development</a> Tagged: <a href='http://tedvinke.wordpress.com/tag/gorm/'>gorm</a>, <a href='http://tedvinke.wordpress.com/tag/grails/'>grails</a>, <a href='http://tedvinke.wordpress.com/tag/hibernate/'>hibernate</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/212/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=212&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2010/07/01/gorm-and-hibernate-session-factory/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>
	</item>
		<item>
		<title>Eclipse &#8220;Initializing Java Tooling&#8221; hangs</title>
		<link>http://tedvinke.wordpress.com/2010/06/21/eclipse-initializing-java-tooling-hangs/</link>
		<comments>http://tedvinke.wordpress.com/2010/06/21/eclipse-initializing-java-tooling-hangs/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 09:28:40 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[SpringSource Tool Suite]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=200</guid>
		<description><![CDATA[Sometimes using SpringSource Tool Suite (STS) e.g. version 2.3.2- which is based on Eclipse &#8211; startup hangs on various operations: Initializing Java Tooling Repository registry initialization STS/Eclipse does not seem to respond to anything &#8211; the UI freezes and that&#8217;s it! I&#8217;ve had this on several occassions with no apparent cause on my part. Usually [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=200&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes using SpringSource Tool Suite (STS) e.g. version 2.3.2- which is based on Eclipse &#8211; startup hangs on various operations:</p>
<blockquote><p>Initializing Java Tooling</p></blockquote>
<blockquote><p>Repository registry initialization</p></blockquote>
<p>STS/Eclipse does not seem to respond to anything &#8211; the UI freezes and that&#8217;s it! I&#8217;ve had this on several occassions with no apparent cause on my part. Usually it has something to do with fiddling with (adding libraries to) the classpath and/or cleaning the project. Some users report Eclipse hangs at &#8220;Initializing Java Tooling&#8221; at 30% for  20-30 secs after which everything continues normally, but I don&#8217;t have  that much luck <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <span id="more-200"></span></p>
<p>I&#8217;ve tried the most suggested actions in forum posts, such a starting STS/Eclipse with the <code>-clean</code> parameter which most of the times doesn&#8217;t work in my configuration. If you inspect the .log files under the workspace&#8217;s .metadata folder you might find something of interest, but quite often STS/Eclipse just hangs without anything written to the log in my case. The largeness of your project or the amount of projects quite often seem to be one of the causes. Here are a few workarounds and/or solutions that might prove succesful:</p>
<ul>
<li>Start a new workspace and import the project back in &#8211; which is just plain tedious and annoying although it quite often works</li>
<li>Close all projects before you exit Eclipse after which Eclipse normally restarts.</li>
<li>Some users have reported it does seem related to a configured Tomcat server instance. If you have this configured a possible workaround instead of reimporting your projects in a new workspace, is to rename the .project file in workspace/Servers, restarting, removing and adding the Server configuration again.</li>
<li>The solution I found &#8211; which seems to work most of the times &#8211; is to remove or rename the <code>.projects</code> folder in <code>.metadata/.plugins/org.eclipse.core.resources</code> in the workspace folder. This doesn&#8217;t seem to affect any project and the .project folder will be recreated when Eclipse restarts.</li>
</ul>
<p>Hopefully someone with this problem saves some time because of this. Ofcourse the real problem needs to be addressed by the guys and girls over at Eclipse.</p>
<br />Filed under: <a href='http://tedvinke.wordpress.com/category/java/'>Java</a> Tagged: <a href='http://tedvinke.wordpress.com/tag/eclipse/'>eclipse</a>, <a href='http://tedvinke.wordpress.com/tag/springsource-tool-suite/'>SpringSource Tool Suite</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=200&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2010/06/21/eclipse-initializing-java-tooling-hangs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>
	</item>
		<item>
		<title>Separating and securing Grails controllers</title>
		<link>http://tedvinke.wordpress.com/2010/06/09/separating-and-securing-grails-controllers/</link>
		<comments>http://tedvinke.wordpress.com/2010/06/09/separating-and-securing-grails-controllers/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 09:12:20 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Grails & Groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[acegi]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=188</guid>
		<description><![CDATA[Fiddling with Acegi, package names and url mappings will make securing a subset of your controllers a breeze.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=188&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to have several Grails controllers automatically secured &#8211; just by name?</p>
<p>I had to make a subset of my Grails 1.2.2 application controllers only available to a certain group of people. A few controllers made actions on the application possible which only Administrators were allowed to do.</p>
<h2>Acegi what?</h2>
<p>So, I think everybody recognizes the ever so popular <a href="http://grails.org/plugin/acegi" target="_blank">Acegi</a> way (using Spring Security) of securing things with a single <code>com.app.controller.HelloController</code> in <code>SecurityConfig.groovy</code>:</p>
<pre class="brush: java;">
security {
	active = true

	useRequestMapDomainClass = false
	requestMapString = &quot;&quot;&quot;
		CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
		PATTERN_TYPE_APACHE_ANT

		/hello/**=ROLE_USER
		/**=IS_AUTHENTICATED_ANONYMOUSLY
	&quot;&quot;&quot;
}
</pre>
<p>This way a login-screen will appear when a user tries to open the <code>HelloController</code> on <code>/hello</code> since ROLE_USER is required. Well, not really high-tech yet &#8211; a basic example you could find in the Acegi plugin&#8217;s documentation as well.</p>
<h2>More&#8230;more controllers!</h2>
<p>Let&#8217;s introduce several other controllers next to the <code>com.app.controller.HelloController</code>. Notice I myself made up the package name <code>com.app.controller</code> &#8211; just a habit to seperate Domain classes, Controllers and Services into <code>com.app.domain</code>, <code>com.app.controller</code> and <code>com.app.services</code>.</p>
<p><span id="more-188"></span>Anyway, see here a package structure with a few new controllers:</p>
<pre class="brush: plain;">
com.app.controller
 \ HelloController.groovy
 \ ImportController.groovy
 \ BackupController.groovy
com.app.domain
 \ User.groovy
 \ Role.groovy
</pre>
<p>Now, it isn&#8217;t surprising that <code>ImportController</code> and <code>BackupController</code> might be used for several system administration functions, such as importing of backing up data &#8211; not to be messed with by regular users! In <code>SecurityConfig</code> we would have to adjust the settings in order to only allow Administrators to do execute these kind of backend-controllers.</p>
<pre class="brush: java;">
security {
	active = true

	useRequestMapDomainClass = false
	requestMapString = &quot;&quot;&quot;
		CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
		PATTERN_TYPE_APACHE_ANT

		/import/**=ROLE_ADMIN
		/backup/**=ROLE_ADMIN
		/hello/**=ROLE_USER
		/**=IS_AUTHENTICATED_ANONYMOUSLY
	&quot;&quot;&quot;
}
</pre>
<p>The problem I had in my development team, was that any developer might be developing some kind of backend or &#8216;administration&#8217; controller &#8211; <strong>without</strong> adding the appropratiate changes in <code>SecurityConfig</code>. Next of all, when the list grows to&#8230;</p>
<pre class="brush: plain;">
/scrub/**=ROLE_ADMIN
/settings/remove**=ROLE_ADMIN
/settings/delete**=ROLE_ADMIN
/run/**=ROLE_ADMIN
/export2/**=ROLE_ADMIN
/another/**=ROLE_ADMIN
/schedule/**=ROLE_ADMIN
/export/**=ROLE_ADMIN
/import/**=ROLE_ADMIN
/backup/**=ROLE_ADMIN
</pre>
<p>&#8230;you&#8217;ll need something more centralized <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I could either use <a href="http://www.grails.org/AcegiSecurity+Plugin+-+Securing+URLs" target="_blank">annotations</a> for each controller at the action or class-level, such as <code>@Secured(['ROLE_ADMIN'])</code>, but then each developer had to remember to add these constructs to each backend-controller instead of adding a requestmap entry in <code>SecurityConfig</code>.</p>
<p><!--more-->Depending on your needs annotations just might be your preferred way of doing this, but I choose to take a less intrusive (and in my opinion more fail-safe) way to separate these controllers from the rest. Here&#8217;s the summary:</p>
<ul>
<li>Move the backend-controllers into a separate package</li>
<li>Have url mappings and <code>SecurityConfig</code> do the crunch work!</li>
</ul>
<h2>Seperate package</h2>
<p>Move the backend controllers to a seperate subpackage e.g. <code>com.app.controller.admin</code>.</p>
<pre class="brush: plain;">
com.app.controller
 \ HelloController.groovy
com.app.controller.admin
 \ ImportController.groovy
 \ BackupController.groovy
com.app.domain
 \ User.groovy
 \ Role.groovy
</pre>
<p>Note that the controllers are still accessible on the original url&#8217;s &#8211; no matter their changed packages! One could still execute <code>domain.com/import</code> to access the <code>ImportController</code>.</p>
<h2>Change url mapping</h2>
<p>In <code>UrlMappings.groovy</code> we have to add a few bits &#8211; mainly I want the backend controllers to be accessible under the /admin url and disallow access on the original ones.</p>
<p>First we make a convenience method inside <code>UrlMappings</code> to locate and list controllers with a certain package name.</p>
<pre class="brush: java;">
/**
 * Returns a list of controller names starting with specified package name.
 *
 * @param packageName The name the controller package should start with
 * @return the names of the controllers
 */
private static def findControllersInPackage(String packageName) {
	def controllers = []
	ApplicationHolder.application.controllerClasses.findAll{ c -&gt; c.packageName.startsWith( packageName ) }.each { c -&gt;
		controllers.add(c.logicalPropertyName)
	}
	return controllers
}
</pre>
<p>&#8230;and second we iterate over these controllers and make them work on our new url and disable them on the original url.</p>
<pre class="brush: java;">
class UrlMappings {
	static mappings = {

		// collect controllers
		def secureControllers = findControllersInPackage(&quot;com.app.controller.admin&quot;)

		// disallow secured controllers on normal url
		&quot;/$controller/$action?/$id?&quot;{
			constraints {
				controller(validator: {
					   return !secureControllers.contains(it)
				})
			}
		}

		// allow secured controllers on secured url
		secureControllers.each { controllerName -&gt;
			&quot;/admin/${controllerName}/$action?/$id?&quot; {
				controller = controllerName
			}

		}

		// errors
		&quot;500&quot;(view:'/error')
	}

	private static def findControllersInPackage(String packageName) {
		//...
	}
}
</pre>
<p>The way we collect the appropriate controllers allows me to even have controllers in sub sub subpackages under <code>com.app.controller.admin</code>. You&#8217;ll find that <code>/import</code> no longer works, but now you can find it under <code>/admin/import </code> &#8211; because of the url mappings disallow the original mappings,  even generated or scaffolded GSP&#8217;s pages (with their <code>createLink()</code>&#8216;s) keep working.</p>
<h2>Secure url</h2>
<p>Well, the only thing left to do, is shorten our <code>SecurityConfig</code> &#8211; securing everything under <code>/admin</code> will make things work nicely for us:</p>
<pre class="brush: java;">
security {
	active = true

	useRequestMapDomainClass = false
	requestMapString = &quot;&quot;&quot;
		CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
		PATTERN_TYPE_APACHE_ANT

		/admin/**=ROLE_ADMIN
		/hello/**=ROLE_USER
		/**=IS_AUTHENTICATED_ANONYMOUSLY
	&quot;&quot;&quot;
}
</pre>
<p>Just instruct your fellow team members to put the appropriate controllers under the right package and they are instantaneously secured <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />Filed under: <a href='http://tedvinke.wordpress.com/category/grails-groovy/'>Grails &amp; Groovy</a>, <a href='http://tedvinke.wordpress.com/category/java/'>Java</a>, <a href='http://tedvinke.wordpress.com/category/web-development/'>Web Development</a> Tagged: <a href='http://tedvinke.wordpress.com/tag/acegi/'>acegi</a>, <a href='http://tedvinke.wordpress.com/tag/grails/'>grails</a>, <a href='http://tedvinke.wordpress.com/tag/linkedin/'>linkedin</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=188&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2010/06/09/separating-and-securing-grails-controllers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>
	</item>
		<item>
		<title>Please enter the correct password for the postgres windows user account</title>
		<link>http://tedvinke.wordpress.com/2010/06/04/please-enter-the-correct-password-for-the-postgres-windows-user-account/</link>
		<comments>http://tedvinke.wordpress.com/2010/06/04/please-enter-the-correct-password-for-the-postgres-windows-user-account/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 08:37:57 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=181</guid>
		<description><![CDATA[I just had a weird case where I reinstalled Windows XP completely clean om my desktop, had to install PostgreSQL (8.4 &#8211; via the &#8220;One Click Installer&#8221;) again and the Postgres installer barfed on the &#8216;postgres&#8217; windows user account. Somehow it believed there already was a &#8216;postgres&#8217; account present &#8211; while I was under the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=181&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just had a weird case where I reinstalled Windows XP completely clean om my desktop, had to install <a href="http://www.postgresql.org" target="_blank">PostgreSQL</a> (8.4 &#8211; via the &#8220;One Click Installer&#8221;) again and the Postgres installer barfed on the &#8216;postgres&#8217; windows user account. Somehow it believed there already was a &#8216;postgres&#8217; account present &#8211; while I was under the impression I was creating a new one: I just did a clean install of Windows right? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<blockquote><p>The password specified was incorrect. Please enter the correct password for the postgres windows user account.</p></blockquote>
<p>Having followed several forum posts, suggesting to restart the PostgreSQL Service or changing the postgres password in the Computer Management MMC, all didn&#8217;t work &#8211; I didn&#8217;t install Postgres yet so there was no service to be found.</p>
<p>To make sure there really was no user present I executed the following at the command line:</p>
<p><code>net user postgres /delete</code></p>
<p>The first time the command returned as succesfully and the 2nd time it stated it couldn&#8217;t find the &#8216;postgres&#8217; user &#8211; meaning the 1st time it <em>was</em> present &#8211; and succesfully deleted. I started the installer again and all went like clockwork!</p>
<br />Filed under: <a href='http://tedvinke.wordpress.com/category/web-development/'>Web Development</a> Tagged: <a href='http://tedvinke.wordpress.com/tag/postgres/'>postgres</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=181&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2010/06/04/please-enter-the-correct-password-for-the-postgres-windows-user-account/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>
	</item>
		<item>
		<title>Trying to reach google.com&#8230;</title>
		<link>http://tedvinke.wordpress.com/2010/04/03/trying-to-reach-google-com/</link>
		<comments>http://tedvinke.wordpress.com/2010/04/03/trying-to-reach-google-com/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 12:21:48 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=163</guid>
		<description><![CDATA[Since several weeks been getting &#8220;Trying to reach google.com&#8230;&#8221; a LOT when editting e.g. a spreadsheet in Google Apps &#8211; causing any updates to the document to get lost. Seemed that I was opening the Google Docs url on HTTP instead of HTTPS. After manually changing the url in the addressbar to https://docs.google.com or https://spreadsheets.google.com [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=163&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since several weeks been getting &#8220;Trying to reach google.com&#8230;&#8221; a LOT when editting e.g. a spreadsheet in Google Apps &#8211; causing any updates to the document to get lost.<br />
<a href="http://tedvinke.wordpress.com/2010/04/03/trying-to-reach-google-com/trying-to-reach-google/" rel="attachment wp-att-164"><img src="http://tedvinke.files.wordpress.com/2010/04/trying-to-reach-google.png?w=207&#038;h=83" alt="" title="trying-to-reach-google" width="207" height="83" class="alignleft size-full wp-image-164" /></a>Seemed that I was opening the Google Docs url on HTTP instead of HTTPS. After manually changing the url in the addressbar to http<strong>s</strong>://docs.google.com or http<strong>s</strong>://spreadsheets.google.com all was fine again! </p>
<br />Filed under: <a href='http://tedvinke.wordpress.com/category/web/'>Web</a> Tagged: <a href='http://tedvinke.wordpress.com/tag/google/'>google</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/163/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=163&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2010/04/03/trying-to-reach-google-com/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>

		<media:content url="http://tedvinke.files.wordpress.com/2010/04/trying-to-reach-google.png" medium="image">
			<media:title type="html">trying-to-reach-google</media:title>
		</media:content>
	</item>
		<item>
		<title>Grails remote jQuery form validation</title>
		<link>http://tedvinke.wordpress.com/2010/03/02/grails-remote-jquery-form-validation/</link>
		<comments>http://tedvinke.wordpress.com/2010/03/02/grails-remote-jquery-form-validation/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 20:27:40 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Grails & Groovy]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=150</guid>
		<description><![CDATA[I recently had to validate a form in my Grails application using jQuery. jQuery has an excellent mechanism to validate a form with certain validation rules. It allows you to prevent form submission if the user input doesn&#8217;t pass the validation attached to the form. Below a simple example HTML snippet to validate a postal [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=150&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently had to validate a form in my Grails application using jQuery. jQuery has an <a href="http://docs.jquery.com/Plugins/Validation">excellent mechanism</a> to validate a form with certain validation rules. It allows you to prevent form submission if the user input doesn&#8217;t pass the validation attached to the form.</p>
<p>Below a simple example HTML snippet to validate a postal code field:</p>
<pre class="brush: java;">
&lt;script type=&quot;text/javascript&quot;&gt;
$(function (){
	$(&quot;#form&quot;).validate({
		rules: {
			'address.postalCode': {
				required: true
			},
		},
		messages: {
			'address.postalCode': {
				required: &quot;Please enter a postal code.&quot;
			}
		}
	});
});
&lt;/script&gt;
&lt;g:form method=&quot;post&quot; action=&quot;register&quot; name=&quot;form&quot;&gt;
	&lt;input type=&quot;text&quot; name=&quot;address.postalCode&quot; id=&quot;postalCode&quot; /&gt;
	&lt;input type=&quot;submit&quot; value=&quot;Proceed&quot; /&gt;
&lt;/g:form&gt;
</pre>
<p>As you can see: a simple &#8216;required&#8217; rule is specified for field with name address.postalCode and errormessage to go with it. Notice that special field names e.g. with a dot requires a notation <a href="http://docs.jquery.com/Plugins/Validation/Reference#Fields_with_complex_names_.28brackets.2C_dots.29">with quotes around it</a>.</p>
<p>Now, let&#8217;s say we need to validate the postal code on the server side for validity and still need to have the form validation performed by jQuery &#8211; and not inside the controller and returing some kind of error- or flash message. Use the <strong>remote </strong>rule!</p>
<p>As the <a href="http://docs.jquery.com/Plugins/Validation/Methods/remote#options">documentation</a> states:</p>
<blockquote><p>The serverside resource is called via $.ajax (XMLHttpRequest) and gets a key/value pair, corresponding to the name of the validated element and its value as a GET parameter. The response is evaluated as JSON and must be true for valid elements, and can be any false, undefined or null for invalid elements, using the default message; or a string, eg. &#8220;That name is already taken, try peter123 instead&#8221; to display as the error message.</p></blockquote>
<p>We create a controller which does such a thing: check the submitted postal code, verify it against some kind of backend service or database table and return the expected JSON return values.</p>
<p>E.g. let&#8217;s expand our form HTML with the following:</p>
<pre class="brush: java;">
&lt;script type=&quot;text/javascript&quot;&gt;
	$(function (){
		$(&quot;#form&quot;).validate({
			rules: {
				'address.postalCode': {
					required: true,
					remote: {
						url: &quot;${createLink(controller:'postalCode', action:'validate')}&quot;,
						type: &quot;post&quot;,
						data: {
							postalCode: function() {
								return $(&quot;#postalCode&quot;).val();
						  }
						}
					  }
				},
			},
			messages: {
				'address.postalCode': {
					required: &quot;Please enter a postal code.&quot;,
					remote: &quot;Please enter a valid postal code.&quot;
				}
			}
		});
	});
&lt;/script&gt;
&lt;g:form method=&quot;post&quot; action=&quot;register&quot; name=&quot;form&quot;&gt;
	&lt;input type=&quot;text&quot; name=&quot;address.postalCode&quot; id=&quot;postalCode&quot; /&gt;
	&lt;input type=&quot;submit&quot; value=&quot;Proceed&quot; /&gt;
&lt;/g:form&gt;
</pre>
<p>As you can see, the remote rule specifies a resource which is one of our <em>controllers </em>and a specified <em>action</em>. As data for our Grails action we pass along the current value of the post code field &#8211; using the &#8216;data&#8217; block with a function.</p>
<p>Our <strong>PostalCodeController </strong>may have the following <em>validate </em>action:</p>
<pre class="brush: java;">
class PostalCodeController {

	def postalCodeService

	def validate = {
		String pc = params.postalCode

		String result = &quot;false&quot;
		if (postalCodeService.checkPostalCode(pc)) {
			result = &quot;true&quot;
		}

		response.setContentType(&quot;text/json;charset=UTF-8&quot;);
		render result
	}
}
</pre>
<p>Voila! We validate our data (which we simply read from the <em>params</em>) en return a string &#8220;true&#8221; if it&#8217;s valid else &#8220;false&#8221;. </p>
<p>Upon form submission our action is called and the outcome is used by jQuery to validate the user data! I couldn&#8217;t get my response rendered via the usual <a href="http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.1.8%20More%20on%20JSONBuilder">Grails JSON builder</a> which seems to have trouble with single values (such as &#8220;true&#8221; or &#8220;false&#8221;), but set the content type directly. You might want to send additional caching headers along with the JSON response to prevent browser caching, but that&#8217;s all left as an excercise for the reader.</p>
<br />Filed under: <a href='http://tedvinke.wordpress.com/category/grails-groovy/'>Grails &amp; Groovy</a>, <a href='http://tedvinke.wordpress.com/category/web-development/'>Web Development</a> Tagged: <a href='http://tedvinke.wordpress.com/tag/grails/'>grails</a>, <a href='http://tedvinke.wordpress.com/tag/jquery/'>jQuery</a>, <a href='http://tedvinke.wordpress.com/tag/json/'>JSON</a>, <a href='http://tedvinke.wordpress.com/tag/linkedin/'>linkedin</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/150/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=150&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2010/03/02/grails-remote-jquery-form-validation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>
	</item>
		<item>
		<title>Grails Testing Plugin Log Mocking</title>
		<link>http://tedvinke.wordpress.com/2009/09/02/grails-testing-plugin-log-mocking/</link>
		<comments>http://tedvinke.wordpress.com/2009/09/02/grails-testing-plugin-log-mocking/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 12:03:23 +0000</pubDate>
		<dc:creator>Ted Vinke</dc:creator>
				<category><![CDATA[Grails & Groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://tedvinke.wordpress.com/?p=137</guid>
		<description><![CDATA[I&#8217;m a big fan of the famous Grails Testing Plugin, which is used to mock domain classes, controllers and many more things usually needed in my unit tests for Grails.  Here&#8217;s a quick example from its documentation: Recently in a Grails 1.0.5 project I had to unit test a service method. Because of several &#8220;log&#8221; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=137&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a big fan of the famous <a href="http://grails.org/Testing+Plugin" target="_blank">Grails Testing Plugin</a>, which is used to mock domain classes, controllers and many more things usually needed in my unit tests for Grails.  Here&#8217;s a quick example from its documentation:</p>
<pre class="brush: java;">
class BookTests extends GrailsUnitTestCase {
 void testConstraints() {
 def existingBook = new Book(title: &quot;Misery&quot;, author: &quot;Stephen King&quot;)
 mockForConstraintsTests(Book, [ existingBook ])

 // Validation should fail if both properties are null.
 def book = new Book()
 assertFalse book.validate()
 assertEquals &quot;nullable&quot;, book.errors[&quot;title&quot;]
 assertEquals &quot;nullable&quot;, book.errors[&quot;author&quot;]

 // So let's demonstrate the unique and minSize constraints.
 book = new Book(title: &quot;Misery&quot;, author: &quot;JK&quot;)
 assertFalse book.validate()
 assertEquals &quot;unique&quot;, book.errors[&quot;title&quot;]
 assertEquals &quot;minSize&quot;, book.errors[&quot;author&quot;]

 // Validation should pass!
 book = new Book(title: &quot;The Shining&quot;, author: &quot;Stephen King&quot;)
 assertTrue book.validate()
 }
}
</pre>
<p>Recently in a Grails 1.0.5 project I had to unit test a service method. Because of several &#8220;log&#8221; statements, I had the dreaded</p>
<pre><code>groovy.lang.MissingPropertyException:
No such property: log for class:  SubscriptionService</code></pre>
<p>Fortunately, the testing framework has the excellent mock Logging() method in place for that, which provides a mock implementation of the &#8220;log&#8221; property for the given class, in my case SubscriptionService. Here&#8217;s how I created my setUp() method:</p>
<pre class="brush: java;">
void setUp() {
 mockLogging(SubscriptionService.class, true)
}
</pre>
<p>This resulted in</p>
<p><code>java.lang.NullPointerException:<br />
Cannot invoke method containsKey() on null  object</code></p>
<p>It was a NPE on the following part inside GrailsUnitTestCase.groovy:</p>
<pre class="brush: java;">
protected void registerMetaClass(Class clazz) {
 // If the class has already been registered, then there's
 // nothing to do.
 if (savedMetaClasses.containsKey(clazz)) return
...
</pre>
<p>After some digging around, it almost seemed to trivial to fix thix. Just add called the super&#8217;s setUp() first.</p>
<pre class="brush: java;">
void setUp() {
 super.setUp()
 mockLogging(SubscriptionService.class, true)
}
</pre>
<p>Happy mocking!</p>
<br />Posted in Grails &amp; Groovy, Java Tagged: logging, mock, testing <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tedvinke.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tedvinke.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tedvinke.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tedvinke.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tedvinke.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tedvinke.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tedvinke.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tedvinke.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tedvinke.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tedvinke.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tedvinke.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tedvinke.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tedvinke.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tedvinke.wordpress.com/137/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tedvinke.wordpress.com&amp;blog=6557354&amp;post=137&amp;subd=tedvinke&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://tedvinke.wordpress.com/2009/09/02/grails-testing-plugin-log-mocking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0162e4fc0714206d466b196acc7cb3ea?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Teddy</media:title>
		</media:content>
	</item>
	</channel>
</rss>
