Search in sources :

Example 21 with IcecreamServiceApi

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

the class StatusHandlerTest method shouldThrowRetryException.

@Test
public void shouldThrowRetryException() {
    wireMockRule.stubFor(get(urlEqualTo("/icecream/orders/1")).withHeader("Accept", equalTo("application/json")).willReturn(aResponse().withStatus(HttpStatus.SC_SERVICE_UNAVAILABLE)));
    IcecreamServiceApi client = builder().statusHandler(throwOnStatus(status -> status == HttpStatus.SC_SERVICE_UNAVAILABLE, (methodTag, response) -> new RetryableException("Should retry on next node", null))).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(client.findFirstOrder()).expectError(RetryableException.class);
}
Also used : RetryableException(feign.RetryableException) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) Test(org.junit.Test)

Example 22 with IcecreamServiceApi

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

the class CompressionTest method testCompression.

@Test
public void testCompression() throws JsonProcessingException {
    IceCreamOrder order = new OrderGenerator().generate(20);
    Bill billExpected = Bill.makeBill(order);
    wireMockRule.stubFor(post(urlEqualTo("/icecream/orders")).withHeader("Accept-Encoding", containing("gzip")).withRequestBody(equalTo(TestUtils.MAPPER.writeValueAsString(order))).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withHeader("Content-Encoding", "gzip").withBody(Gzip.gzip(TestUtils.MAPPER.writeValueAsString(billExpected)))));
    IcecreamServiceApi client = builder(new ReactiveOptions.Builder().setTryUseCompression(true).build()).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    Mono<Bill> bill = client.makeOrder(order);
    StepVerifier.create(bill).expectNextMatches(equalsComparingFieldByFieldRecursively(billExpected)).verifyComplete();
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) Bill(reactivefeign.testcase.domain.Bill) 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