Search in sources :

Example 1 with IcecreamServiceApi

use of reactivefeign.testcase.IcecreamServiceApi 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 IcecreamServiceApi

use of reactivefeign.testcase.IcecreamServiceApi 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 IcecreamServiceApi

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

the class ReactiveHttpOptionsTest method testCompression.

@Test
public void testCompression() {
    ReactiveOptions options = new ReactiveOptions.Builder().setConnectTimeoutMillis(5000).setReadTimeoutMillis(5000).setTryUseCompression(true).build();
    IcecreamServiceApi client = ReactiveFeign.<IcecreamServiceApi>builder().webClient(webClient).options(options).target(IcecreamServiceApi.class, targetUrl);
    testClient(client);
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with IcecreamServiceApi

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

the class DefaultMethodTest method shouldOverrideEquals.

@Test
public void shouldOverrideEquals() {
    IcecreamServiceApi client = builder(new ReactiveOptions.Builder().setConnectTimeoutMillis(300).setReadTimeoutMillis(100).build()).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    IcecreamServiceApi clientWithSameTarget = builder().target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    Assertions.assertThat(client).isEqualTo(clientWithSameTarget);
    IcecreamServiceApi clientWithOtherPort = builder().target(IcecreamServiceApi.class, "http://localhost:" + (wireMockRule.port() + 1));
    Assertions.assertThat(client).isNotEqualTo(clientWithOtherPort);
    OtherApi clientWithOtherInterface = builder(OtherApi.class).target(OtherApi.class, "http://localhost:" + wireMockRule.port());
    Assertions.assertThat(client).isNotEqualTo(clientWithOtherInterface);
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) Test(org.junit.Test)

Example 5 with IcecreamServiceApi

use of reactivefeign.testcase.IcecreamServiceApi 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)

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