2012-12-09 2 views
4

Grails 프로덕션 코드를 테스트하고 싶습니다. 아래 예제를 보았습니다. 문제는 HttpBuilder의 클라이언트 부분에서 MissimgMethodExceptions을 실행한다는 것입니다. 이것은 내가 테스트하고 싶은 제품 코드 : 사용 http://groovy.codehaus.org/Groovy+way+to+implement+interfacesMockFor를 사용하여 HttpBuilder에서 모의 ​​클라이언트를 사용하는 방법?

: 여기에 멋있는 문서에 인터페이스를 조롱에 Groovy HTTPBuilder Mocking the Response을 일부 : 나는 어떤 여기에 HTTPBuilder를 조롱의 주제에 대한 도움말을 발견

class RunkeeperActivitiesRetrieverService { 
    def http = new RESTClient("http://api.runkeeper.com/") 

    def getActivities() { 
     http.client.clearRequestInterceptors(); 
     http.client.addRequestInterceptor(new HttpRequestInterceptor() { 
      void process(HttpRequest httpRequest, HttpContext httpContext) { 
       httpRequest.addHeader('Authorization', 'Bearer xxxxxxxxxx') 
      } 
     }) 
     //Do more with the httpBuilder 
    } 
} 

그 코드는 나는이 테스트 코드에 온 :

def mock = new MockFor(HTTPBuilder) 
def impl = [ 
    addRequestInterceptor : {HttpRequestInterceptor interceptor -> println "hi 4"+interceptor}, 
    clearRequestInterceptors : {println "hi 88"} 
      ] 
def client = impl as HttpClient 

mock.demand.getClient {return client} 
mock.use{ 
    service.http = new HTTPBuilder() 
    println service.getActivities() 
} 

불행하게도 그루비의 내 지식이 너무 throw되는 예외 해결하기 위해 제한됩니다 groovy.lang.MissingMethodException: No signature of method: $Proxy15.clearRequestInterceptors() is applicable for argument types:() values: []

여기에 무엇이 누락 되었습니까?

답변

1

impl에서 HttpClient으로 캐스팅하고 있습니다. 문제의 방법이 나타나지 않습니다. that interface에 정의되어 있습니다. 아마도 AbstractHttpClient의 하위 클래스를 사용하는 것이 좋습니다.