Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company.everest
- import grails.test.*
- import org.codehaus.groovy.grails.plugins.web.taglib.FormTagLib
- import org.codehaus.groovy.grails.commons.ApplicationAttributes
- import groovy.mock.interceptor.StubFor
- import org.springframework.context.MessageSource
- class CompanyCustomTagLibTests extends TagLibUnitTestCase {
- def messageSourceStubber
- def originalFormTagLib
- protected void setUp() {
- super.setUp()
- mockTagLib(FormTagLib)
- originalFormTagLib = new FormTagLib()
- mockGrailsAttributesForTagLib(originalFormTagLib)
- tagLib.metaClass.getG = { return originalFormTagLib }
- tagLib.metaClass.g = originalFormTagLib
- registerMetaClass(String)
- String.class.metaClass.encodeAsHTML = {
- return delegate; // return the string itself
- }
- // mock a spring-MessageSource with a message getMessage()
- messageSourceStubber = new StubFor(MessageSource.class)
- messageSourceStubber.demand.getMessage(1..1) {code, args, locale -> return code }
- }
- private void mockGrailsAttributesForTagLib(def theLib) {
- // provide grailsAttributes to the tagLib
- theLib.metaClass.getGrailsAttributes = { getGrailsAttributesStub() }
- }
- private ApplicationAttributes getGrailsAttributesStub() {
- def applicationContextStubber = new StubFor(org.springframework.context.ApplicationContext.class)
- applicationContextStubber.demand.getBean() {beanName -> getBean(beanName) }
- def grailsAttributesStubber = new StubFor(ApplicationAttributes.class)
- grailsAttributesStubber.demand.getApplicationContext() { applicationContextStubber.proxyInstance() }
- return (ApplicationAttributes) grailsAttributesStubber.proxyInstance()
- }
- private getBean(String beanName)
- {
- assertEquals "messageSource", beanName
- return messageSourceStubber.proxyInstance()
- }
- void testClientSpecificQueuesSelectBox(){
- def taskService = mockFor(TaskService)
- taskService.demand.getClientSpecificQueues(){clientName->
- return [new TaskQueues(name: 'CM Referral'),
- new TaskQueues(name: 'DM Referral'),
- new TaskQueues(name: 'Authorization Requests')]
- }
- tagLib.taskService = taskService.createMock()
- def output = tagLib.clientSpecificQueues().toString()
- // assert output.contains("input type")
- // assert output.contains("td")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment