我正在尝试为使用网关向队列发送请求的服务编写集成测试。使用resources.xml中的spring集成将网关连接到队列:
<gateway
service-interface="WebRequestService"
id="webRequestGateway"
default-request-channel="queueChannel" />
使用Russ Miles http://blog.springsource.com/2008/12/11/spring-integration-in-grails-part-1/的示例,我能够在使用DI进入网关时编写Controller集成测试。
但是,当尝试使用服务集成测试时,我没有获得网关的DI,并且无法初始化它,因为它是一个接口。
我可以从Service集成测试中访问bean吗?或者有没有办法在服务中初始化它?
答案 0 :(得分:2)
确实是空的, 按照Luke Daley关于grails邮件列表的建议试试这个:
在您的测试类中,声明:
def grailsApplication
然后你得到这样的应用程序上下文: grailsApplication.mainContext
它对我有用; - )
答案 1 :(得分:0)
您可以按照以下方式获取应用程序上下文:
import grails.test.*
import grails.spring.BeanBuilder
class FooBarTests extends GrailsUnitTestCase {
boolean transactional = false
void testSomething() {
def bb = new BeanBuilder()
bb.loadBeans("classpath:*.spring.resources.groovy")
def applicationContext = bb.createApplicationContext()
}
}