This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new a5fa0ce1b6e6 CAMEL-27184: camel-azure-cosmosdb - the producer uses the 
createDatabaseIfNotExists and createContainerIfNotExists options (#30548)
a5fa0ce1b6e6 is described below

commit a5fa0ce1b6e6daef0e2ecf0e0291ef60f1cfc58b
Author: DAKSHIN <[email protected]>
AuthorDate: Sat Nov 21 17:15:38 2026 +0530

    CAMEL-27184: camel-azure-cosmosdb - the producer uses the 
createDatabaseIfNotExists and createContainerIfNotExists options (#30548)
    
    The createDatabaseIfNotExists and createContainerIfNotExists endpoint 
options were ignored by the producer when the
    matching exchange headers were not set: CosmosDbConfigurationOptionsProxy 
read the headers as boolean.class, so a
    missing header became false instead of null and the fallback to the 
endpoint configuration never applied.
    
    The headers are now read as Boolean.class, so a missing header falls back 
to the endpoint option, and an explicit
    header still takes precedence. Regression test in CosmosDbProducerIT.
    
    Closes #30548
---
 .../CosmosDbConfigurationOptionsProxy.java         |  4 +-
 .../cosmosdb/integration/CosmosDbProducerIT.java   | 45 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfigurationOptionsProxy.java
 
b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfigurationOptionsProxy.java
index d188d2309e63..19f7072f1dba 100644
--- 
a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfigurationOptionsProxy.java
+++ 
b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfigurationOptionsProxy.java
@@ -80,12 +80,12 @@ public class CosmosDbConfigurationOptionsProxy {
 
     public boolean isCreateDatabaseIfNotExist(final Exchange exchange) {
         return getOption(exchange, 
CosmosDbConstants.CREATE_DATABASE_IF_NOT_EXIST, 
configuration::isCreateDatabaseIfNotExists,
-                boolean.class);
+                Boolean.class);
     }
 
     public boolean isCreateContainerIfNotExist(final Exchange exchange) {
         return getOption(exchange, 
CosmosDbConstants.CREATE_CONTAINER_IF_NOT_EXIST, 
configuration::isCreateContainerIfNotExists,
-                boolean.class);
+                Boolean.class);
     }
 
     public CosmosDbOperationsDefinition getOperation(final Exchange exchange) {
diff --git 
a/components/camel-azure/camel-azure-cosmosdb/src/test/java/org/apache/camel/component/azure/cosmosdb/integration/CosmosDbProducerIT.java
 
b/components/camel-azure/camel-azure-cosmosdb/src/test/java/org/apache/camel/component/azure/cosmosdb/integration/CosmosDbProducerIT.java
index b7d46b599d35..4f0927eb5aa6 100644
--- 
a/components/camel-azure/camel-azure-cosmosdb/src/test/java/org/apache/camel/component/azure/cosmosdb/integration/CosmosDbProducerIT.java
+++ 
b/components/camel-azure/camel-azure-cosmosdb/src/test/java/org/apache/camel/component/azure/cosmosdb/integration/CosmosDbProducerIT.java
@@ -366,6 +366,46 @@ public class CosmosDbProducerIT extends 
BaseCamelCosmosDbTestSupport {
                 .readAllItems(new PartitionKey("test-1"), 
Object.class).collectList().block().size());
     }
 
+    @Test
+    void testCreateItemWithCreateIfNotExistsEndpointOptions() throws 
InterruptedException {
+        final String databaseName = 
RandomStringUtils.secure().nextAlphabetic(10).toLowerCase();
+        final String containerName = 
RandomStringUtils.secure().nextAlphabetic(10).toLowerCase();
+
+        final Map<String, Object> item = new HashMap<>();
+        item.put("id", "test-id-1");
+        item.put("partition", "test-1");
+        item.put("name", "Test item");
+
+        result.expectedMessageCount(1);
+
+        template.send("direct:createItemWithEndpointOptions", exchange -> {
+            exchange.getIn().setHeader(CosmosDbConstants.DATABASE_NAME, 
databaseName);
+            exchange.getIn().setHeader(CosmosDbConstants.CONTAINER_NAME, 
containerName);
+            exchange.getIn().setHeader(CosmosDbConstants.ITEM_PARTITION_KEY, 
"test-1");
+            exchange.getIn().setBody(item);
+        });
+
+        result.assertIsSatisfied(1000);
+
+        final Message response = result.getExchanges().get(0).getMessage();
+
+        assertTrue(response.getHeader(CosmosDbConstants.STATUS_CODE, 
Integer.class) < 300);
+
+        // Verify that the database and container were created.
+        assertNotNull(client.getDatabase(databaseName).read().block());
+        
assertNotNull(client.getDatabase(databaseName).getContainer(containerName).read().block());
+
+        // Verify that the item was successfully created.
+        final List<?> items = client.getDatabase(databaseName)
+                .getContainer(containerName)
+                .readAllItems(new PartitionKey("test-1"), Object.class)
+                .collectList()
+                .block();
+
+        assertNotNull(items);
+        assertEquals(1, items.size());
+    }
+
     @Test
     void testQueryItems() {
         final String containerName = 
RandomStringUtils.secure().nextAlphabetic(10).toLowerCase();
@@ -444,6 +484,11 @@ public class CosmosDbProducerIT extends 
BaseCamelCosmosDbTestSupport {
                 
from("direct:replaceItem").to("azure-cosmosdb://?operation=replaceItem").to(resultName);
                 
from("direct:deleteItem").to("azure-cosmosdb://?operation=deleteItem").to(resultName);
                 
from("direct:queryItems").to("azure-cosmosdb://?operation=queryItems").to(resultName);
+                
from("direct:createItemWithEndpointOptions").to("azure-cosmosdb://?operation=createItem"
+                                                                + 
"&createDatabaseIfNotExists=true"
+                                                                + 
"&createContainerIfNotExists=true"
+                                                                + 
"&containerPartitionKeyPath=/partition")
+                        .to(resultName);
             }
         };
     }

Reply via email to