use of io.github.resilience4j.feign.test.TestService in project resilience4j by resilience4j.
the class DecoratorInvocationHandlerTest method setUp.
@Before
public void setUp() throws Throwable {
target = new HardCodedTarget<TestService>(TestService.class, TestService.class.getSimpleName());
testService = new TestServiceImpl();
greetingMethod = testService.getClass().getDeclaredMethod("greeting");
feignDecorator = new TestFeignDecorator();
methodHandler = mock(MethodHandler.class);
when(methodHandler.invoke(any())).thenReturn(testService.greeting());
dispatch = new HashMap<>();
dispatch.put(greetingMethod, methodHandler);
testSubject = new DecoratorInvocationHandler(target, dispatch, feignDecorator);
}
use of io.github.resilience4j.feign.test.TestService in project resilience4j by resilience4j.
the class Resilience4jFeignFallbackFactoryTest method should_go_to_second_fallback_and_consume_exception_with_predicate.
@Test
public void should_go_to_second_fallback_and_consume_exception_with_predicate() {
setupStub(400);
TestService uselessFallback = spy(TestService.class);
when(uselessFallback.greeting()).thenReturn("I should not be called");
FeignDecorators decorators = FeignDecorators.builder().withFallbackFactory(e -> uselessFallback, MyException.class::isInstance).withFallbackFactory(TestServiceFallbackWithException::new).build();
TestService testService = Resilience4jFeign.builder(decorators).target(TestService.class, MOCK_URL);
String result = testService.greeting();
assertThat(result).isEqualTo("Message from exception: status 400 reading TestService#greeting()");
verify(uselessFallback, times(0)).greeting();
verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}
use of io.github.resilience4j.feign.test.TestService in project resilience4j by resilience4j.
the class Resilience4jFeignFallbackFactoryTest method should_go_to_fallback_and_consume_exception.
@Test
public void should_go_to_fallback_and_consume_exception() {
setupStub(400);
TestService testService = buildTestService(TestServiceFallbackWithException::new);
String result = testService.greeting();
assertThat(result).isEqualTo("Message from exception: status 400 reading TestService#greeting()");
verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}
use of io.github.resilience4j.feign.test.TestService in project resilience4j by resilience4j.
the class Resilience4jFeignFallbackFactoryTest method should_go_to_second_fallback_and_consume_exception_with_exception_filter.
@Test
public void should_go_to_second_fallback_and_consume_exception_with_exception_filter() {
setupStub(400);
TestService uselessFallback = spy(TestService.class);
when(uselessFallback.greeting()).thenReturn("I should not be called");
FeignDecorators decorators = FeignDecorators.builder().withFallbackFactory(e -> uselessFallback, MyException.class).withFallbackFactory(TestServiceFallbackWithException::new).build();
TestService testService = Resilience4jFeign.builder(decorators).target(TestService.class, MOCK_URL);
String result = testService.greeting();
assertThat(result).isEqualTo("Message from exception: status 400 reading TestService#greeting()");
verify(uselessFallback, times(0)).greeting();
verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}
use of io.github.resilience4j.feign.test.TestService in project resilience4j by resilience4j.
the class Resilience4jFeignFallbackFactoryTest method should_go_to_fallback_and_consume_exception_with_predicate.
@Test
public void should_go_to_fallback_and_consume_exception_with_predicate() {
setupStub(400);
TestService uselessFallback = spy(TestService.class);
when(uselessFallback.greeting()).thenReturn("I should not be called");
FeignDecorators decorators = FeignDecorators.builder().withFallbackFactory(TestServiceFallbackWithException::new, FeignException.class::isInstance).withFallbackFactory(e -> uselessFallback).build();
TestService testService = Resilience4jFeign.builder(decorators).target(TestService.class, MOCK_URL);
String result = testService.greeting();
assertThat(result).isEqualTo("Message from exception: status 400 reading TestService#greeting()");
verify(uselessFallback, times(0)).greeting();
verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}
Aggregations