Search in sources :

Example 1 with Bill

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

the class ReactiveHttpClientTest method testPayBill_success.

@Test
public void testPayBill_success() {
    Bill bill = Bill.makeBill(new OrderGenerator().generate(30));
    client.payBill(bill).block();
}
Also used : Bill(reactivefeign.testcase.domain.Bill) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Bill

use of reactivefeign.testcase.domain.Bill 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 3 with Bill

use of reactivefeign.testcase.domain.Bill 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 4 with Bill

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

Test (org.junit.Test)4 Bill (reactivefeign.testcase.domain.Bill)4 OrderGenerator (reactivefeign.testcase.domain.OrderGenerator)4 IceCreamOrder (reactivefeign.testcase.domain.IceCreamOrder)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 IcecreamServiceApi (reactivefeign.testcase.IcecreamServiceApi)2 Level (org.apache.logging.log4j.Level)1 LogEvent (org.apache.logging.log4j.core.LogEvent)1