Skip to content

Commit

Permalink
KOGITO-8410 Added support for Number and Boolean to GetRequestKnative…
Browse files Browse the repository at this point in the history
…ParamsDecorator

Signed-off-by: Helber Belmiro <[email protected]>
  • Loading branch information
hbelmiro committed Aug 14, 2023
1 parent b31d488 commit 447d1ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public void decorate(KogitoWorkItem workItem, Map<String, Object> 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.";
throw new IllegalArgumentException(MessageFormat.format(message, key, value.getClass()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ class GetRequestKnativeParamsDecoratorTest {

@Test
void decorate() {
Map<String, String> expectedParams = Map.of(
Map<String, Object> expectedParams = Map.of(
"key1", "value1",
"key2", "value2");
"key2", "value2",
"booleanParam", true,
"numberParam", 42);

HttpRequest<?> request = createRequest();

Expand All @@ -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<String, Object> expectedParams = Map.of(
"key1", "value1",
"key2", new Object());
Expand Down

0 comments on commit 447d1ac

Please sign in to comment.