Search in sources :

Example 1 with TestServiceFallbackWithException

use of io.github.resilience4j.feign.test.TestServiceFallbackWithException 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 2 with TestServiceFallbackWithException

use of io.github.resilience4j.feign.test.TestServiceFallbackWithException 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)

Example 3 with TestServiceFallbackWithException

use of io.github.resilience4j.feign.test.TestServiceFallbackWithException in project resilience4j by resilience4j.

the class Resilience4jFeignFallbackFactoryTest method should_go_to_fallback_and_consume_exception_with_exception_filter.

@Test
public void should_go_to_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(TestServiceFallbackWithException::new, FeignException.class).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) TestServiceFallbackWithException(io.github.resilience4j.feign.test.TestServiceFallbackWithException) Test(org.junit.Test)

Aggregations

TestService (io.github.resilience4j.feign.test.TestService)3 TestServiceFallbackWithException (io.github.resilience4j.feign.test.TestServiceFallbackWithException)3 Test (org.junit.Test)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 TestServiceFallbackThrowingException (io.github.resilience4j.feign.test.TestServiceFallbackThrowingException)2 Function (java.util.function.Function)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)2 ClassRule (org.junit.ClassRule)2 Rule (org.junit.Rule)2 Mockito (org.mockito.Mockito)2 Mockito.verify (org.mockito.Mockito.verify)2