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


##########
components/camel-test/camel-test-citrus/src/main/java/org/apache/camel/component/citrus/CitrusEndpoint.java:
##########
@@ -0,0 +1,405 @@
+/*
+ * 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 java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.Category;
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.DefaultEndpoint;
+import org.citrusframework.exceptions.ValidationException;
+import org.citrusframework.message.MessagePayloadBuilder;
+import org.citrusframework.validation.context.ValidationContext;
+
+@UriEndpoint(firstVersion = "4.23.0", scheme = "citrus", title = "Citrus", 
syntax = "citrus:operation/name",
+             producerOnly = true, remote = false, category = { 
Category.TESTING })
+public class CitrusEndpoint extends DefaultEndpoint {

Review Comment:
   Thanks @christophd, that is fine as a follow-up if it lands before 4.24.0. 
Since `validate` no longer throws (see the thread on `CitrusProducer` line 
105), a `CamelTestSupport` test that uses 
`MockEndpoint.assertIsSatisfied(context)` now passes with a failed Citrus 
validation, so the context-wide assert matters more than before. Could you open 
a JIRA for it and link it here? I could not find one yet.
   
   _Claude Code on behalf of @davsclaus._



##########
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:
   Fixed in 50328b86: `validate` records failures and `receive` still throws. 
The remaining request, a test with `onException(...).handled(true)` or a 
redelivery policy for `receive`, is tracked in the thread on `CitrusProducer` 
line 105, so I am resolving this one.
   
   _Claude Code on behalf of @davsclaus._



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