<?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>Xebia Blog &#187; Albert Sikkema</title>
	<atom:link href="http://blog.xebia.com/author/asikkema/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xebia.com</link>
	<description>Software development done right!</description>
	<lastBuildDate>Wed, 01 Feb 2012 00:30:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Making screenshots from Selenium with JUnit @Rule&#8217;s</title>
		<link>http://blog.xebia.com/2010/03/30/making-screenshots-from-selenium-with-junit-rules/</link>
		<comments>http://blog.xebia.com/2010/03/30/making-screenshots-from-selenium-with-junit-rules/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 19:03:45 +0000</pubDate>
		<dc:creator>Albert Sikkema</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tools]]></category>

	<!-- AutoMeta Start -->
	<category></category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=4338</guid>
		<description><![CDATA[When running Selenium tests from JUnit it&#8217;s very useful to be able to capture screenshots when something fails. Especially when you run it in a Continuous Integration environment which you aren&#8217;t monitoring. A screenshot combined with the stacktrace makes identifying and fixing the error easier. When you combine this with a JUnit @Rule you can [...]]]></description>
			<content:encoded><![CDATA[<p>When running <a href="http://seleniumhq.org/">Selenium</a> tests from JUnit it&#8217;s very useful to be able to capture screenshots when something fails. Especially when you run it in a <a href="http://martinfowler.com/articles/continuousIntegration.html">Continuous Integration</a> environment which you aren&#8217;t monitoring. A screenshot combined with the stacktrace makes identifying and fixing the error easier. When you combine this with a<a href="http://blog.xebia.com/2009/10/23/junit-4-7-rules/"> JUnit @Rule</a> you can make it transparant and use it for every testcase<span id="more-4338"></span></p>
<p><strong>Implementing the @Rule</strong><br />
For implementing rules you need to implement the MethodRule interface and implement the apply method. The base.evaluate method invokes the unittest. The screenshot is made in case of any exception which is re-thrown as a RuntimeException so that your testcase will fail. This class extends the SeleneseTestBase which helps you writing selenium unit tests. Capturing screenshots is a feature of selenium and is very easy. You might want to store the file differently, but that should be easy.</p>
<pre class="brush: java; title: ; notranslate">
public class CapturingSelenium extends SeleneseTestBase implements MethodRule {

    @Override
    public Statement apply(final Statement base, FrameworkMethod method, Object target) {
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                try {
                    setUp(&quot;http://localhost:8080/&quot;, &quot;*firefox&quot;);
                    base.evaluate();
                }
                catch (Exception e) {
                    selenium.captureEntirePageScreenshot(&quot;/tmp/selenium-error-&quot; + new UUID().toString() + &quot;.PNG&quot;, &quot;&quot;);
                    throw new RuntimeException(e);
                }
            }
        };
}
</pre>
<p>That&#8217;s it. Now you can just use the CapturingSelenium class and annotate it with @Rule. When any test fails with an exception the rule catches it and captures a screenshot of the browser at the time of the exception. Here&#8217;s a basic example:<br />
Usage:</p>
<pre class="brush: java; title: ; notranslate">
public class SeleniumTest {

    @Rule
    private CapturingSelenium selenium = new CapturingSelenium();

    @Test(expected=RuntimeException.class)
    public void shouldCaptureScreenshotWhenFailing() throws Exception {
        selenium.open(&quot;http://localhost/myapp/home&quot;);
        selenium.click(&quot;some-button-which-is-not-there&quot;);
        //...
    }
}
</pre>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2010/03/30/making-screenshots-from-selenium-with-junit-rules/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2010%2F03%2F30%2Fmaking-screenshots-from-selenium-with-junit-rules%2F&amp;title=Making%20screenshots%20from%20Selenium%20with%20JUnit%20%40Rule%26%238217%3Bs" id="wpa2a_2"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2010/03/30/making-screenshots-from-selenium-with-junit-rules/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JPA implementation patterns: Using UUIDs as primary keys</title>
		<link>http://blog.xebia.com/2009/06/03/jpa-implementation-patterns-using-uuids-as-primary-keys/</link>
		<comments>http://blog.xebia.com/2009/06/03/jpa-implementation-patterns-using-uuids-as-primary-keys/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 19:58:28 +0000</pubDate>
		<dc:creator>Albert Sikkema</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JPA Implementation Patterns]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[JPA implementation patterns]]></category>

	<!-- AutoMeta Start -->
	<category></category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=1856</guid>
		<description><![CDATA[Continuing Vincent Partington&#8216;s blog series about JPA implementation patterns, I would like to add the following The default way in JPA for primary keys is to use the @GeneratedValue annotation with the strategy attribute set to one of AUTO, IDENTITY, SEQUENCE, or TABLE. You pick the most appropriate strategy for your situation and that&#8217;s it. [...]]]></description>
			<content:encoded><![CDATA[<p><em>Continuing <a href="/author/vpartington">Vincent Partington</a>&#8216;s blog series about <a href="/category/jpa/implementation-patterns/">JPA implementation patterns</a>, I would like to add the following </em></p>
<p>The default way in JPA for primary keys is to use the <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/GeneratedValue.html"><tt>@GeneratedValue</tt></a> annotation with the strategy attribute set to one of <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/GenerationType.html#AUTO"><tt>AUTO</tt></a>, <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/GenerationType.html#IDENTITY"><tt>IDENTITY</tt></a>, <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/GenerationType.html#SEQUENCE"><tt>SEQUENCE</tt></a>, or <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/GenerationType.html#TABLE"><tt>TABLE</tt></a>. You pick the most appropriate strategy for your situation and that&#8217;s it.<br />
But you can also choose to generate the primary key yourself.<br />
<span id="more-1856"></span><br />
Using <a href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier">UUIDs</a> for this is ideal and has some great benefits. In our current project we&#8217;ve used this strategy by creating an abstract base class our entities to inherit from which takes care of dealing with primary keys.</p>
<pre lang="java">@MappedSuperclass
public abstract class AbstractBaseEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private String id;

	public AbstractBaseEntity() {
		this.id = UUID.randomUUID().toString();
	}

	@Override
	public int hashCode() {
		return id.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof AbstractBaseEntity)) {
			return false;
		}
		AbstractBaseEntity other = (AbstractBaseEntity) obj;
		return getId().equals(other.getId());
	}
}</pre>
<p>Using UUIDs versus sequences in general has been widely discussed on the web, so I won&#8217;t go into too much detail here. But here are some pro&#8217;s and con&#8217;s:</p>
<h3>Pros</h3>
<ul>
<li>Write this base class once and every entity gets an Id for free. If you implement equals and hashcode as above you also throw that one in as a bonus.</li>
<li>UUID are Universal Unique(what&#8217;s in a name). This means that you get great flexibility if you need to copy/merge records from location a to b without having to re-generate keys. (or use complex sequence strategies).</li>
<li>UUIDs are not guessable. This means it can be safer to expose them to the outside world in let&#8217;s say urls. If this would be good practice is another thing.</li>
</ul>
<h3>Cons</h3>
<ul>
<li>Performance can be an issue. See http://johannburkard.de/blog/programming/java/Java-UUID-generators-compared.html, Some databases don&#8217;t perform well with UUIDs (at least when they are stored as strings) for indexes.</li>
<li>Ordering, Sorting. Speaks for itself.</li>
<li>JPA specific: you cannot test if a record has already been persisted by checking if the Id field has been set. One might argue if you need such checks anyway.</li>
</ul>
<h3>Conclusion</h3>
<p>UUIDs are easy to use, but wouldn&#8217;t it be nice if the JPA spec would open up to include UUID as a strategy? Some JPA implementations, like Hibernate, already have support for this:</p>
<pre lang="java">@Id @GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid",
  strategy = "uuid")</pre>
<p><strong>For a list of all the JPA implementation pattern blogs, please refer to the <a href="/2009/07/13/jpa-implementation-patterns-wrap-up/">JPA implementation patterns wrap-up</a>.</strong></p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2009/06/03/jpa-implementation-patterns-using-uuids-as-primary-keys/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2009%2F06%2F03%2Fjpa-implementation-patterns-using-uuids-as-primary-keys%2F&amp;title=JPA%20implementation%20patterns%3A%20Using%20UUIDs%20as%20primary%20keys" id="wpa2a_4"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2009/06/03/jpa-implementation-patterns-using-uuids-as-primary-keys/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.xebia.com/author/asikkema/feed/ ) in 0.48703 seconds, on Feb 9th, 2012 at 4:19 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 9th, 2012 at 5:19 pm UTC -->
