Search in sources :

Example 1 with IceCreamOrder

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

the class DefaultMethodTest method shouldWrapExceptionWithFlux.

@Test
public void shouldWrapExceptionWithFlux() throws JsonProcessingException {
    IceCreamOrder orderGenerated = new OrderGenerator().generate(1);
    IcecreamServiceApi client = ReactiveFeign.<IcecreamServiceApi>builder().webClient(WebClient.create()).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    IceCreamOrder errorOrder = client.throwExceptionFlux().onErrorReturn(throwable -> throwable.equals(IcecreamServiceApi.RUNTIME_EXCEPTION), orderGenerated).blockFirst();
    assertThat(errorOrder).isEqualToComparingFieldByField(orderGenerated);
}
Also used : WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) Java6Assertions.assertThat(org.assertj.core.api.Java6Assertions.assertThat) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) WebClient(org.springframework.web.reactive.function.client.WebClient) Test(org.junit.Test) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AllFeaturesApi(reactivefeign.allfeatures.AllFeaturesApi) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) Rule(org.junit.Rule) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) ClassRule(org.junit.ClassRule) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test)

Example 2 with IceCreamOrder

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

the class DefaultMethodTest method shouldWrapExceptionWithMono.

@Test
public void shouldWrapExceptionWithMono() throws JsonProcessingException {
    IceCreamOrder orderGenerated = new OrderGenerator().generate(1);
    IcecreamServiceApi client = ReactiveFeign.<IcecreamServiceApi>builder().webClient(WebClient.create()).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    IceCreamOrder errorOrder = client.throwExceptionMono().onErrorReturn(throwable -> throwable.equals(IcecreamServiceApi.RUNTIME_EXCEPTION), orderGenerated).block();
    assertThat(errorOrder).isEqualToComparingFieldByField(orderGenerated);
}
Also used : WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) Java6Assertions.assertThat(org.assertj.core.api.Java6Assertions.assertThat) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) WebClient(org.springframework.web.reactive.function.client.WebClient) Test(org.junit.Test) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AllFeaturesApi(reactivefeign.allfeatures.AllFeaturesApi) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) Rule(org.junit.Rule) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) ClassRule(org.junit.ClassRule) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test)

Example 3 with IceCreamOrder

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

the class ReactiveHttpClientTest method testFindOrder_success.

@Test
public void testFindOrder_success() {
    IceCreamOrder order = client.findOrder(1).block();
    Assertions.assertThat(order).isEqualToComparingFieldByFieldRecursively(icecreamController.findOrder(1).block());
    Optional<IceCreamOrder> orderOptional = client.findOrder(123).blockOptional();
    assertThat(!orderOptional.isPresent());
}
Also used : IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with IceCreamOrder

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

the class DefaultMethodTest method shouldNotWrapException.

@Test(expected = RuntimeException.class)
public void shouldNotWrapException() {
    IceCreamOrder orderGenerated = new OrderGenerator().generate(1);
    IcecreamServiceApi client = builder().target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    client.throwsException().onErrorReturn(throwable -> throwable.equals(IcecreamServiceApi.RUNTIME_EXCEPTION), orderGenerated).block();
}
Also used : StepVerifier(reactor.test.StepVerifier) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) RequestLine(feign.RequestLine) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) WireMock(com.github.tomakehurst.wiremock.client.WireMock) Flux(reactor.core.publisher.Flux) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) TestUtils.equalsComparingFieldByFieldRecursively(reactivefeign.TestUtils.equalsComparingFieldByFieldRecursively) Assertions(org.assertj.core.api.Assertions) ClassRule(org.junit.ClassRule) Before(org.junit.Before) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test)

Example 5 with IceCreamOrder

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

the class RetryingTest method shouldSuccessOnRetriesMono.

@Test
public void shouldSuccessOnRetriesMono() throws JsonProcessingException {
    IceCreamOrder orderGenerated = new OrderGenerator().generate(1);
    String orderStr = TestUtils.MAPPER.writeValueAsString(orderGenerated);
    mockResponseAfterSeveralAttempts(wireMockRule, 2, "testRetrying_success", "/icecream/orders/1", aResponse().withStatus(503).withHeader(RETRY_AFTER, "1"), aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(orderStr));
    IcecreamServiceApi client = builder().retryWhen(ReactiveRetryers.retryWithBackoff(3, 0)).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(client.findOrder(1)).expectNextMatches(equalsComparingFieldByFieldRecursively(orderGenerated)).verifyComplete();
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 IceCreamOrder (reactivefeign.testcase.domain.IceCreamOrder)12 OrderGenerator (reactivefeign.testcase.domain.OrderGenerator)11 IcecreamServiceApi (reactivefeign.testcase.IcecreamServiceApi)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 WireMockConfiguration.wireMockConfig (com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig)3 WireMockClassRule (com.github.tomakehurst.wiremock.junit.WireMockClassRule)3 Before (org.junit.Before)3 ClassRule (org.junit.ClassRule)3 Bill (reactivefeign.testcase.domain.Bill)3 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 Java6Assertions.assertThat (org.assertj.core.api.Java6Assertions.assertThat)2 Rule (org.junit.Rule)2 ExpectedException (org.junit.rules.ExpectedException)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 WebClient (org.springframework.web.reactive.function.client.WebClient)2 AllFeaturesApi (reactivefeign.allfeatures.AllFeaturesApi)2