Tuesday, October 27, 2009

Wow! Two car related posts in a row!

Here's some in-car footage from the Grafton Hillclimb. It's a short, tight course about 3 hours south of the Gold Coast. They hold 4 or 5 of these each year. Heaps of fun! I set a new PB this trip, beating my old best time by about 5 seconds thanks to better tires and suspension.




Check out Motorsport Photography for heaps of great shots of the events (including me!)

Friday, October 16, 2009

Finally something car related

So I've been very lazy with posting anything car related but finally have something interesting :) Here's some youtube video from my last two outings in the VR4. The first was to a track day at Queensland Raceway and the second was drag racing the following day.



Photobucket



Grails Amazon S3 0.7.4 Released

see http://refactor.com.au/blog/grails-amazon-s3-074-released

Saturday, June 13, 2009

Adding pagination to a Grails WebFlow state

I noticed a few unanswered questions relating to paginating a WebFlow state on the users mailing list and thought I'd post the solution I came up with for a Refactor project I was working on last week.

It basically involves splitting the behaviour into an action and a view state with a transition between them called 'paginate'
loadResults {
 action {
    def criteria = MyDomain.createCriteria(){
        eq('someField','someval')
    }
    flow.myDomainResults  = criteria.list([max: 9, offset: flow.myDomainOffset ?: 0])   
    flow.totalMyDomains = flow.myDomainResults.totalCount
    return success()
 }
 on('success').to('browse')
 on(Exception).to "handleError"
}
browse {
 on('paginate') {
    flow.myDomainOffset = params.offset
 }.to('loadResults')
 on('selectItem').to('someOtherState')
 //...
}
One point to note is that I use a criteria in order to get the totalCount property populated for me automatically so that I don't have to run a separate query. Also, the above only works if your domain class is Serializable, in my real application this wasn't the case so I stored a list of maps containing the properties I wanted to display instead of the list of domain objects.

Then in the view all we need to do is to pass the current page from the flow scope to the paginate tag. The paginate tag also contains an extra parameter in order to trigger the paginate event when the generated links are clicked.
<g:each in="${myDomainResults}" status="i" var="myDomain">
    <g:form action="myFlow">
        <input name="id" value="${myDomain.id}" type="hidden">
        URL: ${myDomain.url}
        <g:submitbutton name="selectItem" value="Select"/>
    </g:form>
</g:each>
<div class="paginateButtons">
   <g:paginate max="9" offset="${myDomainOffset}" total="${totalMyDomains}" params="${[_eventId_paginate:true]}" />
</div>

You can also see I render each item as a separate form with a hidden id field and a submit button to trigger the 'selectItem' event and move onto the next state.

I haven't tried messing with all the options for g:paginate to make sure they still work so please let me know if you find any problems with the above code.

Thursday, June 11, 2009

Thursday, May 21, 2009

Grails JSR-186 Portlets Plugin Released

Kenji Nakamura has taken the reins of my initial work on the Grails Portlets plugin and done an awesome job of refactoring it into more manageable sub-plugins.

You can now plug-in portal implementations with Pluto and Liferay supported initially.

JSR-286 will be supported when the underlying version of Spring used by Grails is updated to Spring 3.0.

Check it out at the Grails plugin portal.

Great work Kenji!

Wednesday, May 6, 2009

Grails Amazon S3 Plugin 0.5 Released

The latest version of the Amazon S3 plugin has been released which incorporates the latest jets3t snapshot library (0.7.1-SNAPSHOT) which has improved compatibility with the Eucalyptus open source EC2/S3 clone and some bug fixes.

The plugin S3 event handling code was also updated to avoid stale object and optimistic locking exceptions being thrown by Hibernate.

Thursday, April 30, 2009

WebTest Plugin 1.1.4.2 Released

A new minor release of the Grails WebTest plugin to allow the plugin to download the latest WebTest snapshot (which uses HtmlUnit 2.5 which fixes issues with testing JQuery 1.3.2).

It will download the latest snapshot by default when installed. If you would prefer the latest stable release (3.0) you can answer no when prompted.

Testing a JQuery-UI Drag and Drop using WebTest

Just a quick post regarding using WebTest with JQuery-UI Draggable and Droppable.
The way that WebTest performs a drag and drop is as follows:
from.mouseDown()
to.mouseOver()
to.mouseUp()
Note that there is no intermediate move events between mouse down on the thing you're dragging and mousing over the target element.
What this means is that you need to configure your Draggable to start dragging on mousedown without delay. You can do this by setting the distance and delay options to zero (delay is zero by default):
$('.block').draggable({distance:0});
WebTest will now be able to click and drag it correctly. Unfortunately due to HtmlUnits 'renderless' behaviour you cannot specify exactly where you want to drop it so if you require precise targeting to properly test your application you're out of luck.

Saturday, April 4, 2009

