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


##########
components/camel-elasticsearch/src/test/java/org/apache/camel/component/es/converter/ElasticsearchActionRequestConverterTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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 co.elastic.clients.elasticsearch.core.UpdateRequest;
+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());
+    }
+
+    @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);
+
+        // no CamelIndexId header -> the caller's id must be preserved, not 
overwritten with null
+        assertEquals("original", result.build().id());
+    }
+}

Review Comment:
   **Missing test: `UpdateRequest.Builder` with header present.** The test 
suite covers `IndexRequest.Builder` symmetrically (no-header + with-header) and 
`UpdateRequest.Builder` without header — but not `UpdateRequest.Builder` with 
header. The fix in `toUpdateRequestBuilder` now does `if (id != null) 
builder.id(id)`, which means the override branch is untested. Add:
   
   ```java
   @Test
   void preBuiltUpdateBuilderHeaderOverridesId() throws Exception {
       Exchange exchange = new DefaultExchange(context);
       exchange.getIn().setHeader(ElasticsearchConstants.PARAM_INDEX_ID, 
"fromHeader");
       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("fromHeader", result.build().id());
   }
   ```



##########
components/camel-opensearch/src/test/java/org/apache/camel/component/opensearch/converter/OpensearchActionRequestConverterTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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 org.opensearch.client.opensearch.core.UpdateRequest;
+
+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());
+    }
+
+    @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
+                = 
OpensearchActionRequestConverter.toUpdateRequestBuilder(preBuilt, exchange);
+
+        // no CamelOpensearchIndexId header -> the caller's id must be 
preserved, not overwritten with null
+        assertEquals("original", result.build().id());
+    }
+}

Review Comment:
   **Same gap as the Elasticsearch test:** `UpdateRequest.Builder` with header 
present is not tested. Add the symmetric case (using 
`OpensearchConstants.PARAM_INDEX_ID` and 
`OpensearchActionRequestConverter.toUpdateRequestBuilder`).



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