Search in sources :

Example 11 with TestService

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

the class Resilience4jFeignFallbackFactoryTest method should_go_to_fallback_and_rethrow_an_exception_thrown_in_fallback.

@Test
public void should_go_to_fallback_and_rethrow_an_exception_thrown_in_fallback() {
    setupStub(400);
    TestService testService = buildTestService(e -> new TestServiceFallbackThrowingException());
    Throwable result = catchThrowable(testService::greeting);
    assertThat(result).isNotNull().isInstanceOf(RuntimeException.class).hasMessageContaining("Exception in greeting fallback");
    verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}
Also used : TestService(io.github.resilience4j.feign.test.TestService) TestServiceFallbackThrowingException(io.github.resilience4j.feign.test.TestServiceFallbackThrowingException) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 12 with TestService

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

the class Resilience4jFeignFallbackFactoryTest method should_successfully_get_a_response.

@Test
public void should_successfully_get_a_response() {
    setupStub(200);
    TestService testService = buildTestService(e -> "my fallback");
    String result = testService.greeting();
    assertThat(result).isEqualTo("Hello, world!");
    verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}
Also used : TestService(io.github.resilience4j.feign.test.TestService) Test(org.junit.Test)

Example 13 with TestService

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

the class Resilience4jFeignFallbackFactoryTest method should_lazily_fail_on_invalid_fallback.

@Test
public void should_lazily_fail_on_invalid_fallback() {
    TestService testService = buildTestService(e -> "my fallback");
    Throwable throwable = catchThrowable(testService::greeting);
    assertThat(throwable).isNotNull().hasMessageContaining("Cannot use the fallback [class java.lang.String] for [interface io.github.resilience4j.feign.test.TestService]");
}
Also used : TestService(io.github.resilience4j.feign.test.TestService) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) 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