mockrestserviceserver

Spring boot testing of a rest client using @RestClientTest

China☆狼群 提交于 2019-12-21 04:12:42
问题 I am using spring boot 1.5.8 and want to test my client: @Component public class RestClientBean implements RestClient { private Map<String, RestTemplate> restTemplates = new HashMap<>(); @Autowired public RestClientBean(RestTemplateBuilder builder, SomeConfig conf) { restTemplates.put("first", builder.rootUri("first").build(); restTemplates.put("second", builder.rootUri("second").build(); } } with the following test: @RunWith(SpringRunner.class) @RestClientTest(RestClient.class) public class

How can I unit-test javanica @HystrixCommand annotated methods?

给你一囗甜甜゛ 提交于 2019-12-19 17:38:57
问题 I am using javanica and annotating my hystrix command methods like this: @HystrixCommand(groupKey="MY_GROUP", commandKey="MY_COMMAND" fallbackMethod="fallbackMethod") public Object getSomething(Object request) { .... And I am trying to unit tests my fallback methods, without having to call them directly, i.e. I would like to call the @HystrixCommand annotated method and let it flow naturally into the fallback after throwing a 500 error. This all works outside of unit tests. In my unit tests I

How can I unit-test javanica @HystrixCommand annotated methods?

独自空忆成欢 提交于 2019-12-01 16:58:05
I am using javanica and annotating my hystrix command methods like this: @HystrixCommand(groupKey="MY_GROUP", commandKey="MY_COMMAND" fallbackMethod="fallbackMethod") public Object getSomething(Object request) { .... And I am trying to unit tests my fallback methods, without having to call them directly, i.e. I would like to call the @HystrixCommand annotated method and let it flow naturally into the fallback after throwing a 500 error. This all works outside of unit tests. In my unit tests I am using springs MockRestServiceServer to return 500 errors, this part is working, but Hystrix is not

How to mock RestTemplate with MockRestServiceServer?

半世苍凉 提交于 2019-11-30 09:55:55
问题 @RunWith(MockitoJUnitRunner.class) public class FeatureFlipperManagerTest { @Autowired RestTemplate restTemplate = new RestTemplate(); @Autowired Service service = new Service(); MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); @Test public void test() throws Exception { mockServer.expect(requestTo(Mockito.anyString())) .andRespond(withSuccess("{\"enabled\":true}", MediaType.APPLICATION_JSON)); boolean res = service.isEnabled("xxx"); mockServer.verify();

How to mock RestTemplate with MockRestServiceServer?

好久不见. 提交于 2019-11-29 18:13:39
@RunWith(MockitoJUnitRunner.class) public class FeatureFlipperManagerTest { @Autowired RestTemplate restTemplate = new RestTemplate(); @Autowired Service service = new Service(); MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); @Test public void test() throws Exception { mockServer.expect(requestTo(Mockito.anyString())) .andRespond(withSuccess("{\"enabled\":true}", MediaType.APPLICATION_JSON)); boolean res = service.isEnabled("xxx"); mockServer.verify(); Assert.assertEquals(true, res); } } I have MockRestServiceServer to mock restTemplete in a service. But