Grails의 문서 상태 : 인터셉터를 호출하지 않습니다
Grails의이하기를 원하지 않을 경우 당신이 전체 라이프 사이클을 통해 갈 것이다 성배의 기능 테스트 같은 것을 사용하는 것 같아요 또는 서블릿 필터를 사용하여 통합 테스트를 수행 할 수 있습니다. 필요한 경우 기능 테스트를 사용하여 격리에서 인터셉터와 필터를 테스트해야합니다.
이것은 단위 테스트에도 적용되며 컨트롤러 작업은 정의 된 인터셉터의 영향을받지 않습니다.
당신이 가진 것을 감안할 때 :
def afterInterceptor = [action: this.&interceptAfter, only: ['actionWithAfterInterceptor','someOther']]
private interceptAfter(model) { model.lastName = "Threepwood" }
당신이해야 인터셉터 테스트하려면 :
가 가로 채기 확인을
void "After interceptor applied to correct actions"() {
expect: 'Interceptor method is the correct one'
controller.afterInterceptor.action.method == "interceptAfter"
and: 'Interceptor is applied to correct action'
that controller.afterInterceptor.only, contains('actionWithAfterInterceptor','someOther')
}
이 인터셉터 방법은이 있는지 확인 원하는 행동에 적용 원하는 효과
void "Verify interceptor functionality"() {
when: 'After interceptor is applied to the model'
def model = [firstName: "Guybrush"]
controller.afterInterceptor.action.doCall(model)
then: 'Model is modified as expected'
model.firstName == "Guybrush"
model.lastName == "Threepwood"
}
,210
또는 더 인터셉터가없는 경우, 어떤
void "Verify there is no before interceptor"() {
expect: 'There is no before interceptor'
!controller.hasProperty('beforeInterceptor')
}
그 예는 인터셉터 후 테스트를했다하지만 같은도 인터셉터 전에 적용해야이없는 확인합니다.