Skip to content

Commit cf4cfc0

Browse files
committed
Improve test
1 parent f6c022f commit cf4cfc0

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/ApiClientWithRequestCustomizerTest.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
1212
import org.apache.hc.core5.http.Header;
13+
import org.apache.hc.core5.http.io.entity.EntityUtils;
1314
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
1415
import org.apache.hc.core5.http.protocol.HttpContext;
1516
import org.junit.jupiter.api.Test;
@@ -30,38 +31,31 @@ void testRequestCustomizer()
3031

3132
// Use the withRequestCustomizer API to add a custom header
3233
final UnaryOperator<ClassicRequestBuilder> customizer =
33-
builder -> builder.addHeader("X-Custom-Header", "custom-value");
34+
builder -> builder.setPath("/custom-path").addHeader("X-Custom", "custom");
3435

3536
final var apiClient = ApiClient.fromHttpClient(httpClient).withRequestCustomizer(customizer);
3637
new DefaultApi(apiClient).findPets();
3738

3839
verify(httpClient).execute(argThat(req -> Try.run(() -> {
39-
assertThat(req.getRequestUri()).isEqualTo("/pets");
40+
assertThat(req.getRequestUri()).isEqualTo("/custom-path");
4041
assertThat(req.getMethod()).isEqualTo("GET");
41-
assertThat(req.getHeaders())
42-
.extracting(Header::getName)
43-
.containsExactlyInAnyOrder("Accept", "X-Custom-Header");
44-
assertThat(req.getFirstHeader("X-Custom-Header").getValue()).isEqualTo("custom-value");
42+
assertThat(req.getHeaders()).extracting(Header::getName).containsExactlyInAnyOrder("Accept", "X-Custom");
43+
assertThat(req.getFirstHeader("X-Custom").getValue()).isEqualTo("custom");
4544
assertThat(req.getFirstHeader("Accept").getValue()).isEqualTo("application/json");
4645
}).isSuccess()), any(HttpContext.class), any());
4746
}
4847

4948
@Test
5049
@SneakyThrows
51-
void testRequestCustomizerWithMultipleHeaders()
50+
void testRequestCustomizerWithEntity()
5251
{
5352
final CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
5453

55-
// Chain multiple customizations
56-
final UnaryOperator<ClassicRequestBuilder> customizer =
57-
builder -> builder.addHeader("X-Correlation-Id", "12345").addHeader("X-Tenant-Id", "tenant-abc");
58-
59-
final var apiClient = ApiClient.fromHttpClient(httpClient).withRequestCustomizer(customizer);
54+
final var apiClient = ApiClient.fromHttpClient(httpClient).withRequestCustomizer(b -> b.setEntity("foo"));
6055
new DefaultApi(apiClient).findPets();
6156

6257
verify(httpClient).execute(argThat(req -> Try.run(() -> {
63-
assertThat(req.getFirstHeader("X-Correlation-Id").getValue()).isEqualTo("12345");
64-
assertThat(req.getFirstHeader("X-Tenant-Id").getValue()).isEqualTo("tenant-abc");
58+
assertThat(EntityUtils.toString(req.getEntity())).isEqualTo("foo");
6559
}).isSuccess()), any(HttpContext.class), any());
6660
}
6761

0 commit comments

Comments
 (0)