Search in sources :

Example 1 with TestService

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);
}
Also used : MethodHandler(feign.InvocationHandlerFactory.MethodHandler) TestService(io.github.resilience4j.feign.test.TestService) TestFeignDecorator(io.github.resilience4j.feign.test.TestFeignDecorator) TestServiceImpl(io.github.resilience4j.feign.test.TestServiceImpl) Before(org.junit.Before)

Example 2 with TestService

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")));
}
Also used : TestService(io.github.resilience4j.feign.test.TestService) Test(org.junit.Test)

Example 3 with TestService

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")));
}
Also used : TestService(io.github.resilience4j.feign.test.TestService) TestServiceFallbackWithException(io.github.resilience4j.feign.test.TestServiceFallbackWithException) Test(org.junit.Test)

Example 4 with TestService

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")));
}
Also used : TestService(io.github.resilience4j.feign.test.TestService) Test(org.junit.Test)

Example 5 with TestService

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")));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestServiceFallbackWithException(io.github.resilience4j.feign.test.TestServiceFallbackWithException) Test(org.junit.Test) TestService(io.github.resilience4j.feign.test.TestService) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) TestServiceFallbackThrowingException(io.github.resilience4j.feign.test.TestServiceFallbackThrowingException) Function(java.util.function.Function) WireMock(com.github.tomakehurst.wiremock.client.WireMock) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ClassRule(org.junit.ClassRule) FeignException(feign.FeignException) TestService(io.github.resilience4j.feign.test.TestService) FeignException(feign.FeignException) TestServiceFallbackWithException(io.github.resilience4j.feign.test.TestServiceFallbackWithException) Test(org.junit.Test)

Aggregations

TestService (io.github.resilience4j.feign.test.TestService)13 Test (org.junit.Test)12 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)4 TestServiceFallbackThrowingException (io.github.resilience4j.feign.test.TestServiceFallbackThrowingException)3 TestServiceFallbackWithException (io.github.resilience4j.feign.test.TestServiceFallbackWithException)3 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 WireMock.verify (com.github.tomakehurst.wiremock.client.WireMock.verify)2 WireMockClassRule (com.github.tomakehurst.wiremock.junit.WireMockClassRule)2 FeignException (feign.FeignException)2 Function (java.util.function.Function)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ClassRule (org.junit.ClassRule)2 Rule (org.junit.Rule)2 Mockito (org.mockito.Mockito)2 Mockito.verify (org.mockito.Mockito.verify)2 MethodHandler (feign.InvocationHandlerFactory.MethodHandler)1 TestFeignDecorator (io.github.resilience4j.feign.test.TestFeignDecorator)1 TestServiceImpl (io.github.resilience4j.feign.test.TestServiceImpl)1 Before (org.junit.Before)1