Guest User

Test class

a guest
Dec 3rd, 2012
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.59 KB | None | 0 0
  1. package com.company.everest
  2.  
  3. import grails.test.*
  4. import org.codehaus.groovy.grails.plugins.web.taglib.FormTagLib
  5. import org.codehaus.groovy.grails.commons.ApplicationAttributes
  6. import groovy.mock.interceptor.StubFor
  7. import org.springframework.context.MessageSource
  8.  
  9.  
  10. class CompanyCustomTagLibTests extends TagLibUnitTestCase {
  11.  
  12.     def messageSourceStubber
  13.     def originalFormTagLib
  14.  
  15.     protected void setUp() {
  16.         super.setUp()
  17.        
  18.         mockTagLib(FormTagLib)
  19.         originalFormTagLib = new FormTagLib()
  20.         mockGrailsAttributesForTagLib(originalFormTagLib)
  21.         tagLib.metaClass.getG = { return originalFormTagLib }
  22.         tagLib.metaClass.g = originalFormTagLib
  23.  
  24.        
  25.         registerMetaClass(String)
  26.         String.class.metaClass.encodeAsHTML = {
  27.             return delegate; // return the string itself
  28.         }
  29.  
  30.  
  31.  
  32.         // mock a spring-MessageSource with a message getMessage()
  33.         messageSourceStubber = new StubFor(MessageSource.class)
  34.         messageSourceStubber.demand.getMessage(1..1) {code, args, locale ->       return code     }
  35.     }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.     private void mockGrailsAttributesForTagLib(def theLib) {
  42.         // provide grailsAttributes to the tagLib
  43.         theLib.metaClass.getGrailsAttributes = { getGrailsAttributesStub() }
  44.     }
  45.  
  46.  
  47.     private ApplicationAttributes getGrailsAttributesStub() {
  48.         def applicationContextStubber = new StubFor(org.springframework.context.ApplicationContext.class)
  49.         applicationContextStubber.demand.getBean() {beanName -> getBean(beanName) }
  50.  
  51.         def grailsAttributesStubber = new StubFor(ApplicationAttributes.class)
  52.         grailsAttributesStubber.demand.getApplicationContext() {       applicationContextStubber.proxyInstance()     }
  53.         return (ApplicationAttributes) grailsAttributesStubber.proxyInstance()
  54.     }
  55.  
  56.  
  57.     private getBean(String beanName)
  58.     {
  59.         assertEquals "messageSource", beanName
  60.         return messageSourceStubber.proxyInstance()
  61.     }
  62.  
  63.  
  64.  
  65.    
  66.  
  67.  
  68.  
  69.     void testClientSpecificQueuesSelectBox(){
  70.         def taskService = mockFor(TaskService)
  71.  
  72.         taskService.demand.getClientSpecificQueues(){clientName->
  73.             return [new TaskQueues(name: 'CM Referral'),
  74.                     new TaskQueues(name: 'DM Referral'),
  75.                     new TaskQueues(name: 'Authorization Requests')]
  76.         }
  77.  
  78.  
  79.         tagLib.taskService = taskService.createMock()
  80.  
  81.        def output = tagLib.clientSpecificQueues().toString()
  82.  
  83.  
  84. //        assert output.contains("input type")
  85. //        assert output.contains("td")
  86.  
  87.     }
  88.  
  89.  
  90.  
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment