You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/01/17 14:39:20 UTC
[camel] branch main updated: CAMEL-17057: Update documentation for MongoDB component. (#6762)
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 02f7d33 CAMEL-17057: Update documentation for MongoDB component. (#6762)
02f7d33 is described below
commit 02f7d3313985b97e9b554ff2a20ceee21c8b1076
Author: klease <38...@users.noreply.github.com>
AuthorDate: Mon Jan 17 15:38:35 2022 +0100
CAMEL-17057: Update documentation for MongoDB component. (#6762)
* CAMEL-17057: Update documentation for MongoDB component.
Update the documentation and add an example showing a connection URL
with only a hosts parameter and no connectionBean.
Add two unit tests showing both ways of specifying the URL.
* Specify dummy as connectionBean
---
.../apache/camel/component/mongodb/mongodb.json | 4 +-
.../src/main/docs/mongodb-component.adoc | 3 +-
.../camel/component/mongodb/MongoDbEndpoint.java | 4 +-
.../mongodb/MongoDbEndpointClientTest.java | 56 ++++++++++++++++++++++
.../mongodb/MongoDbEndpointHostsTest.java | 49 +++++++++++++++++++
5 files changed, 111 insertions(+), 5 deletions(-)
diff --git a/components/camel-mongodb/src/generated/resources/org/apache/camel/component/mongodb/mongodb.json b/components/camel-mongodb/src/generated/resources/org/apache/camel/component/mongodb/mongodb.json
index 6499270..c0a97ed 100644
--- a/components/camel-mongodb/src/generated/resources/org/apache/camel/component/mongodb/mongodb.json
+++ b/components/camel-mongodb/src/generated/resources/org/apache/camel/component/mongodb/mongodb.json
@@ -28,12 +28,12 @@
"autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...]
},
"properties": {
- "connectionBean": { "kind": "path", "displayName": "Connection Bean", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Sets the connection bean reference used to lookup a client for connecting to a database." },
+ "connectionBean": { "kind": "path", "displayName": "Connection Bean", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Sets the connection bean reference used to lookup a client for connecting to a database if no hosts parameter is present." },
"collection": { "kind": "parameter", "displayName": "Collection", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the name of the MongoDB collection to bind to this endpoint" },
"collectionIndex": { "kind": "parameter", "displayName": "Collection Index", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the collection index (JSON FORMAT : { field1 : order1, field2 : order2})" },
"createCollection": { "kind": "parameter", "displayName": "Create Collection", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Create collection during initialisation if it doesn't exist. Default is true." },
"database": { "kind": "parameter", "displayName": "Database", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the name of the MongoDB database to target" },
- "hosts": { "kind": "parameter", "displayName": "Hosts", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Host address of mongodb server in host:port format. It's possible also use more than one address, as comma separated list of hosts: host1:port1,host2:port2. If hosts parameter is specified, provided connectionBean is ignored." },
+ "hosts": { "kind": "parameter", "displayName": "Hosts", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Host address of mongodb server in host:port format. It's possible also use more than one address, as comma separated list of hosts: host1:port1,host2:port2. If the hosts parameter is specified, the provided connectionBean is ignored." },
"mongoConnection": { "kind": "parameter", "displayName": "Mongo Connection", "group": "common", "label": "", "required": false, "type": "object", "javaType": "com.mongodb.client.MongoClient", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the connection bean used as a client for connecting to a database." },
"operation": { "kind": "parameter", "displayName": "Operation", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.mongodb.MongoDbOperation", "enum": [ "findById", "findOneByQuery", "findAll", "findDistinct", "insert", "save", "update", "remove", "bulkWrite", "aggregate", "getDbStats", "getColStats", "count", "command" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the operation this endpoint [...]
"outputType": { "kind": "parameter", "displayName": "Output Type", "group": "common", "label": "common", "required": false, "type": "object", "javaType": "org.apache.camel.component.mongodb.MongoDbOutputType", "enum": [ "DocumentList", "Document", "MongoIterable" ], "deprecated": false, "autowired": false, "secret": false, "description": "Convert the output of the producer to the selected type : DocumentList Document or MongoIterable. DocumentList or MongoIterable applies to findAll [...]
diff --git a/components/camel-mongodb/src/main/docs/mongodb-component.adoc b/components/camel-mongodb/src/main/docs/mongodb-component.adoc
index a364252..5eea949 100644
--- a/components/camel-mongodb/src/main/docs/mongodb-component.adoc
+++ b/components/camel-mongodb/src/main/docs/mongodb-component.adoc
@@ -56,10 +56,11 @@ for this component:
</dependency>
------------------------------------------------------------
-== URI format
+== URI formats
---------------------------------------------------------------------------------------------------------------
mongodb:connectionBean?database=databaseName&collection=collectionName&operation=operationName[&moreOptions...]
+mongodb:dummy?hosts=hostnames&database=databaseName&collection=collectionName&operation=operationName[&moreOptions...]
---------------------------------------------------------------------------------------------------------------
// component-configure options: START
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
index 9d4c9d2..8c92596 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
@@ -66,7 +66,7 @@ public class MongoDbEndpoint extends DefaultEndpoint {
@UriParam(description = "Sets the connection bean used as a client for connecting to a database.")
private MongoClient mongoConnection;
- @UriPath(description = "Sets the connection bean reference used to lookup a client for connecting to a database.")
+ @UriPath(description = "Sets the connection bean reference used to lookup a client for connecting to a database if no hosts parameter is present.")
@Metadata(required = true)
private String connectionBean;
@@ -732,7 +732,7 @@ public class MongoDbEndpoint extends DefaultEndpoint {
/**
* Host address of mongodb server in `[host]:[port]` format. It's possible also use more than one address, as comma
- * separated list of hosts: `[host1]:[port1],[host2]:[port2]`. If hosts parameter is specified, provided
+ * separated list of hosts: `[host1]:[port1],[host2]:[port2]`. If the hosts parameter is specified, the provided
* connectionBean is ignored.
*
* @param hosts
diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbEndpointClientTest.java b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbEndpointClientTest.java
new file mode 100644
index 0000000..abff7ff
--- /dev/null
+++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbEndpointClientTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.mongodb;
+
+import com.mongodb.client.MongoClients;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.Registry;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class MongoDbEndpointClientTest extends CamelTestSupport {
+
+ @Override
+ protected void bindToRegistry(Registry registry) throws Exception {
+ registry.bind("mongoClient", MongoClients.create("mongodb://localhost"));
+ }
+
+ @Test
+ void testMongoDbEndpoint() {
+ MongoDbEndpoint mongoDb
+ = context.getEndpoint("mongodb:mongoClient?database=test&collection=test&operation=findAll",
+ MongoDbEndpoint.class);
+ assertNotNull(mongoDb);
+ assertNotNull(mongoDb.getMongoConnection());
+ assertNotNull(mongoDb.getMongoConnection().getDatabase("test"));
+ assertEquals("test", mongoDb.getCollection());
+ assertEquals("findAll", mongoDb.getOperation().toString());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:dbFromBean").to("mongodb:mongoClient?database=test&collection=test&operation=findAll");
+ }
+ };
+ }
+
+}
diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbEndpointHostsTest.java b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbEndpointHostsTest.java
new file mode 100644
index 0000000..ac07211
--- /dev/null
+++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbEndpointHostsTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.mongodb;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class MongoDbEndpointHostsTest extends CamelTestSupport {
+
+ @Test
+ void testMongoDbEndpoint() {
+ MongoDbEndpoint mongoDb
+ = context.getEndpoint("mongodb:dummy?hosts=localhost&database=test&collection=test&operation=findAll",
+ MongoDbEndpoint.class);
+ assertNotNull(mongoDb);
+ assertNotNull(mongoDb.getMongoConnection());
+ assertNotNull(mongoDb.getMongoConnection().getDatabase("test"));
+ assertEquals("test", mongoDb.getCollection());
+ assertEquals("findAll", mongoDb.getOperation().toString());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:dbFromHost").to("mongodb:dummy?hosts=localhost&database=test&collection=test&operation=findAll");
+ }
+ };
+ }
+
+}