I need a little help with a strange problem that I came across with unit testing of a very simple Grails 2.4.1 controller.
Given this controller:
class AuthenticationEventController { def index() { // Sorry, ajax only! if(!request.xhr) { redirect(controller: "main") return false } render(template: "index") return } }
And this test:
@TestFor(AuthenticationEventController) class AuthenticationEventControllerSpec extends Specification { void "Test that the index rejects non-ajax calls"() { given: request.isXhr = { false } when: controller.index() then: response.redirectedUrl == '/main' } }
I get a NullPointerException in a controller.index () call.
java.lang.NullPointerException at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130) at org.codehaus.groovy.grails.orm.support.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:85) at au.com.intrinsicminds.advansys.controller.AuthenticationEventControllerSpec.Test that the index rejects non-ajax calls(AuthenticationEventControllerSpec.groovy:17)
unit-testing grails
Paul willems
source share