christophd commented on code in PR #27792:
URL: https://github.com/apache/camel/pull/27792#discussion_r4279755740


##########
components/camel-test/camel-test-citrus/src/main/java/org/apache/camel/component/citrus/CitrusProducer.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * 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.citrus;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.citrus.CitrusEndpoint.MessageResponseSpec;
+import org.apache.camel.component.citrus.CitrusEndpoint.MessageValidationSpec;
+import org.apache.camel.support.DefaultProducer;
+import org.citrusframework.CitrusContext;
+import org.citrusframework.context.TestContext;
+import org.citrusframework.message.DefaultMessage;
+import org.citrusframework.message.MessagePayloadBuilder;
+import org.citrusframework.message.MessagePayloadUtils;
+import org.citrusframework.message.MessageType;
+import org.citrusframework.validation.MessageValidator;
+import org.citrusframework.validation.MessageValidatorRegistry;
+import org.citrusframework.validation.context.DefaultMessageValidationContext;
+import org.citrusframework.validation.context.HeaderValidationContext;
+import org.citrusframework.validation.context.ValidationContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CitrusProducer extends DefaultProducer {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CitrusProducer.class);
+
+    private volatile CitrusContext citrusContext;
+
+    public CitrusProducer(CitrusEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    @Override
+    public CitrusEndpoint getEndpoint() {
+        return (CitrusEndpoint) super.getEndpoint();
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        citrusContext = CitrusContext.create();
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        CitrusEndpoint endpoint = getEndpoint();
+
+        try {
+            int index = endpoint.nextExchangeIndex();
+            MessageValidationSpec spec = endpoint.resolveValidationSpec(index);
+            TestContext testContext = citrusContext.createTestContext();
+            propagateExchangeProperties(exchange, testContext);
+
+            if (spec != null) {
+                DefaultMessage receivedMessage = 
buildReceivedMessage(exchange);
+                DefaultMessage controlMessage = buildControlMessage(spec, 
testContext);
+
+                String messageType = resolveMessageType(endpoint, spec);
+                controlMessage.setType(messageType);
+
+                List<ValidationContext> validationContexts = 
buildValidationContexts(spec);
+
+                performValidation(receivedMessage, controlMessage, 
testContext, validationContexts, messageType);
+            }
+
+            if ("receive".equals(endpoint.getOperation())) {
+                MessageResponseSpec responseSpec = 
endpoint.resolveResponseSpec(index);
+                if (responseSpec != null) {
+                    applyResponse(exchange, responseSpec, testContext);
+                }
+            }
+        } catch (Exception e) {
+            endpoint.addFailure(e);
+            throw e;

Review Comment:
   _Claude Code on behalf of Christoph Deppisch_
   
   Addressed — the architecture change resolves the concerns:
   
   - **Validate mode**: the processor just throws on failure. `tryProcessing()` 
catches it and sets `exchange.setException(e)`. Our `performAssertions()` 
override then captures the exception into `getFailures()` and clears 
`exchange.setException(null)` so it does not interfere with route error 
handling. Failures are reported via `assertIsSatisfied()`.
   - **Receive mode**: same flow, but the exception is left on the exchange so 
the caller sees it (simulating a service error).
   
   Since the processor no longer catches/rethrows itself, redelivery applies to 
the whole `tryProcessing()` call naturally through MockEndpoint's existing 
mechanism.



##########
components/camel-test/camel-test-citrus/src/main/java/org/apache/camel/component/citrus/CitrusProducer.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * 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.citrus;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.citrus.CitrusEndpoint.MessageResponseSpec;
+import org.apache.camel.component.citrus.CitrusEndpoint.MessageValidationSpec;
+import org.apache.camel.support.DefaultProducer;
+import org.citrusframework.CitrusContext;
+import org.citrusframework.context.TestContext;
+import org.citrusframework.message.DefaultMessage;
+import org.citrusframework.message.MessagePayloadBuilder;
+import org.citrusframework.message.MessagePayloadUtils;
+import org.citrusframework.message.MessageType;
+import org.citrusframework.validation.MessageValidator;
+import org.citrusframework.validation.MessageValidatorRegistry;
+import org.citrusframework.validation.context.DefaultMessageValidationContext;
+import org.citrusframework.validation.context.HeaderValidationContext;
+import org.citrusframework.validation.context.ValidationContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CitrusProducer extends DefaultProducer {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CitrusProducer.class);
+
+    private volatile CitrusContext citrusContext;
+
+    public CitrusProducer(CitrusEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    @Override
+    public CitrusEndpoint getEndpoint() {
+        return (CitrusEndpoint) super.getEndpoint();
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        citrusContext = CitrusContext.create();
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        CitrusEndpoint endpoint = getEndpoint();
+
+        try {
+            int index = endpoint.nextExchangeIndex();
+            MessageValidationSpec spec = endpoint.resolveValidationSpec(index);
+            TestContext testContext = citrusContext.createTestContext();
+            propagateExchangeProperties(exchange, testContext);
+
+            if (spec != null) {
+                DefaultMessage receivedMessage = 
buildReceivedMessage(exchange);
+                DefaultMessage controlMessage = buildControlMessage(spec, 
testContext);
+
+                String messageType = resolveMessageType(endpoint, spec);
+                controlMessage.setType(messageType);
+
+                List<ValidationContext> validationContexts = 
buildValidationContexts(spec);
+
+                performValidation(receivedMessage, controlMessage, 
testContext, validationContexts, messageType);
+            }
+
+            if ("receive".equals(endpoint.getOperation())) {
+                MessageResponseSpec responseSpec = 
endpoint.resolveResponseSpec(index);
+                if (responseSpec != null) {
+                    applyResponse(exchange, responseSpec, testContext);
+                }
+            }
+        } catch (Exception e) {
+            endpoint.addFailure(e);
+            throw e;
+        } finally {
+            endpoint.onExchangeReceived(exchange);
+        }
+    }
+
+    private void propagateExchangeProperties(Exchange exchange, TestContext 
testContext) {

Review Comment:
   _Claude Code on behalf of Christoph Deppisch_
   
   Addressed — both exchange properties and Camel 4 exchange variables 
(`exchange.getVariables()`) are now propagated to the Citrus `TestContext`. 
Extracted variables are also written back: after validation, any new variables 
in the `TestContext` that did not originate from the exchange are set as 
exchange variables via `exchange.setVariable()`, making them available for 
subsequent route steps.



-- 
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]

Reply via email to