Grails 3.3 Unit Tests (when you’re used to Grails 2.4)

I’ve spent some of this weekend migrating an old Grails 2.0 application to Grails 3.3. It went pretty well. I created a new project and then copied domain, controller and service classes over. There is still some work to do, migrating tests and refactoring code to use the asset pipeline.

Here I share what I’ve learned about the changes between unit tests in Grails 2.4 and 3.3.

  1. IntelliJ IDEA 16 doesn’t properly support Grails 3.3 yet
  2. Grails 2.4 and 3.3 on the same machine sometimes collide
  3. Domain/service mocking has changed since 2.4

Intellij IDEA Support

I’ve run in to problems running tests in another project. The tests run just fine from the command line, but not in IDEA. With further reading last night I found that IDEA fails to add “-integration” or “-unit” to the run/debug configuration commands. This results in Grails reporting no tests found. It should look like something like test-app AreaControllerSpec -echoOut -unit.

Once I added this the test ran but be aware that IDEA continues to report “Test framework quit unexpectedly” in all cases. If you ignore this, and perhaps use the very pretty HTML formatted reports, you can make progress.

Grails 2.4/3.3 Conflict

The main project that I’m working on is 2.4. When I tried to run the tests from the command line (as noted above) but they failed to even start, reporting missing dependencies (junit-dep and cglib-nodep).

 :: junit#junit-dep;4.10: not found
 :: cglib#cglib-nodep;2.2.2: not found

The found that the tests needed to be run from within IDEA.

Domain/Service Mocking

A key test that I have migrated is a controller integration test in the 2.0 project. I copied the methods over to a unit test and then needed to mock the domain objects and the services that were called by the controller. (The examples on the Grails documentation website didn’t show how to do this; how unrealistic is it to give an example with no reference to services?) Notice the lack of @Mock annotations.

import grails.testing.gorm.DataTest
import grails.testing.web.controllers.ControllerUnitTest
import org.grails.testing.GrailsUnitTest
import spock.lang.Specification

