From 960afd72151700111c25edb96bd29878c458952c Mon Sep 17 00:00:00 2001 From: Helber Belmiro Date: Mon, 14 Aug 2023 12:06:52 -0300 Subject: [PATCH] KOGITO-8410 Added support for Number and Boolean to GetRequestKnativeParamsDecorator Signed-off-by: Helber Belmiro --- .../GetRequestKnativeParamsDecorator.java | 4 +++- .../GetRequestKnativeParamsDecoratorTest.java | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/quarkus/addons/knative/serving/runtime/src/main/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/GetRequestKnativeParamsDecorator.java b/quarkus/addons/knative/serving/runtime/src/main/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/GetRequestKnativeParamsDecorator.java index 42c456db07f..7937e03a03a 100644 --- a/quarkus/addons/knative/serving/runtime/src/main/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/GetRequestKnativeParamsDecorator.java +++ b/quarkus/addons/knative/serving/runtime/src/main/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/GetRequestKnativeParamsDecorator.java @@ -30,8 +30,10 @@ public void decorate(KogitoWorkItem workItem, Map parameters, Ht KnativeFunctionPayloadSupplier.getPayload(parameters).forEach((key, value) -> { if (value instanceof String) { request.addQueryParam(key, (String) value); + } else if (value instanceof Number || value instanceof Boolean) { + request.addQueryParam(key, String.valueOf(value)); } else { - String message = "Knative functions support only GET requests with String attributes. {0} has a {1} value."; + String message = "Knative functions support only GET requests with String, Number or Boolean attributes. {0} has a {1} value."; throw new IllegalArgumentException(MessageFormat.format(message, key, value.getClass())); } }); diff --git a/quarkus/addons/knative/serving/runtime/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/GetRequestKnativeParamsDecoratorTest.java b/quarkus/addons/knative/serving/runtime/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/GetRequestKnativeParamsDecoratorTest.java index 342f19d6296..1b3248be032 100644 --- a/quarkus/addons/knative/serving/runtime/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/GetRequestKnativeParamsDecoratorTest.java +++ b/quarkus/addons/knative/serving/runtime/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/GetRequestKnativeParamsDecoratorTest.java @@ -43,9 +43,11 @@ class GetRequestKnativeParamsDecoratorTest { @Test void decorate() { - Map expectedParams = Map.of( + Map expectedParams = Map.of( "key1", "value1", - "key2", "value2"); + "key2", "value2", + "booleanParam", true, + "numberParam", 42); HttpRequest request = createRequest(); @@ -54,12 +56,12 @@ void decorate() { decorator.decorate(null, parameters, request); - assertThat(request.queryParams()).hasSize(2); - expectedParams.forEach((k, v) -> assertThat(request.queryParams().get(k)).isEqualTo(v)); + assertThat(request.queryParams()).hasSize(4); + expectedParams.forEach((k, v) -> assertThat(request.queryParams().get(k)).isEqualTo(String.valueOf(v))); } @Test - void decorateNonStringValuesShouldThrowException() { + void decorateInvalidTypeShouldThrowException() { Map expectedParams = Map.of( "key1", "value1", "key2", new Object());