This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new ef9d9c19679 Camel 19756 throw error operation does not set processor 3.21.x (#11144) ef9d9c19679 is described below commit ef9d9c19679bd60379aec084618cc8f11ffe02b8 Author: LoRez <karstenreu...@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 d6475b054ec..a20e36fd185 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 @@ -96,6 +96,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 495db67008d..8e335cc9980 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 @@ -26,7 +26,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 dbe15835b2e..8ade870a927 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 @@ -26,7 +26,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 14b50293bc7..7be20c154d5 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 @@ -31,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ @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); + } +}