Deploying Spring Boot Groovy scripts as a Jar file in Cloud Foundry

This post is a step by step guide on deploying a Spring Boot application on Cloud Foundry using the spring jar feature introduced in 1.0.0.RC2.

If you read the Cloud Foundry documentation, they would claim that the proper way to deploy Spring Boot Groovy scripts is via:

spring grab *.groovy
cf push

Unfortunately, this approach is almost as effective as Sex Panther Cologne.

It fails badly when you try to include other starter packs, such as the websocket starter pack.

Using the jar approach outlined here allows us to overcome the errors that you might encounter in Cloud Foundry otherwise. Continue reading

Extending Geb Navigators to work with Third Party Javascript Libraries

In Asgard, we use the select2 jQuery library to make combo boxes on our pages more user friendly.

This causes a problem when writing functional tests, however, since you cannot use the default drop down selection mechanisms provided by Geb.

A pretty powerful technique mentioned in Marcin Edrmann’s Advanced Geb talk is to extend the default navigators to provide your own methods to acommodate third party libraries.

In this post, I will show you how we use this to provide our own dropdown selection method.

Continue reading

Mocking out Amazon AWS SDK with the Betamax Recording Proxy for testing

One of the ways you can make your testing more efficient is to mock out external services.

If you are using Amazon Web Services in your application, you can use the Betamax proxy to record and playback responses so they are consistent across your tests.

Here is an example Spock specification on how to mock out the SDK’s http service so it plays nice with Betamax:

    @Betamax(tape = "mytape")
    void 'can use betamax to stub out amazon service'() {

        given:
        // set up an AWS client configuration that uses a proxy
        ClientConfiguration clientConfig = new ClientConfiguration()
        clientConfig.proxyHost = '127.0.0.1'
        clientConfig.proxyPort = 5555

        // configure your AWS client, here we use the SimpleDBClient as an example
        AmazonSimpleDBClient simpleDbClient = new AmazonSimpleDBClient(
            new BasicAWSCredentials('accessKey', 'secretKey'),
            clientConfig
        )
        
        // setup the betamax proxy on the AWS SDK's httpClient
        BetamaxHttpsSupport.configure(simpleDbClient.client.httpClient)

        when:
        // now, when a request is made, the test will first check on the betamax tape to see if it has been previously recorded.
        SelectResult result = simpleDbClient.select(new SelectRequest("select * from MYRESOURCELIST limit 20", true))
        
        then:
        result.size() == 20
    }

Test your applications against the nightly builds of Grails

One of the cool things the team at Sky used to do was to test the codebase against the latest nightly build of Grails.

This allowed us to quickly catch regressions or incompatibilities as soon as they were checked into Grails. 

Here is a bash script that you can add to Jenkins to do so for Grails 2.3.x 

#download grails nightly
export GRAILS_NIGHTLY="grails-2.3.2.BUILD-SNAPSHOT"
rm -rf $GRAILS_NIGHTLY.zip $GRAILS_NIGHTLY 
curl -O http://hudson.grails.org/job/grails_core_2.3.x/lastSuccessfulBuild/artifact/build/distributions/${GRAILS_NIGHTLY}.zip
unzip $GRAILS_NIGHTLY.zip

#install jar files into local maven repository
cd $GRAILS_NIGHTLY/dist
for f in *BUILD-SNAPSHOT.pom; 
do 
   mvn install:install-file -Dfile=${f/.pom/.jar} -DpomFile=$f 
done
cd ../../

#set environment variables
export GRAILS_HOME="$PWD/$GRAILS_NIGHTLY"
export PATH="$PATH:$GRAILS_HOME/bin"

#test grails app
grails upgrade --non-interactive
grails test-app --non-interactive

Set it to run once and day and you can guarantee that your code is compatible with changes that are happening within Grails.

Caution: Your project needs to be compatible with at least Grails 2.3.0 for this script to work as the versioning for the Tomcat and Hibernate plugins have changed from previous versions.