Camel bean 구성 요소가 참조하는 서비스를 사용하는 Grails의 생산 경로에 대한 단위 테스트를 작성해야합니다. 내 요구 사항은 테스트 중 기존 경로를 변경하거나 복사하지 않아야합니다.Grails Services in Camel Production 경로 단위 테스트
문제는 서비스 빈을 모의 해 카멜 레지스트리에 추가하는 것입니다.
'context.registry.registry'개체에서 'bind'메서드를 사용하여이 작업을 수행 할 수있었습니다. 더 안전한 방법으로이를 수행 할 수있는 기능이 있습니까? 낙타 버전은 2.10이다 Grails는 2.1
경로는 다음과 같습니다
package com
class CamelService {
def echo(text) {
println "text=$text"
text
}
}
테스트 (경로 질문 간단하게 만 복사) 다음입니다 :
from('direct:validate').to('bean:camelService?method=echo')
CamelService 그냥 간단한 클래스입니다
package com
import grails.test.mixin.*
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.test.junit4.CamelTestSupport
@TestFor(CamelService)
class RouteTests extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from('direct:validate').to('bean:camelService?method=echo')
}
};
}
void testMockBean() throws Exception {
context.registry.registry.bind 'camelService', service
def result = template.requestBody('direct:validate', 'message')
assert result != null
assert result == 'message'
}
}
감사합니다. 이 질문에 대한 답변입니다. 위의 코드는 JNDI 레지스트리가 테스트 클래스에서 다른 것으로 변경되지 않을 때까지 안전합니다. SimpleRegistry로이를 재정의하면 예상대로 작동합니다. – droggo