Доступ к servletContext из службы в рамках интеграционного теста
Я пытаюсь получить доступ к servletContext (контекст приложения) из службы в интеграционный тест.
Вот как я пытаюсь включить его в свой интеграционный тест:
import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH
class ScraperServiceIntegrationTests extends GroovyTestCase {
ScraperService scraperService
def testStoring() {
scraperService = new ScraperService()
scraperService.servletContext = new SCH()
scraperService.storing()
...
}
...
}
Вот как я использую контекст сервлета в своей службе:
class ScraperService {
static transactional = true
def servletContext
synchronized def storing() {
servletContext.numberOfCreditProvider = "whatever"
...
}
...
}
Я получаю следующее сообщение об ошибке:
No such property: numberOfCreditProvider for class: org.codehaus.groovy.grails.web.context.ServletContextHolder
Как я могу решить эту ошибку?
2 ответов:
Вы присваиваете свой
servletContextв тестеServletContextHolderвместо самого фактического контекста.Вы, вероятно, хотите, чтобы это было в вашем тесте:
import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH def testStoring() { scraperService = new ScraperService() scraperService.servletContext = SCH.servletContext scraperService.storing() ... }
Comments