Search in sources :

Example 6 with OrderGenerator

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

the class LoggerTest method shouldLog.

@Test
public void shouldLog() throws Exception {
    Level originalLevel = setLogLevel(Level.TRACE);
    IceCreamOrder order = new OrderGenerator().generate(20);
    Bill billExpected = Bill.makeBill(order);
    wireMockRule.stubFor(post(urlEqualTo("/icecream/orders")).withRequestBody(equalTo(TestUtils.MAPPER.writeValueAsString(order))).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(TestUtils.MAPPER.writeValueAsString(billExpected))));
    IcecreamServiceApi client = builder().target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    Mono<Bill> billMono = client.makeOrder(order);
    // no logs before subscription
    ArgumentCaptor<LogEvent> argumentCaptor = ArgumentCaptor.forClass(LogEvent.class);
    Mockito.verify(appender, never()).append(argumentCaptor.capture());
    billMono.block();
    Mockito.verify(appender, times(7)).append(argumentCaptor.capture());
    List<LogEvent> logEvents = argumentCaptor.getAllValues();
    assertLogEvent(logEvents, 0, Level.DEBUG, "[IcecreamServiceApi#makeOrder]--->POST http://localhost");
    assertLogEvent(logEvents, 1, Level.TRACE, "[IcecreamServiceApi#makeOrder] REQUEST HEADERS\n" + "Accept:[application/json]");
    assertLogEvent(logEvents, 2, Level.TRACE, "[IcecreamServiceApi#makeOrder] REQUEST BODY\n" + "IceCreamOrder{ id=20, balls=");
    assertLogEvent(logEvents, 3, Level.TRACE, "[IcecreamServiceApi#makeOrder] RESPONSE HEADERS", "Content-Type:application/json");
    assertLogEvent(logEvents, 4, Level.DEBUG, "[IcecreamServiceApi#makeOrder]<--- headers takes");
    assertLogEvent(logEvents, 5, Level.TRACE, "[IcecreamServiceApi#makeOrder] RESPONSE BODY\n" + "reactivefeign.testcase.domain.Bill");
    assertLogEvent(logEvents, 6, Level.DEBUG, "[IcecreamServiceApi#makeOrder]<--- body takes");
    setLogLevel(originalLevel);
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) LogEvent(org.apache.logging.log4j.core.LogEvent) Bill(reactivefeign.testcase.domain.Bill) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) Level(org.apache.logging.log4j.Level) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test)

Example 7 with OrderGenerator

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

the class ReactivityTest method shouldRunReactively.

@Test
public void shouldRunReactively() throws JsonProcessingException {
    IceCreamOrder orderGenerated = new OrderGenerator().generate(1);
    String orderStr = TestUtils.MAPPER.writeValueAsString(orderGenerated);
    wireMockRule.stubFor(get(urlEqualTo("/icecream/orders/1")).withHeader("Accept", equalTo("application/json")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(orderStr).withFixedDelay(DELAY_IN_MILLIS)));
    IcecreamServiceApi client = builder().target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    AtomicInteger counter = new AtomicInteger();
    new Thread(() -> {
        for (int i = 0; i < CALLS_NUMBER; i++) {
            client.findFirstOrder().doOnNext(order -> counter.incrementAndGet()).subscribe();
        }
    }).start();
    waitAtMost(new Duration(timeToCompleteReactively(), TimeUnit.MILLISECONDS)).until(() -> counter.get() == CALLS_NUMBER);
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) Duration(org.awaitility.Duration) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test)

Example 8 with OrderGenerator

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

the class RequestInterceptorTest method shouldInterceptRequestAndSetAuthHeader.

@Test
public void shouldInterceptRequestAndSetAuthHeader() throws JsonProcessingException {
    String orderUrl = "/icecream/orders/1";
    IceCreamOrder orderGenerated = new OrderGenerator().generate(1);
    String orderStr = TestUtils.MAPPER.writeValueAsString(orderGenerated);
    wireMockRule.stubFor(get(urlEqualTo(orderUrl)).withHeader("Accept", equalTo("application/json")).willReturn(aResponse().withStatus(HttpStatus.SC_UNAUTHORIZED))).setPriority(100);
    wireMockRule.stubFor(get(urlEqualTo(orderUrl)).withHeader("Accept", equalTo("application/json")).withHeader("Authorization", equalTo("Bearer mytoken123")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(orderStr))).setPriority(1);
    IcecreamServiceApi clientWithoutAuth = builder().target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(clientWithoutAuth.findFirstOrder()).expectError(notAuthorizedException()).verify();
    IcecreamServiceApi clientWithAuth = builder().addHeaders(singletonList(new Pair<>("Authorization", "Bearer mytoken123"))).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(clientWithAuth.findFirstOrder()).expectNextMatches(equalsComparingFieldByFieldRecursively(orderGenerated)).expectComplete();
}
Also used : IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test)

Example 9 with OrderGenerator

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

the class ReactiveHttpClientTest method testMakeOrder_success.

@Test
public void testMakeOrder_success() {
    IceCreamOrder order = new OrderGenerator().generate(20);
    Bill bill = client.makeOrder(order).block();
    assertThat(bill).isEqualToComparingFieldByField(Bill.makeBill(order));
}
Also used : Bill(reactivefeign.testcase.domain.Bill) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with OrderGenerator

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

the class DefaultMethodTest method shouldProcessDefaultMethodOnProxy.

@Test
public void shouldProcessDefaultMethodOnProxy() throws JsonProcessingException {
    IceCreamOrder orderGenerated = new OrderGenerator().generate(1);
    String orderStr = TestUtils.MAPPER.writeValueAsString(orderGenerated);
    wireMockRule.stubFor(get(urlEqualTo("/icecream/orders/1")).withHeader("Accept", equalTo("application/json")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(orderStr)));
    IcecreamServiceApi client = builder().target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(client.findFirstOrder()).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 OrderGenerator (reactivefeign.testcase.domain.OrderGenerator)12 IceCreamOrder (reactivefeign.testcase.domain.IceCreamOrder)11 IcecreamServiceApi (reactivefeign.testcase.IcecreamServiceApi)10 Bill (reactivefeign.testcase.domain.Bill)4 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 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