Jan*_*Jan 6 unit-testing jax-rs mocking resteasy
我有一个ExceptionMapper
使用RESTeasy 2.0.1.GA在JAX-RS中使用的场景.这很好用.
我现在想用RESTeasy的模拟机制来测试整个事情.不幸的是我的ExceptionMapper-provider没有注册.我错过了什么?
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);
Run Code Online (Sandbox Code Playgroud)
Jan*_*Jan 12
好的,我找到了解决方案.需要手动注册ExceptionMapper:
dispatcher.getProviderFactory().addExceptionMapper(SomeExceptionMapper.class);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3268 次 |
最近记录: |