如何为grails集成测试注入依赖项的依赖项?

时间:2014-07-18 20:21:42

标签: grails groovy

我有一个控制器,它调用一个调用另一个服务的服务。我试图将这两个依赖项注入到我的集成测试中,但我只能将其用于第一个服务。

我尝试过集成测试:

import grails.test.mixin.TestMixin
@TestMixin(IntegrationTestMixin)

class BookVacationTests extends GroovyTestCase{
    def travelAgentService
    def julie
    void testPlanTrip(){
        def bookVacationController = new BookVacationController()
        bookVacationController.travelAgentService = travelAgentService
        bookVacationController.travelAgentService.secretaryService = julie
        bookVacationController.planTrip()
        assertEquals(HttpServletResponse.SC_OK, bookVacationController.response)
    }
}

我的控制器是什么样的:

class BookVacationController {
    def travelAgentService
    def planTrip(){
        travelAgentService.makeSecretaryDoIt()
        render HttpServletResponse.SC_OK
    }
}

我的第一项服务是什么样的:

@Transactional
class TravelAgentService {
    SecretaryService secretaryService
    def makeSecretaryDoIt(){
        secretaryService.bookTheTripPlease()
    }
}

我的秘书服务界面是什么样的:

public interface SecretaryService {
    public void bookTheTripPlease();
}

我的第二项服务是什么样的:

@Transactional
class Julie implements SecretaryService {
    public void bookTheTripPlease(){
        //...
    }
}

但是我得到了运行时异常:

  

创建名为'julie'的bean时出错:bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[com.lexmark.pigeon.ws.service.julie]:构造函数抛出异常;嵌套异常是java.lang.IllegalArgumentException:参数类型不匹配

为什么我不能这样做?

0 个答案:

没有答案
相关问题