Unit Test Patterns: The Domain Test Values Class
December 20, 2010
On my latest Java project, my colleagues and I are keen to improve the readability of test classes. We’ve chosen to use Mockito and Hamcrest because of their natural language approach to mocking and assertions, but on their own they can’t always convey the meaning of values used in a test.
To overcome this, we use a pattern which I’ll call the “Domain Test Values Class”, the purpose of which is to provide values used in the testing of a domain in a way which improves understanding of test code by increasing readability and adding meaning to values.
Read the rest of this entry »
Redirecting to .com (without confusing CloudFoundry…)
September 26, 2010
It’s a two-for-one today – a “gotcha” and a “how to” all rolled into one, this time about redirecting in a Grails filter.
Much like my favicon woes my initial attempt to redirect to a primary domain (a .com without the “www” prefix) had some unexpected consequences when deployed to a live server on CloudFoundry – I started getting warnings that my site had gone down!
In this post I’ll hopefully save you the panic of CloudFoundry telling you that your site’s not responding when you try to rationalise your domain names!
Read the rest of this entry »
When localhost is not the same as 127.0.0.1 a MySQL Connection Gotcha
September 13, 2010
Setting up MySQL connection pooling has been standard stuff in server-side apps for as long as I’ve been writing them, so I was at a loss when, every 5 days or so, my newly deployed app died with this exception:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago.
Spring Secutiry (ACEGI) Plugin and Favicon Permissions
September 6, 2010
Here’s a quick gotcha for you. You set up a favicon in the root of your web app, as is the convention, and when you log in you are redirected to a picture of your favicon or you are asked to download it… Weird.
Odds on you’ve installed the Spring Security plugin and forgotten to give permission to the favicon file in the root and the result is that on login Spring Security redirects you to the first restricted item that was requested by the browser – the favicon.
The solution? Easy, set the favicon path to IS_AUTHENTICATED_ANONYMOUSLY in your SecurityConfig.groovy (or database):
controllerAnnotationStaticRules = [
...
'/favicon.ico' : ['IS_AUTHENTICATED_ANONYMOUSLY'],
...
]
Handling Embedded Fonts in the Grails UI-Performance Plugin
August 31, 2010
I’ve been waiting for the time to give Burt Beckwith’s fantastic UI-Performance plugin a proper post, but it looks like it’s not going to happen any time soon so I thought some of you might find this tip for getting the plugin to cache font files, along with images and css, useful.
Read the rest of this entry »
Upgrading Grails from 1.2.2 to 1.3.1
June 16, 2010
The usually simple upgrade process in Grails has caused me a few headaches in moving from 1.2.2 to 1.3.1. I skipped the 1.3 upgrade because there were a few people having issues on the mailing list but yesterday I bit the bullet and encountered a couple of problems.
I think the release notes for Grails 1.3.x have been unusually poor so this post has the issues I’ve encountered in the hope that you won’t go quite as mad as I have. I’ll keep it updated if I find more problems. Read the rest of this entry »
Forcing No Selection on a Grails datePicker
April 14, 2010
I just came across this problem using the datePicker tag in a gsp – it appeared that there was no way to stop the tag showing today’s date when no value was set on the bean. Read the rest of this entry »
Sending email asynchronously is an essential part of most Web applications and there are many ways in which to implement it. In this post I’ve chosen to demonstrate how to set up JMS, ActiveMQ and Gmail with the Grails Mail plugin to provide asynchronous email capabilities while only having to write a few lines of code, all thanks to some great plugins. I’ll also show the fantastic Grails Mail templating feature which uses GSP views to generate HTML emails along with a solution for one of the big bugs with it too!
Simple Aspects using Annotations in Grails
March 15, 2010
Aspect Oriented Programming is a concept which will be familiar to users of the Spring Framework as one of its core features. However, the details of how to get AOP working in Grails appear thin on the ground, so in this post I will show how to set up a simple aspect then configure and apply it using attributes. I will assume some familiarity with Spring AOP so I won’t explain the terminology or general concepts since they are exactly the same in Java as they are in Grails. Read the rest of this entry »
Following on from my post on how to log in a user using the Grails Acegi/Spring Security plugin I stumbled into a new use for the same code when I tried to update a user’s own details while logged in. The security plugin caches the user’s domain object so any changes are not seen until the next login (wholly unhelpful when you’re trying to implement account management on a Website!).