|
14 | 14 |
|
15 | 15 | import java.io.IOException;
|
16 | 16 | import java.time.LocalDateTime;
|
| 17 | +import java.time.ZoneId; |
| 18 | +import java.time.ZonedDateTime; |
17 | 19 | import java.util.AbstractMap.SimpleEntry;
|
18 | 20 | import java.util.Arrays;
|
19 | 21 | import java.util.Collections;
|
|
34 | 36 | import org.mockito.stubbing.Answer;
|
35 | 37 |
|
36 | 38 | import apimatic.core.mocks.MockCoreConfig;
|
| 39 | +import apimatic.core.models.Car; |
37 | 40 | import apimatic.core.models.Employee;
|
| 41 | +import apimatic.core.models.Rfc1123Date; |
| 42 | +import apimatic.core.models.containers.SendScalarParamBody; |
38 | 43 | import io.apimatic.core.ApiCall;
|
39 | 44 | import io.apimatic.core.HttpRequest;
|
40 | 45 | import io.apimatic.core.authentication.HeaderAuth;
|
@@ -311,6 +316,49 @@ public void testHeaderPrecedenceOverAdditional() throws IOException {
|
311 | 316 | assertEquals(actualContentType, expectedContentType);
|
312 | 317 | }
|
313 | 318 |
|
| 319 | + /** |
| 320 | + * An instance of {@link LocalDateTime}. |
| 321 | + */ |
| 322 | + private static final LocalDateTime LOCAL_DATE_TIME = LocalDateTime.of(2021, 1, 20, 12, 12, 41); |
| 323 | + /** |
| 324 | + * An instance of {@link ZonedDateTime}. |
| 325 | + */ |
| 326 | + private static final ZonedDateTime ZONED_DATE_TIME = |
| 327 | + ZonedDateTime.of(LOCAL_DATE_TIME, ZoneId.of("GMT")); |
| 328 | + private static final double PRECISION_NUMBER1 = 100.11; |
| 329 | + private static final double PRECISION_NUMBER2 = 133.0; |
| 330 | + |
| 331 | + @Test |
| 332 | + public void testComplexHeaderParameter() throws IOException { |
| 333 | + // when |
| 334 | + String jsonObject = "{\"NumberOfTyres\":\"4\",\"HaveTrunk\":true}"; |
| 335 | + Car car = CoreHelper.tryDeserialize(jsonObject, Car.class); |
| 336 | + |
| 337 | + SendScalarParamBody bodyStringType = SendScalarParamBody.fromMString("some string"); |
| 338 | + SendScalarParamBody precisionArray = SendScalarParamBody.fromPrecision( |
| 339 | + Arrays.asList(PRECISION_NUMBER1, PRECISION_NUMBER2)); |
| 340 | + Rfc1123Date rfc1123Date = new Rfc1123Date.Builder() |
| 341 | + .dateTime(LOCAL_DATE_TIME) |
| 342 | + .zonedDateTime(ZONED_DATE_TIME) |
| 343 | + .build(); |
| 344 | + |
| 345 | + Request coreHttpRequest = |
| 346 | + new HttpRequest.Builder().httpMethod(Method.GET) |
| 347 | + .formParam(param -> param.key("formKey").value("value")) |
| 348 | + .headerParam(param -> param.key("accept").value("application/json")) |
| 349 | + .headerParam(param -> param.key("car-complex-header").value(car)) |
| 350 | + .headerParam(param -> param.key("any-of-string").value(bodyStringType)) |
| 351 | + .headerParam(param -> param.key("precision-array").value(precisionArray)) |
| 352 | + .headerParam(param -> param.key("date-time-header").value(rfc1123Date)) |
| 353 | + .build(getMockGlobalConfig()); |
| 354 | + |
| 355 | + when(coreHttpRequest.getHeaders()).thenReturn(getHttpHeaders()); |
| 356 | + when(getHttpHeaders().value("car-complex-header")).thenReturn(jsonObject); |
| 357 | + |
| 358 | + // verify |
| 359 | + assertEquals(coreHttpRequest.getHeaders().value("car-complex-header"), jsonObject); |
| 360 | + } |
| 361 | + |
314 | 362 | @Test
|
315 | 363 | public void testHeaderParamMultiple() throws IOException {
|
316 | 364 | // when
|
|
0 commit comments