class AreaControllerSpec extends Specification implements
 ControllerUnitTest<AreaController>, DataTest, GrailsUnitTest {
def setup() {
    defineBeans {
    mockDomains Area, Company


One useful link is this commit on GitHub. It’s not exactly readable but it gives the changes implemented to arrive at the new testing framework.


Flattr this!

Trianco Aztec Boiler Issues

An unusual topic for my blog, but it offers something of a solution on an issue that has caused me to do work.

Our central heating at home is all electric. The boiler is a recently installed (May 2016) Trianco Aztec Classic. We had a major issue with it post installation, it was leaking badly and the heat exchanger needed replacing. We subsequently discovered that it was continuing to leak, though not as badly, and a seal was replaced on May 2017. (Given that it is also expensive to run my advice is to avoid them if possible.)

Last weekend it started to exhibit a new behaviour; it would stop heating. Rather like the magic porridge pot, even though the thermostat was not calling for heat the boiler was providing it. I’m rather hoping that this was the first time it’s done this otherwise my electricity bill will be astronomical!

The problem with this is that you can’t (shouldn’t) just turn the boiler off. Usually when the thermostat indicates that temperature has been achieved the boiler shuts off but the pump continues to run, ensuring that there isn’t a boiler full of hot water just sat there. My solution was to reduce the radiator temperature (front button controls on the boiler) to the minimum, let it run for a few minutes and then kill it.

So now the joy of getting it fixed.

I rang the service company and spoke to them. I suggested that any repair should be made under warranty, given the unit’s age and problem history. They said that it didn’t sound like a boiler problem, but rather a thermostat problem and asked if I’d changed the batteries. I knew that this was utter rubbish.

I’d already checked that the thermostat relay was “clicking” when I changed the temperature up and down to make it switch. Also it would be extraordinarily bad design to have it fail switched on if the batteries ran flat – it makes no sense. Not only that I’d had the cover off the boiler and checked the call/no-call operation with my meter.

I humoured them, as you have to, and rang back the next day to confirm that changing the batteries had made no difference. They said they’d have to call out, but that would be a £95 plus VAT charge.

So when I got home that evening I took the front off the boiler again and had a fresh look at it. I even referred to Trianco’s manual for troubleshooting guidance. Oddly it doesn’t cover this situation.

I double checked the wiring, mainly checking for cables that perhaps hadn’t been properly secured into plug blocks and had lost connection over time. Nothing.

Then I noticed a variable resistor on the front edge of the control board. It doesn’t seem to be referred to in the manual, but it is the only adjustable component on the board. It’s adjusted with a flat blade screwdriver. I noted the setting, adjusted off that position and then back, and then fired up the boiler. This fixed the problem.

I can only imagine that over time the wiper had formed a “dry joint” against the element, perhaps not helped by the early leaking which would have led to high humidity. I guess that it provides a balance that prevents the thermostat from triggering the call relay.

A final safety note. If you’re not confident with electrical work you should open up your boiler. If you do then be sure to properly isolate it at the switch and also at the consumer unit.

Flattr this!

Ubuntu Annoyances

I’ve always been a RedHat man myself. Since around RedHat 3 I’ve run with that, and then Fedora, on my laptop and RedHat/CentOS on my servers.

At work Ubuntu is the choice and so that’s what I’m using there. I have recently found a few annoyances though, that I’ve not come across with RedHat/Fedora.

/boot fills up

It seems that with the default installation of both 12.04 LTS and 14.04 LTS versions the boot partition fills up over time (less than twelve months). The system installs updated versions of the kernel and related files. This continues until the partition is out of space.

I had to Google to find the fix, as root on the command line:

  • determine which kernel version is running with uname -r
  • delete the unused files from /boot
  • prevent this from happening in future with apt-get autoremove
  • you’ll probably need to run apt-get -f install to clean things up

I’ll be checking back on the servers to make sure that I really have fixed the problem.

Upgrade requires interaction

Yesterday/last night I decided to take the plunge and update my desktop machine from Ubuntu 12 to 14. I set it going and it warns that it can take hours. I expect that. When I checked back after a while there was a dialog asking if a file should be replace. Such prompts popped up a few times during the process. This sucks!

With Fedora you set the process running, come back in the morning and it’s done.

Flattr this!

VM HD Resize

vm-setupI had a small virtual machine (Ubuntu 12, Virtual Box) being hosted on a headless server. It had an 8Gb drive which I needed to resize.It’s done now, but took more googling than it should have done. Here’s a summary.

  1. Stop the virtual machine
  2. Copy the .vmdk to the workstation
  3. Copy the .vmdk to a .vdi
  4. Resize the .vdi
  5. Attach the .vdi (in place of the .vmdk)
  6. Boot to gparted
  7. Create a swap partition
  8. Extend sda2 to fill the unallocated space
  9. Extend sda5 to fill the partition
  10. Reboot
  11. Extend the logical volume
  12. Resize the filing system
  13. Move the swap partition
  14. Shutdown the machine (test)
  15. Copy the .vdi back to the host server
  16. Detach the existing drive
  17. Attach the new drive
  18. Restart the virtual machine

Steps 1 to 4

As the host server is headless I wanted to do as much of the work as possible on my workstation. I originally created the vm on my machine and copied it over to the host, so only needed to copy the disk image back over. You might need to copy the whole machine (folder) over to your workstation. To stop the vm ssh on to it and sudo shutdown -h now.

Once the .vmdk is copied back to the workstation you can use the graphical VM VirtualBox Manager to copy the drive image to a .vdi. I then resized it on the command line with

VBoxManage modifyhd vm-disk1.vdi --resize 51200

Then using the manager app I detached the .vmdk and attached the .vdi drive. I also set the optical drive to my gparted iso.

Steps 5 to 9

Now start the vm. It should boot to gparted. I went to the command line and then ran startx. I found that trying to boot to X didn’t work. Start the gparted app. Start be deactivating the active drives. I then added an 8Gb swap partition (sda3) at the end of the space before resizing the extended partition (sda2). (A dedicated swap partition is not necessary. Ubuntu seems to use a file on the drive. I’m used to CentOS and I’ve always seen swap on it’s own partition. For a vm I can’t see that it makes any difference.)

I applied the changes after the extended partition had been extended. Then deactivate the drives again and extend the LVM partition (sda5) to fill the now available space. Apply changes. Then shutdown the machine and unmount the gparted iso.

Steps 10 to 15

Now reboot the vm and working it’s command line first extend the logical volume

lvextend -l +100%FREE vm-vg/root

then the filing system

resize2fs /dev/vm-vg/root

If you have taken the opportunity to move the swap partition then turn off swap and mark the new partition as swap

swapoff -a
mkswap /dev/sda3

At this point edit (sudo) /etc/fstab and tell it that swap is now /dev/sda3. Then turn swap back on with

swapon /dev/sda3

Now shutdown the machine. At this point you might want to ensure that it starts okay. I suffered kernel panics a few times; not sure why, perhaps swap was misconfigured). Once you’re happy copy the .vdi drive image back over to the host server.

Steps 16 to 18

Now ssh on to the host server and detach/attach drives. (Not sure about the portcount switch; this worked but gave a slightly different configuration from the original.)

VBoxManage storagectl vm --name vm-disk1.vdmk --detach
VBoxManage storagectl vm --name SATA --add sata --controller IntelAhci --portcount 30 --bootable on
VBoxManage storageattach vm --storagectl SATA --medium vg-disk1a.vdi --port 1 --nonrotational on --type hdd

Finally restart the vm

VBoxManage startvm vm --type headless

Job done.

Flattr this!


I post this because, as I continue to learn Goovy/Grails, I keep getting stuck on stupid problems that should be simple.

I needed to count the number of items in a nested collection. I thought that the Groovy spread operator would give me the solution, but it didn’t. At work I just went for the easy option of nested each construction incrementing a counter. Messy, but I really don’t have time to dick around and it gave me a working solution.

So this evening I spent some time on the problem and discovered this, perhaps obvious, easy solution. The unit test below illustrates this.

import spock.lang.*
import grails.test.mixin.*

@Mock([Employee, Company, CompanyGroup])
class CompanyGroupSpec extends Specification {

	void "Test spread"() {
		when: "We have a group of companies with employees"
		Employee alice = new Employee(employeeName: 'Alice')
		Employee bob = new Employee(employeeName: 'Bob')
		Company acme = new Company(companyName: 'Acme')
		Employee claire = new Employee(employeeName: 'Claire')
		Employee dave = new Employee(employeeName: 'Dave')
		Company bravo = new Company(companyName: 'Bravo')
		CompanyGroup group = new CompanyGroup(groupName: 'Super Group')
		then: "spread gives unexpected results"
		acme.employees.size() == 2
		bravo.employees.size() == 2
		group*.companies*.employees.size() == 1
		group*.companies*.employees.flatten().size() == 4

As you can see, I want a count of the number of employees in all companies in the group. I expected four. If the map isn’t flattened then I end up with a count of outer container, which is always one.

I hope this snippet has saved you enough time to treat yourself to a coffee :-)

Flattr this!


One would hope that playing/managing music on an Android device would be easy, but it’s broken. Here’s why…

I have a lovely HTC One (M8). For those that don’t know, it has forward facing speakers and can play music really loud. I’ve found that it’s now the main way that I listen to music. It also features a micro SD card. When I got it I copied my music collection to the card so I could listen to anything anywhere. But then I started to discover failings; artificial barriers put in place by Amazon and Google.


I usually buy my music from Amazon. With my previous phone I didn’t much care where it stored the music. It only had internal phone storage. With this phone I want to keep all of my music together on the SD Card. Well, you can’t to that. The Amazon app will only store music to the phone memory. It’s also stored in protected folders, so moving it isn’t an option.

You can though download the music on you laptop and then move it to the SD Card. Amazon used to limit downloads to track at a time on the (Linux) desktop. They seem to have recently increased this to 24 tracks at a time, but that didn’t seem to work. Must recently I found that I had to download each track to the Downloads folder then create folders/move files in my Music folder. Good work Amazon!

(A warning about the Amazon MP3 Android app; it chews up loads of mobile data even if you don’t use it. Last month it was around 50Mb, which pushed me over my monthly allowance. I’ve disabled the app now.)

Google Play Music

So yesterday I thought I’d try buying music from Google’s Play Music store. I’d noted that the Play app does allow you to set the SD card as the storage device. However, much to my annoyance I found that it’s not stored in the Music folder. It’s stashed away in a folder that Google’s app can access but others can’t. Not only that, the tracks are stored in a flat folder with numeric names. Thanks Google, that’s pretty mean spirited of you.

Now, I could just use the Play Music app to play my music but it niggles me. It insists on opening to the Instant Mix screen and, I imagine, it probably reports everything that I listen to back to Google. (I don’t mind sharing data with Google, but even I have limits.)

As with music purchased from Amazon, I can download the music from Google to my laptop. This does work quite well under Linux, there’s a program that does a proper job of downloading to my Music folder.

So I’ve now downloaded recent purchases to my laptop and copied them to the micro SD card. I’ve also deleted the Amazon downloads from the internal phone storage and deleted the Google downloads from the secret “Google only” folder. The result is that I can now use HTC’s music player for everything.



Flattr this!

Android Preferences
(and Library Projects)

I’ve been battling with preferences in Android, on and off, since November 2013.

I wrote an app, Pit Board, and at the time split the preferences into two dialog boxes. A simple one for the message text and colour and an more complex one for animation styles and timings. I just created these in dialogs and thought nothing of it.

The animation styles I stored the style as an integer and the animation speed as a long value. I can then use ‘switch’ for the animation style and directly use the long value for the animation. Android preferences allow the storage of these types of variable.

With further development/reading I then wanted to replace my dialog box with a standard PreferenceFragment, which should reduce the work that I do as it automatically stores the values. A change listener can then be used in the activity.

BUT! The standard preference classes don’t have anything for an integer backed list or a way to store long values. Not only that, when setting default values in XML there is no support for long values. As a result I have had to write classes to handle those, and the long values one is a kludge as it stores the defaults as integers.

Library Projects

Obviously, having taken the time to write these I want to be able to share them across apps. At first I tried to put them in a different package (a parent to those that I was for my apps) but this causes problems when compiling. Lots of errors about not finding resources (the R class).

Reading more it seems that projects can be defined as libraries and these can be incorporated at compile time. I set about moving the preferences (and another useful class) to “utils” this morning on the train. Poor internet access can be very frustrating! I studied the examples in the TicTacToe app, but got nowhere. When I tried to compile the project it failed to find the classes that I’d moved to the utility library.

I worked on it on the way home and made the same amount of progress. Once home I googled further and found a useful post which held the secret line that fixed it!

I’d already updated the project, but I hadn’t included the “--library relative/path/to/library/project” bit. When I look at the files I can’t just see what it altered, but it compiles now. (I’d already added the library reference to and even fixed the capitalisation!)

Flattr this!


I thought it would be useful to do a short post about Creative Commons, what it is and why I use it.

Creative Commons (CC) allows others to use the photos that I’ve taken without the need to ask permission. It also allows me to place restrictions on how the photos are used, should I wish to do so. The only requirement that applies to all of the variations of the CC licence is that attribution is given. That is, if you use my photos then you must credit me.

By default I share my photos under the “Attribution-ShareAlike” variation. This means that not only can you reuse my photos as they are, but that you are free to use them as a basis for other works – so long as you then share that work under the same licence.

I have considered the use of more restrictive licences (and occasionally need to use such) but this version has been pretty much problem free since February 2009 when I started using it.


Why do you even bother sharing your photos? It’s effort right?

To my mind there is little/no point in taking photos if they don’t get seen. I’m old enough to remember when photographs were printed on paper. I have a large collection of them. They’re in the Boots cardboard folders, in a box, under the stairs. Sad!

Why don’t you charge for them and become rich?!

Because as soon as you get paid for something it becomes a job. You have to deliver something of value in exchange for the money that you get paid. I enjoy photography as a hobby.

What are the rewards for the effort involved?

First, I get into places for free! I used to attend ThinkVisibility for free because I took photos at the first one. I now get to watch loads of roller derby for free, and stand in the middle of the track whilst doing so. It’s great! (When I say ‘free’ here I mean that there is no exchange of money in either direction. I don’t buy a ticket to get in, but I don’t get paid for the hours of work sorting through, tagging and titling photos.)

Second, if people are happy with the photos I’ve taken then they use them. People generally don’t like having their photo taken. It’s such a compliment when someone chooses to use one of my photos as their profile picture on Facebook.

Third, as people like/share my photos then I get a reputation and a portfolio and so I get to take more photos.

Do you have a preference for attribution?

The best way that people can give credit is to link back to the photo on Flickr. When people follow that link they will discover other photos. Flickr provides statistics on the number of views. It’s satisfying to see a peak following an event:

Flickr stats, April 2014This peak, of over 8,600 views in a day, was from the B-HARD vs SOFT game :-)

Flattr this!

Firefox Offline broken

For some time now it seems that Firefox offline mode is broken or borked in some way.

I notice this on the train when I need to refer to Android documentation. Documentation can be downloaded as part of the Android developer kit. This used to work just fine in Firefox on my netbook when offline. Recently though, perhaps two releases of Firefox ago, it utterly fails.

Firefox displays nothing other than a blank white page whilst trying to connect to or Yesterday/today it has been particularly frustrating as I’ve been trying to work on stuff that I’ve not done before. Documentation was essential.

A search of the internet suggests that it might be add-on related. Some suggest restarting Firefox in safe mode. Disabling add-ons, safe mode make no difference. It is core Firefox that is at fault.

I have now installed Epiphany. It can open the local files, though the search function doesn’t seem to work. Better than nothing.

It looks like Mozilla broke something in Firefox 27?

Flattr this!

Handy Layouts

When developing Android applications the interface layout is usually defined in XML files. Commonly the file main.xml is the definition for the first interface that the application presents to the user.

Android also allows for different layouts to be defined in XML files in different folders. The names of the folders define when the layout should be used. So, for instance, the layout-land folder holds the layouts for the application when running on a device in landscape mode. This method allows design and function to be neatly separated.

It occurred to me on the train this evening, whilst working on an app, that it might be handy to have folders for left and right handedness. This would allow for asymmetric designs, especially in portrait mode, where the device – typically a phone – is being held in one hand. So if an application has multiple buttons on the display for instance, then the more important buttons could be sized/positioned to make them easier to reach.

I don’t know if this already exists, but I wanted to get it out there so that there is prior art, hopefully preventing the likes of Apple, Microsoft and RIM from claiming it as a novel invention and patenting it.

Flattr this!