gnodet-bot commented on code in PR #26590:
URL: https://github.com/apache/camel/pull/26590#discussion_r4045887362


##########
components/camel-opensearch/src/test/java/org/apache/camel/component/opensearch/converter/OpensearchActionRequestConverterTest.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.opensearch.converter;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.opensearch.OpensearchConstants;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.opensearch.client.opensearch.core.IndexRequest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class OpensearchActionRequestConverterTest {
+
+    private CamelContext context;
+
+    @BeforeEach
+    void setUp() {
+        context = new DefaultCamelContext();
+    }
+
+    @AfterEach
+    void tearDown() {
+        context.stop();
+    }
+
+    private IndexRequest.Builder<Object> preBuiltIndexBuilder() {
+        return new 
IndexRequest.Builder<>().index("idx").id("original").document(Map.of("k", "v"));
+    }
+
+    @Test
+    void preBuiltIndexBuilderKeepsItsIdWhenHeaderAbsent() throws Exception {
+        Exchange exchange = new DefaultExchange(context);
+
+        IndexRequest.Builder<?> result
+                = 
OpensearchActionRequestConverter.toIndexRequestBuilder(preBuiltIndexBuilder(), 
exchange);
+
+        // no CamelOpensearchIndexId header -> the caller's id must be 
preserved, not overwritten with null
+        assertEquals("original", result.build().id());
+    }
+
+    @Test
+    void preBuiltIndexBuilderHeaderOverridesId() throws Exception {
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setHeader(OpensearchConstants.PARAM_INDEX_ID, 
"fromHeader");
+
+        IndexRequest.Builder<?> result
+                = 
OpensearchActionRequestConverter.toIndexRequestBuilder(preBuiltIndexBuilder(), 
exchange);
+
+        assertEquals("fromHeader", result.build().id());
+    }
+}

Review Comment:
   ⚠️ **Missing test: `UpdateRequest.Builder` id-preservation.**
   
   Same gap as the Elasticsearch component — `toUpdateRequestBuilder()` with a 
pre-built builder is untested. The fix is present but can silently regress. 
Please add the symmetric test:
   
   ```java
   @Test
   void preBuiltUpdateBuilderKeepsItsIdWhenHeaderAbsent() throws Exception {
       Exchange exchange = new DefaultExchange(context);
       // Use the OpenSearch UpdateRequest builder with a pre-set id
       var preBuilt = new 
org.opensearch.client.opensearch.core.UpdateRequest.Builder<Object, Object>()
           .index("idx").id("original");
   
       UpdateRequest.Builder<?, ?> result =
           OpensearchActionRequestConverter.toUpdateRequestBuilder(preBuilt, 
exchange);
   
       assertEquals("original", result.build().id());
   }
   ```



##########
components/camel-elasticsearch/src/test/java/org/apache/camel/component/es/converter/ElasticsearchActionRequestConverterTest.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.es.converter;
+
+import java.util.Map;
+
+import co.elastic.clients.elasticsearch.core.IndexRequest;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.es.ElasticsearchConstants;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ElasticsearchActionRequestConverterTest {
+
+    private CamelContext context;
+
+    @BeforeEach
+    void setUp() {
+        context = new DefaultCamelContext();
+    }
+
+    @AfterEach
+    void tearDown() {
+        context.stop();
+    }
+
+    private IndexRequest.Builder<Object> preBuiltIndexBuilder() {
+        return new 
IndexRequest.Builder<>().index("idx").id("original").document(Map.of("k", "v"));
+    }
+
+    @Test
+    void preBuiltIndexBuilderKeepsItsIdWhenHeaderAbsent() throws Exception {
+        Exchange exchange = new DefaultExchange(context);
+
+        IndexRequest.Builder<?> result
+                = 
ElasticsearchActionRequestConverter.toIndexRequestBuilder(preBuiltIndexBuilder(),
 exchange);
+
+        // no CamelIndexId header -> the caller's id must be preserved, not 
overwritten with null
+        assertEquals("original", result.build().id());
+    }
+
+    @Test
+    void preBuiltIndexBuilderHeaderOverridesId() throws Exception {
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setHeader(ElasticsearchConstants.PARAM_INDEX_ID, 
"fromHeader");
+
+        IndexRequest.Builder<?> result
+                = 
ElasticsearchActionRequestConverter.toIndexRequestBuilder(preBuiltIndexBuilder(),
 exchange);
+
+        assertEquals("fromHeader", result.build().id());
+    }
+}

Review Comment:
   ⚠️ **Missing test: `UpdateRequest.Builder` id-preservation.**
   
   `toUpdateRequestBuilder()` received the same fix as 
`toIndexRequestBuilder()` — if `CamelIndexId` header is absent, a pre-built 
builder's id should not be clobbered. That path is untested. Please add:
   
   ```java
   @Test
   void preBuiltUpdateBuilderKeepsItsIdWhenHeaderAbsent() throws Exception {
       Exchange exchange = new DefaultExchange(context);
       UpdateRequest.Builder<Object, Object> preBuilt =
           new 
UpdateRequest.Builder<>().index("idx").id("original").doc(Map.of("k", "v"));
   
       UpdateRequest.Builder<?, ?> result =
           ElasticsearchActionRequestConverter.toUpdateRequestBuilder(preBuilt, 
exchange);
   
       assertEquals("original", result.build().id());
   }
   ```



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