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


##########
components/camel-test/camel-test-citrus/src/main/java/org/apache/camel/component/citrus/CitrusEndpoint.java:
##########
@@ -0,0 +1,236 @@
+/*
+ * 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.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.Category;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.mock.MockEndpoint;
+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.citrusframework.CitrusContext;
+import org.citrusframework.message.MessagePayloadBuilder;
+import org.citrusframework.validation.context.ValidationContext;
+
+@UriEndpoint(firstVersion = "4.24.0", scheme = "citrus", title = "Citrus", 
syntax = "citrus:operation/name",
+             producerOnly = true, remote = false, category = { 
Category.TESTING })
+public class CitrusEndpoint extends MockEndpoint {
+
+    @UriPath(description = "The operation to perform. 'validate' validates 
exchanges without modifying them."
+                           + " 'receive' validates exchanges and returns a 
simulated response.",
+             enums = "validate,receive")
+    @Metadata(required = true)
+    private String operation;
+
+    @UriParam(description = "The message type for validation. Determines which 
Citrus validation module is used."
+                            + " Supported values: json, xml, yaml, plaintext.")
+    private String messageType;

Review Comment:
   Fixed in cf3bc8f. Added @UriPath override for name with a Citrus-specific 
description. The generated citrus.json now shows the correct description 
instead of MockEndpoint's.



##########
components/camel-test/camel-test-citrus/src/main/java/org/apache/camel/component/citrus/CitrusEndpoint.java:
##########
@@ -0,0 +1,236 @@
+/*
+ * 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.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.Category;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.mock.MockEndpoint;
+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.citrusframework.CitrusContext;
+import org.citrusframework.message.MessagePayloadBuilder;
+import org.citrusframework.validation.context.ValidationContext;
+
+@UriEndpoint(firstVersion = "4.24.0", scheme = "citrus", title = "Citrus", 
syntax = "citrus:operation/name",
+             producerOnly = true, remote = false, category = { 
Category.TESTING })
+public class CitrusEndpoint extends MockEndpoint {
+
+    @UriPath(description = "The operation to perform. 'validate' validates 
exchanges without modifying them."
+                           + " 'receive' validates exchanges and returns a 
simulated response.",
+             enums = "validate,receive")
+    @Metadata(required = true)
+    private String operation;
+
+    @UriParam(description = "The message type for validation. Determines which 
Citrus validation module is used."
+                            + " Supported values: json, xml, yaml, plaintext.")
+    private String messageType;
+
+    private volatile CitrusContext citrusContext;
+    private final AtomicInteger nextSpecIndex = new AtomicInteger(0);
+
+    public CitrusEndpoint(String endpointUri, CitrusComponent component) {
+        super(endpointUri, component);
+    }
+
+    // --- Lifecycle ---
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        citrusContext = CitrusContext.create();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (citrusContext != null) {
+            citrusContext.close();
+            citrusContext = null;
+        }
+        super.doStop();
+    }
+
+    // --- Fluent validation specification API ---
+
+    public MessageValidationSpec validateAll() {
+        MessageValidationSpec messageValidationSpec = new 
MessageValidationSpec();
+        whenAnyExchangeReceived(createProcessor(messageValidationSpec));
+        return messageValidationSpec;
+    }
+
+    public MessageValidationSpec validate() {
+        return validate(nextSpecIndex.incrementAndGet());
+    }
+
+    public MessageValidationSpec validate(int index) {
+        MessageValidationSpec messageValidationSpec = new 
MessageValidationSpec();
+        whenExchangeReceived(index, createProcessor(messageValidationSpec));
+        return messageValidationSpec;
+    }
+
+    private CitrusValidationProcessor createProcessor(MessageValidationSpec 
validationSpec) {
+        return new CitrusValidationProcessor(citrusContext, messageType, 
validationSpec);

Review Comment:
   Fixed in cf3bc8f. The processor now takes a Supplier<TestContext> instead of 
a CitrusContext reference. The supplier is resolved lazily at process() time, 
so specs configured before doStart() work correctly.



##########
components/camel-test/camel-test-citrus/src/main/java/org/apache/camel/component/citrus/CitrusEndpoint.java:
##########
@@ -0,0 +1,236 @@
+/*
+ * 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.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.Category;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.mock.MockEndpoint;
+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.citrusframework.CitrusContext;
+import org.citrusframework.message.MessagePayloadBuilder;
+import org.citrusframework.validation.context.ValidationContext;
+
+@UriEndpoint(firstVersion = "4.24.0", scheme = "citrus", title = "Citrus", 
syntax = "citrus:operation/name",
+             producerOnly = true, remote = false, category = { 
Category.TESTING })
+public class CitrusEndpoint extends MockEndpoint {
+
+    @UriPath(description = "The operation to perform. 'validate' validates 
exchanges without modifying them."
+                           + " 'receive' validates exchanges and returns a 
simulated response.",
+             enums = "validate,receive")
+    @Metadata(required = true)
+    private String operation;
+
+    @UriParam(description = "The message type for validation. Determines which 
Citrus validation module is used."
+                            + " Supported values: json, xml, yaml, plaintext.")
+    private String messageType;
+
+    private volatile CitrusContext citrusContext;
+    private final AtomicInteger nextSpecIndex = new AtomicInteger(0);
+
+    public CitrusEndpoint(String endpointUri, CitrusComponent component) {
+        super(endpointUri, component);
+    }
+
+    // --- Lifecycle ---
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        citrusContext = CitrusContext.create();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (citrusContext != null) {
+            citrusContext.close();
+            citrusContext = null;
+        }
+        super.doStop();
+    }
+
+    // --- Fluent validation specification API ---
+
+    public MessageValidationSpec validateAll() {
+        MessageValidationSpec messageValidationSpec = new 
MessageValidationSpec();
+        whenAnyExchangeReceived(createProcessor(messageValidationSpec));
+        return messageValidationSpec;
+    }
+
+    public MessageValidationSpec validate() {
+        return validate(nextSpecIndex.incrementAndGet());
+    }
+
+    public MessageValidationSpec validate(int index) {
+        MessageValidationSpec messageValidationSpec = new 
MessageValidationSpec();
+        whenExchangeReceived(index, createProcessor(messageValidationSpec));

Review Comment:
   Fixed in cf3bc8f. Added applyImpliedMinimumCount(index) to both 
validate(int) and receive(int). When no explicit expectedMessageCount is set, 
the highest indexed spec implies a minimum count.



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