|
15 | 15 | */ |
16 | 16 | package io.gravitee.policy; |
17 | 17 |
|
18 | | -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
19 | | -import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; |
20 | | -import static com.github.tomakehurst.wiremock.client.WireMock.get; |
21 | | -import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; |
22 | | -import static com.github.tomakehurst.wiremock.client.WireMock.ok; |
23 | | -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; |
| 18 | +import static com.github.tomakehurst.wiremock.client.WireMock.*; |
24 | 19 | import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; |
25 | 20 | import static org.assertj.core.api.Assertions.assertThat; |
26 | 21 |
|
|
35 | 30 | import io.gravitee.policy.callout.CalloutHttpPolicy; |
36 | 31 | import io.gravitee.policy.callout.configuration.CalloutHttpPolicyConfiguration; |
37 | 32 | import io.reactivex.observers.TestObserver; |
| 33 | +import io.vertx.core.http.HttpHeaders; |
| 34 | +import io.vertx.core.json.JsonObject; |
38 | 35 | import io.vertx.reactivex.core.buffer.Buffer; |
39 | 36 | import io.vertx.reactivex.ext.web.client.HttpResponse; |
40 | 37 | import io.vertx.reactivex.ext.web.client.WebClient; |
@@ -103,6 +100,37 @@ void shouldDoCalloutAndSetResponseAsAttribute(WebClient client) throws Exception |
103 | 100 | calloutServer.verify(getRequestedFor(urlPathEqualTo("/callout")).withHeader("X-Callout", equalTo("calloutHeader"))); |
104 | 101 | } |
105 | 102 |
|
| 103 | + @Test |
| 104 | + @DisplayName("Should call callout endpoint with proper body when it contains accents") |
| 105 | + @DeployApi("/apis/callout-http-post-with-accents.json") |
| 106 | + void shouldDoCalloutAndSetResponseWithAccentAsAttribute(WebClient client) { |
| 107 | + wiremock.stubFor(post("/endpoint").willReturn(ok("réponse from backend"))); |
| 108 | + calloutServer.stubFor(post("/callout").willReturn(ok("response from callout"))); |
| 109 | + |
| 110 | + final TestObserver<HttpResponse<Buffer>> obs = client |
| 111 | + .post("/test") |
| 112 | + .rxSendJsonObject(new JsonObject().put("clé", "value").put("key", "välæur")) |
| 113 | + .test(); |
| 114 | + |
| 115 | + awaitTerminalEvent(obs); |
| 116 | + obs |
| 117 | + .assertComplete() |
| 118 | + .assertValue(response -> { |
| 119 | + assertThat(response.statusCode()).isEqualTo(200); |
| 120 | + assertThat(response.bodyAsString()).isEqualTo("réponse from backend"); |
| 121 | + return true; |
| 122 | + }) |
| 123 | + .assertNoErrors(); |
| 124 | + |
| 125 | + wiremock.verify(postRequestedFor(urlPathEqualTo("/endpoint"))); |
| 126 | + calloutServer.verify( |
| 127 | + postRequestedFor(urlPathEqualTo("/callout")) |
| 128 | + .withoutHeader(HttpHeaders.TRANSFER_ENCODING.toString()) |
| 129 | + .withHeader(HttpHeaders.CONTENT_LENGTH.toString(), equalTo("33")) |
| 130 | + .withRequestBody(equalToJson("{\"clé\":\"value\", \"key\":\"välæur\"}")) |
| 131 | + ); |
| 132 | + } |
| 133 | + |
106 | 134 | @Test |
107 | 135 | @DisplayName("Should do callout Fire and Forget") |
108 | 136 | @DeployApi("/apis/callout-http-fire-and-forget.json") |
|
0 commit comments