Grails

ApplicationTagLib.makeServerURL fails if config is null (and some related issues...)

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.1.1, 1.2-M1, 1.2-M2
  • Fix Version/s: 1.2.1, 1.3-M1
  • Component/s: TagLib
  • Labels:
    None

Description

I encountered this issue when trying to use createLink in unit and integration tests. The problem pops up in 1.1.1 when creating integration tests since the "create-integration-test" script generates a test that subclasses GrailsUnitTestCase rather than GroovyTestCase. GrailsUnitTestCase sets grailsApplication.config to null in its tearDown routine which causes any additional tests that call createLink in that particular run to fail (the first one succeeds).

After changing the integration test to subclass GroovyTestCase, you don't get this issue but it can crop up in other contexts. The specific suggestion is to change the first line of makeServerURL to use null-safe referencing, i.e.

def u = ConfigurationHolder.config?.grails?.serverURL

More generally though, it would be nice to clarify how/when ApplicationTagLib actions can be used. I am using them in services and in tests that exercise those services and had to explicitly create an ApplicationTagLib in order to call the tag.

Issue Links

Activity

Hide
Scott Davis added a comment -

This bug makes unit testing withFormat in a ControllerUnitTestCase fail as described in http://agileice.blogspot.com/2009/09/grails-integration-testing.html

Show
Scott Davis added a comment - This bug makes unit testing withFormat in a ControllerUnitTestCase fail as described in http://agileice.blogspot.com/2009/09/grails-integration-testing.html
Hide
Gabe Beged-Dov added a comment -

Jeff,

The base bug is that there isn't a null test in makeServerURL. This is not a duplicate of 5685. You can certainly argue that this is a minor bug but aren't there other scenarios where config can be null (some of them not errors?) so that generating a NPE is not correct?

Separate from this is the recurring question on whether integration tests should use GrailsUnitTestCase. Many example of being bitten by this (e.g. http://old.nabble.com/Grails-1.1.1-Integration-testing-fails-unless-using-mockDomain-tc25096137.html) and its not clear what capabilities above and beyond GroovyTestCase are needed that outweigh the problems.

Show
Gabe Beged-Dov added a comment - Jeff, The base bug is that there isn't a null test in makeServerURL. This is not a duplicate of 5685. You can certainly argue that this is a minor bug but aren't there other scenarios where config can be null (some of them not errors?) so that generating a NPE is not correct? Separate from this is the recurring question on whether integration tests should use GrailsUnitTestCase. Many example of being bitten by this (e.g. http://old.nabble.com/Grails-1.1.1-Integration-testing-fails-unless-using-mockDomain-tc25096137.html) and its not clear what capabilities above and beyond GroovyTestCase are needed that outweigh the problems.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: