Search in sources :

Example 6 with IcecreamServiceApi

use of reactivefeign.testcase.IcecreamServiceApi in project feign-reactive by kptfh.

the class DefaultMethodTest method shouldOverrideToString.

@Test
public void shouldOverrideToString() {
    IcecreamServiceApi client = builder().target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    Assertions.assertThat(client.toString()).isEqualTo("HardCodedTarget(type=IcecreamServiceApi, " + "url=http://localhost:" + wireMockRule.port() + ")");
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) Test(org.junit.Test)

Example 7 with IcecreamServiceApi

use of reactivefeign.testcase.IcecreamServiceApi in project feign-reactive by kptfh.

the class ReadTimeoutTest method shouldFailOnReadTimeout.

@Test
public void shouldFailOnReadTimeout() {
    String orderUrl = "/icecream/orders/1";
    wireMockRule.stubFor(get(urlEqualTo(orderUrl)).withHeader("Accept", equalTo("application/json")).willReturn(aResponse().withFixedDelay(200)));
    IcecreamServiceApi client = builder(new ReactiveOptions.Builder().setConnectTimeoutMillis(300).setReadTimeoutMillis(100).build()).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(client.findOrder(1)).expectError(ReadTimeoutException.class).verify();
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) ReadTimeoutException(reactivefeign.client.ReadTimeoutException) Test(org.junit.Test)

Example 8 with IcecreamServiceApi

use of reactivefeign.testcase.IcecreamServiceApi in project feign-reactive by kptfh.

the class RetryingTest method shouldFailAsNoMoreRetries.

@Test
public void shouldFailAsNoMoreRetries() {
    String orderUrl = "/icecream/orders/1";
    wireMockRule.stubFor(get(urlEqualTo(orderUrl)).withHeader("Accept", equalTo("application/json")).willReturn(aResponse().withStatus(503).withHeader(RETRY_AFTER, "1")));
    IcecreamServiceApi client = builder().retryWhen(ReactiveRetryers.retry(3)).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(client.findOrder(1)).expectErrorMatches(throwable -> throwable instanceof RetryPublisherHttpClient.OutOfRetriesException && hasProperty("cause", isA(RetryableException.class)).matches(throwable)).verify();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) Matchers.isA(org.hamcrest.Matchers.isA) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) RETRY_AFTER(org.apache.http.HttpHeaders.RETRY_AFTER) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) WireMock(com.github.tomakehurst.wiremock.client.WireMock) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) RetryableException(feign.RetryableException) SC_OK(org.apache.http.HttpStatus.SC_OK) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) TestUtils.equalsComparingFieldByFieldRecursively(reactivefeign.TestUtils.equalsComparingFieldByFieldRecursively) SC_SERVICE_UNAVAILABLE(org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE) Mixin(reactivefeign.testcase.domain.Mixin) ClassRule(org.junit.ClassRule) RetryPublisherHttpClient(reactivefeign.publisher.RetryPublisherHttpClient) Before(org.junit.Before) RetryableException(feign.RetryableException) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) RetryPublisherHttpClient(reactivefeign.publisher.RetryPublisherHttpClient) Test(org.junit.Test)

Example 9 with IcecreamServiceApi

use of reactivefeign.testcase.IcecreamServiceApi in project feign-reactive by kptfh.

the class RetryingTest method shouldSuccessOnRetriesFlux.

@Test
public void shouldSuccessOnRetriesFlux() throws JsonProcessingException {
    String mixinsStr = TestUtils.MAPPER.writeValueAsString(Mixin.values());
    mockResponseAfterSeveralAttempts(wireMockRule, 2, "testRetrying_success", "/icecream/mixins", aResponse().withStatus(SC_SERVICE_UNAVAILABLE).withHeader(RETRY_AFTER, "1"), aResponse().withStatus(SC_OK).withHeader("Content-Type", "application/json").withBody(mixinsStr));
    IcecreamServiceApi client = builder().retryWhen(ReactiveRetryers.retryWithBackoff(3, 0)).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(client.getAvailableMixins()).expectNextSequence(Arrays.asList(Mixin.values())).verifyComplete();
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) Test(org.junit.Test)

Example 10 with IcecreamServiceApi

use of reactivefeign.testcase.IcecreamServiceApi in project feign-reactive by kptfh.

the class RetryingTest method shouldFailAsNoMoreRetriesWithBackoff.

@Test
public void shouldFailAsNoMoreRetriesWithBackoff() {
    String orderUrl = "/icecream/orders/1";
    wireMockRule.stubFor(get(urlEqualTo(orderUrl)).withHeader("Accept", equalTo("application/json")).willReturn(aResponse().withStatus(503).withHeader(RETRY_AFTER, "1")));
    IcecreamServiceApi client = builder().retryWhen(ReactiveRetryers.retryWithBackoff(7, 5)).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(client.findOrder(1)).expectErrorMatches(throwable -> throwable instanceof RetryPublisherHttpClient.OutOfRetriesException && hasProperty("cause", isA(RetryableException.class)).matches(throwable)).verify();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) Matchers.isA(org.hamcrest.Matchers.isA) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) RETRY_AFTER(org.apache.http.HttpHeaders.RETRY_AFTER) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) WireMock(com.github.tomakehurst.wiremock.client.WireMock) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) RetryableException(feign.RetryableException) SC_OK(org.apache.http.HttpStatus.SC_OK) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) TestUtils.equalsComparingFieldByFieldRecursively(reactivefeign.TestUtils.equalsComparingFieldByFieldRecursively) SC_SERVICE_UNAVAILABLE(org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE) Mixin(reactivefeign.testcase.domain.Mixin) ClassRule(org.junit.ClassRule) RetryPublisherHttpClient(reactivefeign.publisher.RetryPublisherHttpClient) Before(org.junit.Before) RetryableException(feign.RetryableException) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) RetryPublisherHttpClient(reactivefeign.publisher.RetryPublisherHttpClient) Test(org.junit.Test)

Aggregations

IcecreamServiceApi (reactivefeign.testcase.IcecreamServiceApi)22 Test (org.junit.Test)21 IceCreamOrder (reactivefeign.testcase.domain.IceCreamOrder)12 OrderGenerator (reactivefeign.testcase.domain.OrderGenerator)12 WireMockConfiguration.wireMockConfig (com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig)6 WireMockClassRule (com.github.tomakehurst.wiremock.junit.WireMockClassRule)6 Before (org.junit.Before)6 ClassRule (org.junit.ClassRule)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 WireMock (com.github.tomakehurst.wiremock.client.WireMock)4 RetryableException (feign.RetryableException)4 StepVerifier (reactor.test.StepVerifier)4 TestUtils.equalsComparingFieldByFieldRecursively (reactivefeign.TestUtils.equalsComparingFieldByFieldRecursively)3 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)2 WireMock.equalTo (com.github.tomakehurst.wiremock.client.WireMock.equalTo)2 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)2 WireMock.urlEqualTo (com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo)2 STARTED (com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED)2 Arrays (java.util.Arrays)2