Grails
  1. Grails
  2. GRAILS-8118

Unit Testing: groovy.lang.MissingMethodException upon calling g.message() in a TagLib

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.0-M2
    • Fix Version/s: 2.0-RC1
    • Component/s: TagLib, Testing
    • Labels:
      None
    • Environment:
      grails-2.0.0.BUILD-SNAPSHOT #1468

      Description

      In http://blog.springsource.com/2011/06/07/countdown-to-grails-1-4-unit-testing/, Peter states that "The standard Grails tags will just work and you can enable other tags by simply calling mockTagLib() with the relevant TagLib class."

      However, tests still fail with the following errors:

      groovy.lang.MissingMethodException: No signature of method: myproj.MyprojTagLib.message() is applicable for argument types: (java.util.LinkedHashMap) values: [[code:taglib.thetag.title, default:Default Message, ...]]
      Possible solutions: isCase(java.lang.Object)
      at myproj.MyprojTagLib$_closure14.doCall(MyprojTagLib.groovy:379)
      at myproj.MyprojTagLibTests.testOutputIsFreeOfAnyInlineScripts(MyprojTagLibTests.groovy:56)

      // Line 379 of MyprojTagLib.groovy:
      def title = (attrs?.remove('title') ?: message(code:"taglib.thetag.title", default:"Default Message", locale: dataLocale)).encodeAsHTML()
      
      // Line 56 of MyprojTagLibTests.groovy:
      assert !(tagLib.theTag(name:'p'){"Arbitrary Body"}.toString()).contains("script")
      

      Is this a bug, or is the according feature simply yet to be implemented?

        Activity

        Hide
        Bernhard Areich added a comment -

        If I amend the example as follows, an NPE is caused (see below).

        // ...
        @TestFor(MyprojTagLib)
        // class ...
        assert !applyTemplate('<myprojtaglib:theTag name="p" />').contains('script')
        // ...
        

        java.lang.NullPointerException
        at grails.test.mixin.web.GroovyPageUnitTestMixin.applyTemplate(GroovyPageUnitTestMixin.groovy:129)
        at grails.test.mixin.web.GroovyPageUnitTestMixin.applyTemplate(GroovyPageUnitTestMixin.groovy:122)
        at myproj.MyprojTagLibTests.testOutputIsFreeOfAnyInlineScripts(MyprojTagLibTests.groovy:60)

        Show
        Bernhard Areich added a comment - If I amend the example as follows, an NPE is caused (see below). // ... @TestFor(MyprojTagLib) // class ... assert !applyTemplate('<myprojtaglib:theTag name= "p" />').contains('script') // ... java.lang.NullPointerException at grails.test.mixin.web.GroovyPageUnitTestMixin.applyTemplate(GroovyPageUnitTestMixin.groovy:129) at grails.test.mixin.web.GroovyPageUnitTestMixin.applyTemplate(GroovyPageUnitTestMixin.groovy:122) at myproj.MyprojTagLibTests.testOutputIsFreeOfAnyInlineScripts(MyprojTagLibTests.groovy:60)
        Hide
        Graeme Rocher added a comment -

        Please attach an example that reproduces the problem

        Show
        Graeme Rocher added a comment - Please attach an example that reproduces the problem
        Hide
        Graeme Rocher added a comment -

        Example application that demonstrates the functionality in question is working

        Show
        Graeme Rocher added a comment - Example application that demonstrates the functionality in question is working
        Hide
        Graeme Rocher added a comment -

        I've attached an example that works fine against current git master. If you continue to have issues please attach an example that reproduces the problem.

        Show
        Graeme Rocher added a comment - I've attached an example that works fine against current git master. If you continue to have issues please attach an example that reproduces the problem.

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Bernhard Areich
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development