gmunozfe commented on code in PR #4076:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4076#discussion_r2401581492


##########
quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/OperationsMockServiceError.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.quarkus.workflows;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.MappingBuilder;
+import com.github.tomakehurst.wiremock.matching.EqualToPattern;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static 
com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
+
+public class OperationsMockServiceError implements 
QuarkusTestResourceLifecycleManager {
+
+    private static WireMockServer subtractionService;
+    private static WireMockServer multiplicationService;
+
+    public static final String SUBTRACTION_SERVICE_MOCK_URL = 
"subtraction-service-mock.url";
+    public static final String MULTIPLICATION_SERVICE_MOCK_URL = 
"multiplication-service-mock.url";
+
+    @Override
+    public Map<String, String> start() {
+        multiplicationService =
+                startServer("{  \"product\": 37.808 }", p -> 
p.withHeader("pepe", new EqualToPattern("pepa")));
+        subtractionService =
+                startServer("{ \"difference\": 68.0 }", p -> p);
+
+        Map<String, String> result = new HashMap<>();
+        result.put(MULTIPLICATION_SERVICE_MOCK_URL, 
multiplicationService.baseUrl());
+        result.put(SUBTRACTION_SERVICE_MOCK_URL, subtractionService.baseUrl());
+        return result;
+    }
+
+    @Override
+    public void stop() {
+        if (multiplicationService != null) {
+            multiplicationService.stop();
+        }
+        if (subtractionService != null) {
+            subtractionService.stop();

Review Comment:
   Same here



##########
quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/OperationsMockServiceError.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.quarkus.workflows;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.MappingBuilder;
+import com.github.tomakehurst.wiremock.matching.EqualToPattern;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static 
com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
+
+public class OperationsMockServiceError implements 
QuarkusTestResourceLifecycleManager {
+
+    private static WireMockServer subtractionService;
+    private static WireMockServer multiplicationService;
+
+    public static final String SUBTRACTION_SERVICE_MOCK_URL = 
"subtraction-service-mock.url";
+    public static final String MULTIPLICATION_SERVICE_MOCK_URL = 
"multiplication-service-mock.url";
+
+    @Override
+    public Map<String, String> start() {
+        multiplicationService =
+                startServer("{  \"product\": 37.808 }", p -> 
p.withHeader("pepe", new EqualToPattern("pepa")));
+        subtractionService =
+                startServer("{ \"difference\": 68.0 }", p -> p);
+
+        Map<String, String> result = new HashMap<>();
+        result.put(MULTIPLICATION_SERVICE_MOCK_URL, 
multiplicationService.baseUrl());
+        result.put(SUBTRACTION_SERVICE_MOCK_URL, subtractionService.baseUrl());
+        return result;
+    }
+
+    @Override
+    public void stop() {
+        if (multiplicationService != null) {
+            multiplicationService.stop();

Review Comment:
   you can call also shutdown after stop: `multiplicationService.shutdown();`



##########
quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/OperationsMockServiceError.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.quarkus.workflows;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.MappingBuilder;
+import com.github.tomakehurst.wiremock.matching.EqualToPattern;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static 
com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
+
+public class OperationsMockServiceError implements 
QuarkusTestResourceLifecycleManager {
+
+    private static WireMockServer subtractionService;
+    private static WireMockServer multiplicationService;
+
+    public static final String SUBTRACTION_SERVICE_MOCK_URL = 
"subtraction-service-mock.url";
+    public static final String MULTIPLICATION_SERVICE_MOCK_URL = 
"multiplication-service-mock.url";
+
+    @Override
+    public Map<String, String> start() {
+        multiplicationService =
+                startServer("{  \"product\": 37.808 }", p -> 
p.withHeader("pepe", new EqualToPattern("pepa")));
+        subtractionService =
+                startServer("{ \"difference\": 68.0 }", p -> p);
+
+        Map<String, String> result = new HashMap<>();
+        result.put(MULTIPLICATION_SERVICE_MOCK_URL, 
multiplicationService.baseUrl());
+        result.put(SUBTRACTION_SERVICE_MOCK_URL, subtractionService.baseUrl());
+        return result;
+    }
+
+    @Override
+    public void stop() {
+        if (multiplicationService != null) {
+            multiplicationService.stop();
+        }
+        if (subtractionService != null) {
+            subtractionService.stop();
+        }
+    }
+
+    private static WireMockServer startServer(final String response, 
UnaryOperator<MappingBuilder> function) {
+        final WireMockServer server = new 
WireMockServer(options().dynamicPort());
+        server.start();
+        server.stubFor(function.apply(post(urlEqualTo("/")))
+                .withPort(server.port())

Review Comment:
   this is not needed for stub with WireMock
   ```suggestion
   ```



##########
quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/OperationsMockServiceError.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.quarkus.workflows;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.MappingBuilder;
+import com.github.tomakehurst.wiremock.matching.EqualToPattern;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static 
com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
+
+public class OperationsMockServiceError implements 
QuarkusTestResourceLifecycleManager {
+
+    private static WireMockServer subtractionService;
+    private static WireMockServer multiplicationService;

Review Comment:
   why are they static? probably it would be better to instantiate them in case 
the test runs in parallel in CIs



##########
quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow/src/main/java/org/kie/kogito/serverless/workflow/openapi/OpenApiWorkItemHandler.java:
##########
@@ -69,14 +78,29 @@ public void filter(ClientRequestContext requestContext) 
throws IOException {
                     });
                 }
             }
-        }, Integer.MIN_VALUE).build(clazz);
+        }, Integer.MIN_VALUE).register((ResponseExceptionMapper) response -> 
new WebApplicationException(fromResponse(response), 
response.getStatus())).build(clazz);
         try {
             return internalExecute(ref, parameters);
         } catch (WebApplicationException ex) {
             throw new 
WorkItemExecutionException(Integer.toString(ex.getResponse().getStatus()), 
ex.getMessage());
         }
     }
 
+    private String fromResponse(Response response) {
+        Object entity = response.getEntity();
+        if (entity instanceof ByteArrayInputStream input) {
+            if 
(MediaType.APPLICATION_JSON_TYPE.equals(response.getMediaType())) {
+                try {
+                    return 
ObjectMapperFactory.get().readTree(input).toString();
+                } catch (IOException e) {
+                    logger.warn("Error parsing json error response {}", 
e.toString());

Review Comment:
   why not to log the complete stack trace?
   ```suggestion
                       logger.warn("Error parsing json error response", e);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to