gpt4 book ai didi

unit-testing - 找不到RESTeasy +服务器模拟+ ExceptionMapper

转载 作者:行者123 更新时间:2023-12-04 13:34:45 24 4
gpt4 key购买 nike

我有一个使用RESTeasy 2.0.1.GA在JAX-RS中使用ExceptionMapper的方案。一切正常。

我现在想使用RESTeasy的mock mechanism测试整个过程。不幸的是我的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);

最佳答案

好的,我找到了解决方案。需要手动注册ExceptionMapper:

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

关于unit-testing - 找不到RESTeasy +服务器模拟+ ExceptionMapper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5866695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com