Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This repository was archived by the owner on May 28, 2025. It is now read-only.

GrailsUnitTest.defineBeans(new PluginClass()) does not set grailsApplication /applicationContext? #43

Open
@boardbloke

Description

@boardbloke

I have a custom TagLib that makes use of the asset-pipeline-grails (version 3.0.6) AssetsTagLib to display images. It calls asset.image() to output an image tag when it renders.

In order to test this, I have a CustomTagLibSpec that implements TagLibUnitTest, and in the setup method I was expecting to be able to do the following to bootstrap and mock the the relevant asset dependencies:

setup() {`
  defineBeans(new AssetPipelineGrailsPlugin())
  mockTagLib(AssetsTagLib)
  mockTagLib(AssetMethodTagLib)
}

On running the unit test though, I get a failure because grailsApplication is used in the AssetPipelineGrailsPlugin.doWithSpring Closure, and that is not set.

If I change my unit test code to

setup() {`
  def assetPlugin = new AssetPipelineGrailsPlugin()
  assetPlugin.applicationContext = applicationContext
  assetPlugin.grailsApplicatin = grailsApplication
  defineBeans(assetPlugin)
  mockTagLib(AssetsTagLib)
  mockTagLib(AssetMethodTagLib)
}

Then my unit test works.

Given that all plugins implement Plugin, and therefore ApplicationContextAware, and GrailsApplicationAware, can the defineBeans(Object plugin) method in GrailsUnitTest be changed to set the grailsApplication and applicationContext from the unit test to avoid having to do it manually please ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions