【问题标题】:Testing Grails Spring Integration测试 Grails Spring 集成
【发布时间】:2009-08-20 12:10:39
【问题描述】:

我正在尝试为使用网关将请求发送到队列的服务编写集成测试。网关使用 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 进入时,我能够编写控制器集成测试。

但是,当尝试通过服务集成测试执行此操作时,我没有获得网关的 DI,并且无法初始化它,因为它是一个接口。

我可以从服务集成测试中访问 bean 吗?或者有没有办法在服务中初始化它?

【问题讨论】:

    标签: spring grails


    【解决方案1】:

    确实是空的, 试试这个,遵循来自 grails 邮件列表的 Luke Daley 的建议:

    在你的测试类中,声明:

    def grailsApplication
    

    然后你会得到这样的应用程序上下文: grailsApplication.mainContext

    它对我有用 ;-)

    【讨论】:

      【解决方案2】:

      您可以通过以下方式获取应用程序上下文:

      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()
          }
      }
      

      【讨论】:

      • 对不起,应用程序上下文接缝为空:-(
      猜你喜欢
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多