2011-05-03 2 views
5

RESTeasy 2.0.1.GA를 사용하여 JAX-RS에서 ExceptionMapper이 사용되는 시나리오가 있습니다. 이것은 모두 잘 작동합니다.RESTeasy + Server 모의 + ExceptionMapper를 찾을 수 없음

이제 RESTeasy의 mock mechanism을 사용하여 모든 것을 테스트하고 싶습니다. 불행히도 내 ExceptionMapper 공급자가 등록되지 않았습니다. 내가 뭘 놓치고 있니?

POJOResourceFactory factory = new POJOResourceFactory(SomeWebResource.class); 

Dispatcher dispatcher = MockDispatcherFactory.createDispatcher(); 
dispatcher.getRegistry().addResourceFactory(factory); 

MockHttpRequest request = MockHttpRequest.get("url"); 
MockHttpResponse response = new MockHttpResponse(); 

// here my exception is thrown 
dispatcher.invoke(request, response); 

// but I expect the response to be 404 (which works outside the mock setup) 
Assert.assertEquals(response.getStatus(), 404); 

답변

10

그래, 해결책을 찾았습니다.

dispatcher.getProviderFactory().addExceptionMapper(SomeExceptionMapper.class); 
+8

참고 : addExceptionMapper()의 가시성이 이후 버전에서는 protected로 변경되었습니다. 대신에 dispatcher.getProviderFactory(). registerProvider (SomeExceptionMapper.class)가 작동합니다. –