Grails WebTest Plugin 1.1.4 Released

Another WebTest plugin release, this time with some new functionality!

Soenke Sothmann has contributed a nice patch to allow you to run custom suites of tests:

run-webtest -suite=MyTestSuite

Note that under windows you will need to quote the -suite argument due to an issue with Gant's argument parsing e.g. "-suite=MyTestSuite"

import grails.util.WebTest

class MyTestSuite extends WebTest {

    static void main(args) {
        new MyTestSuite().runTests(args)
    }

    void suite() {
        new SomeTest1(ant:ant).suite()
        new SomeTest2(ant:ant).suite()
        // You could also load up certain tests based on naming conventions or annotations
    }
}

In addition to this patch, there were some bug fixes relating to running webtests under Hudson and also around setting a custom port when starting up the server.

Wednesday, April 1, 2009

Comments

Apologies to those people who left me comments to which I hadn't replied. I thought I had email notification turned on - looks like I didn't! I've replied as best I could although some of the topics are well out of my recent memory :)
cheers
Lee

Tuesday, March 31, 2009

Grails code example: Integration testing quartz job

Here's a quick snippet to use to integration test a quartz job.
I couldn't find a clear example after a quick Google so hopefully this is useful.
There's a good chance that there's a better auto-magical way to get the job injected but I haven't poked through the testing code to work it out :)
package au.com.refactor

class TempCleanerJobTests extends GrailsUnitTestCase {

  def tempCleanerJob
  def grailsApplication

  protected void setUp() {
    super.setUp()
    tempCleanerJob = grailsApplication.mainContext.getBean(TempCleanerJob)
  }

  protected void tearDown() {
    super.tearDown()
  }

  void testCleanNothing() {
    tempCleanerJob.execute()
  }

}

Monday, March 30, 2009

Grails WebTest Plugin 1.1.2 Released

I've just released the latest version of the WebTest plugin for Grails. This was an update to fix a couple of issues with interactive mode use and parameter parsing and to de-couple the WebTest distribution zip. Highlights
  • run-webtest now supports -headless to stop the Swing progress gui being shown during test runs (this was previously possible via system properties, this is just a tidy up)
  • install-plugin webtest will now prompt you to download WebTest (currently version 3). It installs it into your .grails directory by default or you can answer 'n' and manually set the install location via webtest/conf/webtest.properties using wt.config.home

Tuesday, February 24, 2009

Grails WebTest Plugin 1.1.1 Released

I've released an updated version of the WebTest plugin which is compatible with Grails 1.1.
It also has the latest WebTest release and a couple of small bug fixes.
If you are on 1.0.x DO NOT UPGRADE, stay with 0.6.
It can be installed via:
grails install-plugin webtest

Saturday, January 31, 2009

Grails WebTest Plugin 0.6 Released

The latest version of the Webtest Plugin has been released for Grails 1.0.4. A release for 1.1 will follow shortly, with a newer WebTest snapshot which is now Java 5 dependent.

Release Notes

  • setUp/tearDown at the method and class level

    • classSetUp() and classTearDown() are run as individual test cases. SetUp() and tearDown() are run as the first and last steps of each test case.

  • Superclass changes in WebTest

    • The WebTest superclass now automatically runs all methods starting with test. This saves you having to manually maintain the suite method unless you really want to for test order reasons.

    • WebTest will also generate the test case name from the class and method name removing the need for repetitive webtest('blah'){...} code. The generated test name also makes it much easir to find the failing test from the generate reports.

    • MethodMissing code has been added so you can refactor a group of steps without having to wrap them in and ant.group closure.

    • You can now call config() as the first step in your test method to set WebTest options like host, port and ajax support

  • -nostart option allows you to runthe tests against a server that is already running. It should come after run-webtest on the command line

  • System parameters now passed through to WebTest. They need to be placed directly after grails on the command line e.g. grails -Dwt.headless=true run-webtest

    • -Dwt.headless=true to hide Swing monitor and stop browser launching

    • -Dserver.port=XXXX to get the tests to run against a server on a non-default port

  • The plugin has been updated with a recent snapshot version of WebTest which includes an update of HtmlUnit to version 2.3

  • Application lib folder now on WebTest classpath. This avoids the need to duplicate/move libraries into webtest/home/lib

  • Custom steps

    • You can now extend com.canoo.webtest.steps.Step by placing groovy classes in webtest/tests/step. They will be automatically loaded at runtime and allow for easy testing of complicated scenarios such as JSON interfaces and email integration

      • The last project I worked on used these custom steps to start, check then stop an embedded Wiser SMTP server for testing email functionality.

Upgrade Instructions

delete plugins/webtest-0.x

svn delete webtest/home, commit.

This avoids svn issues as the install script deletes the folder and extracts the latest build over the top, removing the .svn directories

grails install-plugin webtest