You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/08/17 15:13:27 UTC

[camel] branch camel-3.21.x updated: Camel 19756 throw error operation does not set processor 3.21.x (#11144)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.21.x by this push:
     new 92384727f0d Camel 19756 throw error operation does not set processor 3.21.x (#11144)
92384727f0d is described below

commit 92384727f0d0075e1a3a40182c4d0d5f6a560156
Author: LoRez <ka...@me.com>
AuthorDate: Thu Aug 17 17:13:20 2023 +0200

    Camel 19756 throw error operation does not set processor 3.21.x (#11144)
    
    * Set Processor in Producer for ThrowError and implement Integration Test
    
    * Fixed imports formatting in ThrowErrorIT
---
 .../camel/component/zeebe/ZeebeProducer.java       |   1 +
 .../camel/component/zeebe/model/JobRequest.java    |   2 +-
 .../component/zeebe/model/MessageRequest.java      |   2 +-
 .../component/zeebe/model/ProcessRequest.java      |   2 +-
 .../apache/camel/component/zeebe/ThrowErrorIT.java | 106 +++++++++++++++++++++
 5 files changed, 110 insertions(+), 3 deletions(-)

diff --git a/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/ZeebeProducer.java b/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/ZeebeProducer.java
index 6001feabfff..53b8fa88be6 100644
--- a/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/ZeebeProducer.java
+++ b/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/ZeebeProducer.java
@@ -93,6 +93,7 @@ public class ZeebeProducer extends DefaultProducer {
             case COMPLETE_JOB:
             case FAIL_JOB:
             case UPDATE_JOB_RETRIES:
+            case THROW_ERROR:
                 return true;
             default:
                 return false;
diff --git a/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/JobRequest.java b/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/JobRequest.java
index 7a2901bd72f..96242b63989 100644
--- a/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/JobRequest.java
+++ b/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/JobRequest.java
@@ -25,7 +25,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 @JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true, value = { "success", "error_message", "error_code" }, allowGetters = true)
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class JobRequest implements ZeebeMessage {
 
     @JsonProperty("job_key")
diff --git a/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/MessageRequest.java b/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/MessageRequest.java
index b52f5b8dfd1..d0b650c93ac 100644
--- a/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/MessageRequest.java
+++ b/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/MessageRequest.java
@@ -25,7 +25,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 @JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true, value = { "success", "error_message", "error_code" }, allowGetters = true)
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class MessageRequest implements ZeebeMessage {
 
     private String name;
diff --git a/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/ProcessRequest.java b/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/ProcessRequest.java
index c635e59cdbc..935d41497bc 100644
--- a/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/ProcessRequest.java
+++ b/components/camel-zeebe/src/main/java/org/apache/camel/component/zeebe/model/ProcessRequest.java
@@ -29,7 +29,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
  * Contains information about a Zeebe process
  */
 @JsonInclude(Include.NON_NULL)
-@JsonIgnoreProperties(ignoreUnknown = true, value = { "success", "error_message", "error_code" }, allowGetters = true)
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class ProcessRequest implements ZeebeMessage {
 
     @JsonProperty(value = "process_id")
diff --git a/components/camel-zeebe/src/test/java/org/apache/camel/component/zeebe/ThrowErrorIT.java b/components/camel-zeebe/src/test/java/org/apache/camel/component/zeebe/ThrowErrorIT.java
new file mode 100644
index 00000000000..714f298e084
--- /dev/null
+++ b/components/camel-zeebe/src/test/java/org/apache/camel/component/zeebe/ThrowErrorIT.java
@@ -0,0 +1,106 @@
+/*
+ * 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.apache.camel.component.zeebe;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.zeebe.model.JobRequest;
+import org.apache.camel.component.zeebe.model.JobResponse;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@EnabledIfSystemProperty(named = "zeebe.test.integration.enable", matches = "true",
+                         disabledReason = "Requires locally installed test system")
+public class ThrowErrorIT extends CamelTestSupport {
+
+    protected ZeebeComponent component;
+
+    private final ObjectMapper objectMapper = new ObjectMapper();
+
+    @Test
+    void testThrowError() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:throwError");
+        mock.expectedMinimumMessageCount(1);
+
+        JobRequest jobRequest = new JobRequest();
+        jobRequest.setJobKey(11L);
+        jobRequest.setErrorCode("TestError");
+        jobRequest.setErrorMessage("TestMessage");
+
+        template.sendBody("direct:throwError", jobRequest);
+        MockEndpoint.assertIsSatisfied(context);
+        if (!mock.getExchanges().isEmpty()) {
+            Exchange exchange = mock.getExchanges().get(0);
+            Object body = exchange.getMessage().getBody();
+            assertTrue(body instanceof JobResponse);
+            assertFalse(((JobResponse) body).isSuccess()); // The job does not exist in Zeebe
+        }
+    }
+
+    @Test
+    void testThrowErrorJSON() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:throwError_JSON");
+        mock.expectedMinimumMessageCount(1);
+
+        JobRequest jobRequest = new JobRequest();
+        jobRequest.setJobKey(11L);
+        jobRequest.setErrorCode("TestError");
+        jobRequest.setErrorMessage("TestMessage");
+
+        template.sendBody("direct:throwError_JSON", objectMapper.writeValueAsString(jobRequest));
+        MockEndpoint.assertIsSatisfied(context);
+        if (!mock.getExchanges().isEmpty()) {
+            Exchange exchange = mock.getExchanges().get(0);
+            String body = exchange.getMessage().getBody(String.class);
+            JobResponse response = objectMapper.readValue(body, JobResponse.class);
+            assertFalse(response.isSuccess()); // The job does not exist in Zeebe
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        createComponent();
+
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:throwError")
+                        .to("zeebe://throwError")
+                        .to("mock:throwError");
+
+                from("direct:throwError_JSON")
+                        .to("zeebe://throwError?formatJSON=true")
+                        .to("mock:throwError_JSON");
+            }
+        };
+    }
+
+    protected void createComponent() throws Exception {
+        component = new ZeebeComponent();
+
+        component.setGatewayHost(ZeebeConstants.DEFAULT_GATEWAY_HOST);
+        component.setGatewayPort(ZeebeConstants.DEFAULT_GATEWAY_PORT);
+
+        context().addComponent("zeebe", component);
+    }
+}