camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [09/13] camel git commit: CAMEL-10554 - Camel Mongodb evolution to driver 3. Fixed CS
Date Sun, 18 Dec 2016 09:07:25 GMT
http://git-wip-us.apache.org/repos/asf/camel/blob/5715fce7/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbConversionsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbConversionsTest.java b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbConversionsTest.java
index abb265c..7b7ca8b 100644
--- a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbConversionsTest.java
+++ b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbConversionsTest.java
@@ -16,9 +16,6 @@
  */
 package org.apache.camel.component.mongodb3;
 
-import static com.mongodb.client.model.Filters.eq;
-import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
-
 import java.io.ByteArrayInputStream;
 import java.util.HashMap;
 import java.util.Map;
@@ -28,85 +25,89 @@ import org.apache.camel.converter.IOConverter;
 import org.bson.Document;
 import org.junit.Test;
 
+import static com.mongodb.client.model.Filters.eq;
+import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
+
 public class MongoDbConversionsTest extends AbstractMongoDbTest {
 
-	@Test
+    @Test
     public void testInsertMap() throws InterruptedException {
         assertEquals(0, testCollection.count());
-        
+
         Map<String, Object> m1 = new HashMap<>();
         Map<String, String> m1Nested = new HashMap<>();
 
         m1Nested.put("nested1", "nestedValue1");
         m1Nested.put("nested2", "nestedValue2");
-        
+
         m1.put("field1", "value1");
         m1.put("field2", "value2");
         m1.put("nestedField", m1Nested);
         m1.put(MONGO_ID, "testInsertMap");
 
-//        Object result = 
-        		template.requestBody("direct:insertMap", m1);
-        		Document b = testCollection.find(eq(MONGO_ID, "testInsertMap")).first();
+        // Object result =
+        template.requestBody("direct:insertMap", m1);
+        Document b = testCollection.find(eq(MONGO_ID, "testInsertMap")).first();
         assertNotNull("No record with 'testInsertMap' _id", b);
 
     }
-    
+
     @Test
     public void testInsertPojo() {
         assertEquals(0, testCollection.count());
-//        Object result = 
-        		template.requestBody("direct:insertPojo", new MyPojoTest());
-        		Document b = testCollection.find(eq(MONGO_ID, "testInsertPojo")).first();
+        // Object result =
+        template.requestBody("direct:insertPojo", new MyPojoTest());
+        Document b = testCollection.find(eq(MONGO_ID, "testInsertPojo")).first();
         assertNotNull("No record with 'testInsertPojo' _id", b);
     }
-    
+
     @Test
     public void testInsertJsonString() {
         assertEquals(0, testCollection.count());
-//        Object result = 
-        		template.requestBody("direct:insertJsonString", "{\"fruits\": [\"apple\", \"banana\", \"papaya\"], \"veggie\": \"broccoli\", \"_id\": \"testInsertJsonString\"}");
-        //assertTrue(result instanceof WriteResult);
+        // Object result =
+        template.requestBody("direct:insertJsonString", "{\"fruits\": [\"apple\", \"banana\", \"papaya\"], \"veggie\": \"broccoli\", \"_id\": \"testInsertJsonString\"}");
+        // assertTrue(result instanceof WriteResult);
         Document b = testCollection.find(eq(MONGO_ID, "testInsertJsonString")).first();
         assertNotNull("No record with 'testInsertJsonString' _id", b);
     }
-    
+
     @Test
     public void testInsertJsonInputStream() throws Exception {
         assertEquals(0, testCollection.count());
-//        Object result = 
-        		template.requestBody("direct:insertJsonString", 
-                        IOConverter.toInputStream("{\"fruits\": [\"apple\", \"banana\"], \"veggie\": \"broccoli\", \"_id\": \"testInsertJsonString\"}\n", null));
-        		Document b = testCollection.find(eq(MONGO_ID, "testInsertJsonString")).first();
+        // Object result =
+        template.requestBody("direct:insertJsonString",
+                             IOConverter.toInputStream("{\"fruits\": [\"apple\", \"banana\"], \"veggie\": \"broccoli\", \"_id\": \"testInsertJsonString\"}\n", null));
+        Document b = testCollection.find(eq(MONGO_ID, "testInsertJsonString")).first();
         assertNotNull("No record with 'testInsertJsonString' _id", b);
     }
-    
+
     @Test
     public void testInsertBsonInputStream() {
         assertEquals(0, testCollection.count());
-        
+
         Document document = new Document(MONGO_ID, "testInsertBsonString");
-        
-//        Object result = 
-        		template.requestBody("direct:insertJsonString", new ByteArrayInputStream(document.toJson().getBytes()));
-        		Document b = testCollection.find(eq(MONGO_ID, "testInsertBsonString")).first();
+
+        // Object result =
+        template.requestBody("direct:insertJsonString", new ByteArrayInputStream(document.toJson().getBytes()));
+        Document b = testCollection.find(eq(MONGO_ID, "testInsertBsonString")).first();
         assertNotNull("No record with 'testInsertBsonString' _id", b);
     }
-    
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                
+
                 from("direct:insertMap").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
                 from("direct:insertPojo").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
                 from("direct:insertJsonString").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
-                from("direct:insertJsonStringWriteResultInString").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert").convertBodyTo(String.class);
+                from("direct:insertJsonStringWriteResultInString").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert")
+                    .convertBodyTo(String.class);
 
             }
         };
     }
-    
+
     @SuppressWarnings("unused")
     private class MyPojoTest {
         public int number = 123;
@@ -116,5 +117,5 @@ public class MongoDbConversionsTest extends AbstractMongoDbTest {
         public String _id = "testInsertPojo";
         // CHECKSTYLE:ON
     }
-    
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5715fce7/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbDynamicityTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbDynamicityTest.java b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbDynamicityTest.java
index b4d5410..e99fe3e 100644
--- a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbDynamicityTest.java
+++ b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbDynamicityTest.java
@@ -16,69 +16,62 @@
  */
 package org.apache.camel.component.mongodb3;
 
-import static com.mongodb.client.model.Filters.eq;
-import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
-
 import java.util.HashMap;
 import java.util.Map;
 import java.util.stream.StreamSupport;
 
+import com.mongodb.client.MongoCollection;
+
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mongodb3.MongoDbConstants;
 import org.bson.Document;
 import org.junit.Test;
 
-import com.mongodb.client.MongoCollection;
+import static com.mongodb.client.model.Filters.eq;
+import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
 
 public class MongoDbDynamicityTest extends AbstractMongoDbTest {
-    
-	@Test
+
+    @Test
     public void testInsertDynamicityDisabled() {
         assertEquals(0, testCollection.count());
         mongo.getDatabase("otherDB").drop();
         db.getCollection("otherCollection").drop();
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
 
         String body = "{\"_id\": \"testInsertDynamicityDisabled\", \"a\" : \"1\"}";
         Map<String, Object> headers = new HashMap<>();
         headers.put(MongoDbConstants.DATABASE, "otherDB");
         headers.put(MongoDbConstants.COLLECTION, "otherCollection");
-//        Object result = 
-        		template.requestBodyAndHeaders("direct:noDynamicity", body, headers);
+        // Object result =
+        template.requestBodyAndHeaders("direct:noDynamicity", body, headers);
 
-        		Document b = testCollection.find(eq(MONGO_ID, "testInsertDynamicityDisabled")).first();
+        Document b = testCollection.find(eq(MONGO_ID, "testInsertDynamicityDisabled")).first();
         assertNotNull("No record with 'testInsertDynamicityDisabled' _id", b);
-        
+
         body = "{\"_id\": \"testInsertDynamicityDisabledExplicitly\", \"a\" : \"1\"}";
-//        result = 
-        		template.requestBodyAndHeaders("direct:noDynamicityExplicit", body, headers);
+        // result =
+        template.requestBodyAndHeaders("direct:noDynamicityExplicit", body, headers);
 
         b = testCollection.find(eq(MONGO_ID, "testInsertDynamicityDisabledExplicitly")).first();
         assertNotNull("No record with 'testInsertDynamicityDisabledExplicitly' _id", b);
-        
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
 
     }
-    
+
     @Test
     public void testInsertDynamicityEnabledDBOnly() {
         assertEquals(0, testCollection.count());
         mongo.getDatabase("otherDB").drop();
         db.getCollection("otherCollection").drop();
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
 
         String body = "{\"_id\": \"testInsertDynamicityEnabledDBOnly\", \"a\" : \"1\"}";
         Map<String, Object> headers = new HashMap<>();
         headers.put(MongoDbConstants.DATABASE, "otherDB");
-//        Object result = 
-        		template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
-        
+        // Object result =
+        template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
+
         MongoCollection<Document> localDynamicCollection = mongo.getDatabase("otherDB").getCollection(testCollection.getNamespace().getCollectionName(), Document.class);
 
         Document b = localDynamicCollection.find(eq(MONGO_ID, "testInsertDynamicityEnabledDBOnly")).first();
@@ -86,28 +79,24 @@ public class MongoDbDynamicityTest extends AbstractMongoDbTest {
 
         b = testCollection.find(eq(MONGO_ID, "testInsertDynamicityEnabledDBOnly")).first();
         assertNull("There is a record with 'testInsertDynamicityEnabledDBOnly' _id in the test collection", b);
-        
-        assertTrue("The otherDB database should exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
-        
+
+        assertTrue("The otherDB database should exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
+
     }
-    
+
     @Test
     public void testInsertDynamicityEnabledCollectionOnly() {
         assertEquals(0, testCollection.count());
         mongo.getDatabase("otherDB").drop();
         db.getCollection("otherCollection").drop();
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
 
         String body = "{\"_id\": \"testInsertDynamicityEnabledCollectionOnly\", \"a\" : \"1\"}";
         Map<String, Object> headers = new HashMap<>();
         headers.put(MongoDbConstants.COLLECTION, "otherCollection");
-//        Object result = 
-        		template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
-        
+        // Object result =
+        template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
+
         MongoCollection<Document> loaclDynamicCollection = db.getCollection("otherCollection", Document.class);
 
         Document b = loaclDynamicCollection.find(eq(MONGO_ID, "testInsertDynamicityEnabledCollectionOnly")).first();
@@ -115,28 +104,24 @@ public class MongoDbDynamicityTest extends AbstractMongoDbTest {
 
         b = testCollection.find(eq(MONGO_ID, "testInsertDynamicityEnabledDBOnly")).first();
         assertNull("There is a record with 'testInsertDynamicityEnabledCollectionOnly' _id in the test collection", b);
-        
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
     }
-    
+
     @Test
     public void testInsertDynamicityEnabledDBAndCollection() {
         assertEquals(0, testCollection.count());
         mongo.getDatabase("otherDB").drop();
         db.getCollection("otherCollection").drop();
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
 
         String body = "{\"_id\": \"testInsertDynamicityEnabledDBAndCollection\", \"a\" : \"1\"}";
         Map<String, Object> headers = new HashMap<>();
         headers.put(MongoDbConstants.DATABASE, "otherDB");
         headers.put(MongoDbConstants.COLLECTION, "otherCollection");
-//        Object result = 
-        		template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
-        
+        // Object result =
+        template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
+
         MongoCollection<Document> loaclDynamicCollection = mongo.getDatabase("otherDB").getCollection("otherCollection", Document.class);
 
         Document b = loaclDynamicCollection.find(eq(MONGO_ID, "testInsertDynamicityEnabledDBAndCollection")).first();
@@ -144,20 +129,18 @@ public class MongoDbDynamicityTest extends AbstractMongoDbTest {
 
         b = testCollection.find(eq(MONGO_ID, "testInsertDynamicityEnabledDBOnly")).first();
         assertNull("There is a record with 'testInsertDynamicityEnabledDBAndCollection' _id in the test collection", b);
-        
-        assertTrue("The otherDB database should exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+
+        assertTrue("The otherDB database should exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
     }
-    
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                                
-                from("direct:noDynamicity").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");//&writeConcern=SAFE");
-                from("direct:noDynamicityExplicit").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert&dynamicity=false");//&writeConcern=SAFE");
-                from("direct:dynamicityEnabled").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert&dynamicity=true");//&writeConcern=SAFE");
+
+                from("direct:noDynamicity").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
+                from("direct:noDynamicityExplicit").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert&dynamicity=false");
+                from("direct:dynamicityEnabled").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert&dynamicity=true");
 
             }
         };

http://git-wip-us.apache.org/repos/asf/camel/blob/5715fce7/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbExceptionHandlingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbExceptionHandlingTest.java b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbExceptionHandlingTest.java
index 0d3e85e..cc0ff2e 100644
--- a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbExceptionHandlingTest.java
+++ b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbExceptionHandlingTest.java
@@ -17,18 +17,17 @@
 package org.apache.camel.component.mongodb3;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mongodb3.MongoDbConstants;
 import org.bson.Document;
 import org.junit.Test;
 
-public class MongoDbExceptionHandlingTest extends AbstractMongoDbTest {    
-    
+public class MongoDbExceptionHandlingTest extends AbstractMongoDbTest {
+
     @Test
     public void testInduceParseException() throws Exception {
         // Test that the collection has 0 documents in it
         assertEquals(0, testCollection.count());
         pumpDataIntoTestCollection();
-        
+
         // notice missing quote at the end of Einstein
         try {
             template.requestBody("direct:findOneByQuery", "{\"scientist\": \"Einstein}");
@@ -37,37 +36,34 @@ public class MongoDbExceptionHandlingTest extends AbstractMongoDbTest {
             extractAndAssertCamelMongoDbException(e, null);
         }
     }
-    
+
     @Test
     public void testErroneousDynamicOperation() throws Exception {
         // Test that the collection has 0 documents in it
         assertEquals(0, testCollection.count());
         pumpDataIntoTestCollection();
-        
+
         try {
             template.requestBodyAndHeader("direct:findOneByQuery", new Document("scientist", "Einstein").toJson(), MongoDbConstants.OPERATION_HEADER, "dummyOp");
             fail("Should have thrown an exception");
         } catch (Exception e) {
             extractAndAssertCamelMongoDbException(e, "Operation specified on header is not supported. Value: dummyOp");
         }
-       
+
     }
-    
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                
-                from("direct:findAll")
-                    .to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findAll&dynamicity=true")
+
+                from("direct:findAll").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findAll&dynamicity=true")
                     .to("mock:resultFindAll");
-                
-                from("direct:findOneByQuery")
-                    .to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findOneByQuery&dynamicity=true")
+
+                from("direct:findOneByQuery").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findOneByQuery&dynamicity=true")
                     .to("mock:resultFindOneByQuery");
-                
-                from("direct:findById")
-                    .to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findById&dynamicity=true")
+
+                from("direct:findById").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findById&dynamicity=true")
                     .to("mock:resultFindById");
 
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/5715fce7/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbFindOperationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbFindOperationTest.java b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbFindOperationTest.java
index 8884fd4..7e52386 100644
--- a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbFindOperationTest.java
+++ b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbFindOperationTest.java
@@ -16,13 +16,12 @@
  */
 package org.apache.camel.component.mongodb3;
 
-import static com.mongodb.client.model.Filters.eq;
-import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
-
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.mongodb.client.model.Projections;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.commons.lang3.ObjectUtils;
@@ -31,34 +30,36 @@ import org.bson.conversions.Bson;
 import org.bson.types.ObjectId;
 import org.junit.Test;
 
-import com.mongodb.client.model.Projections;
+import static com.mongodb.client.model.Filters.eq;
+import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
 
 public class MongoDbFindOperationTest extends AbstractMongoDbTest {
 
-	@Test
+    @Test
     public void testFindAllNoCriteriaOperation() throws Exception {
         // Test that the collection has 0 documents in it
         assertEquals(0, testCollection.count());
         pumpDataIntoTestCollection();
-        
+
         Object result = template.requestBody("direct:findAll", ObjectUtils.NULL);
         assertTrue("Result is not of type List", result instanceof List);
 
         @SuppressWarnings("unchecked")
-        List<Document> resultList = (List<Document>) result;
+        List<Document> resultList = (List<Document>)result;
 
         assertListSize("Result does not contain all entries in collection", resultList, 1000);
-        
+
         // Ensure that all returned documents contain all fields
         for (Document document : resultList) {
             assertNotNull("Document in returned list should contain all fields", document.get(MONGO_ID));
             assertNotNull("Document in returned list should contain all fields", document.get("scientist"));
             assertNotNull("Document in returned list should contain all fields", document.get("fixedField"));
         }
-        
+
         Exchange resultExchange = getMockEndpoint("mock:resultFindAll").getReceivedExchanges().get(0);
-        //TODO: decide what to do with total count
-        //assertEquals("Result total size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_TOTAL_SIZE));
+        // TODO: decide what to do with total count
+        // assertEquals("Result total size header should equal 1000", 1000,
+        // resultExchange.getIn().getHeader(MongoDbConstants.RESULT_TOTAL_SIZE));
         assertEquals("Result page size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_PAGE_SIZE));
 
     }
@@ -73,11 +74,12 @@ public class MongoDbFindOperationTest extends AbstractMongoDbTest {
         assertTrue("Result is not of type List", result instanceof List);
 
         @SuppressWarnings("unchecked")
-        List<Document> resultList = (List<Document>) result;
+        List<Document> resultList = (List<Document>)result;
 
         assertListSize("Result does not contain correct number of Einstein entries", resultList, 100);
 
-        // Ensure that all returned documents contain all fields, and that they only contain 'Einstein'
+        // Ensure that all returned documents contain all fields, and that they
+        // only contain 'Einstein'
         for (Document document : resultList) {
             assertNotNull("Document in returned list should not contain field _id", document.get(MONGO_ID));
             assertNotNull("Document in returned list does not contain field 'scientist'", document.get("scientist"));
@@ -100,11 +102,12 @@ public class MongoDbFindOperationTest extends AbstractMongoDbTest {
         assertTrue("Result is not of type List", result instanceof List);
 
         @SuppressWarnings("unchecked")
-        List<Document> resultList = (List<Document>) result;
+        List<Document> resultList = (List<Document>)result;
 
         assertListSize("Result does not contain correct number of Einstein entries", resultList, 100);
 
-        // Ensure that all returned documents contain all fields, and that they only contain 'Einstein'
+        // Ensure that all returned documents contain all fields, and that they
+        // only contain 'Einstein'
         for (Document document : resultList) {
             assertNull("Document in returned list should not contain field _id", document.get(MONGO_ID));
             assertNotNull("Document in returned list does not contain field 'scientist'", document.get("scientist"));
@@ -121,35 +124,36 @@ public class MongoDbFindOperationTest extends AbstractMongoDbTest {
         // Test that the collection has 0 documents in it
         assertEquals(0, testCollection.count());
         pumpDataIntoTestCollection();
-        
+
         Bson fieldFilter = Projections.exclude(MONGO_ID, "fixedField");
         Object result = template.requestBodyAndHeader("direct:findAll", ObjectUtils.NULL, MongoDbConstants.FIELDS_PROJECTION, fieldFilter);
         assertTrue("Result is not of type List", result instanceof List);
 
         @SuppressWarnings("unchecked")
-        List<Document> resultList = (List<Document>) result;
+        List<Document> resultList = (List<Document>)result;
 
         assertListSize("Result does not contain all entries in collection", resultList, 1000);
-        
+
         // Ensure that all returned documents contain all fields
         for (Document document : resultList) {
             assertNull("Document in returned list should not contain field _id", document.get(MONGO_ID));
             assertNotNull("Document in returned list does not contain field 'scientist'", document.get("scientist"));
             assertNull("Document in returned list should not contain field fixedField", document.get("fixedField"));
         }
-        
+
         Exchange resultExchange = getMockEndpoint("mock:resultFindAll").getReceivedExchanges().get(0);
-        //assertEquals("Result total size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_TOTAL_SIZE));
+        // assertEquals("Result total size header should equal 1000", 1000,
+        // resultExchange.getIn().getHeader(MongoDbConstants.RESULT_TOTAL_SIZE));
         assertEquals("Result page size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_PAGE_SIZE));
-        
+
     }
-    
+
     @Test
     public void testFindAllIterationOperation() throws Exception {
         // Test that the collection has 0 documents in it
         assertEquals(0, testCollection.count());
         pumpDataIntoTestCollection();
-        
+
         // Repeat ten times, obtain 10 batches of 100 results each time
         int numToSkip = 0;
         final int limit = 100;
@@ -161,34 +165,35 @@ public class MongoDbFindOperationTest extends AbstractMongoDbTest {
             assertTrue("Result is not of type List", result instanceof List);
 
             @SuppressWarnings("unchecked")
-            List<Document> resultList = (List<Document>) result;
+            List<Document> resultList = (List<Document>)result;
 
             assertListSize("Result does not contain 100 elements", resultList, 100);
-            assertEquals("Id of first record is not as expected", numToSkip + 1, Integer.parseInt((String) resultList.get(0).get(MONGO_ID)));
-            
+            assertEquals("Id of first record is not as expected", numToSkip + 1, Integer.parseInt((String)resultList.get(0).get(MONGO_ID)));
+
             // Ensure that all returned documents contain all fields
             for (Document document : resultList) {
                 assertNotNull("Document in returned list should contain all fields", document.get(MONGO_ID));
                 assertNotNull("Document in returned list should contain all fields", document.get("scientist"));
                 assertNotNull("Document in returned list should contain all fields", document.get("fixedField"));
             }
-            
+
             numToSkip = numToSkip + limit;
         }
-        
+
         for (Exchange resultExchange : getMockEndpoint("mock:resultFindAll").getReceivedExchanges()) {
-            //TODO: decide what to do with the total number of elements
-            //assertEquals("Result total size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_TOTAL_SIZE));
+            // TODO: decide what to do with the total number of elements
+            // assertEquals("Result total size header should equal 1000", 1000,
+            // resultExchange.getIn().getHeader(MongoDbConstants.RESULT_TOTAL_SIZE));
             assertEquals("Result page size header should equal 100", 100, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_PAGE_SIZE));
         }
     }
-    
+
     @Test
     public void testFindOneByQuery() throws Exception {
         // Test that the collection has 0 documents in it
         assertEquals(0, testCollection.count());
         pumpDataIntoTestCollection();
-        
+
         Bson query = eq("scientist", "Einstein");
         Document result = template.requestBody("direct:findOneByQuery", query, Document.class);
         assertTrue("Result is not of type Document", result instanceof Document);
@@ -196,27 +201,27 @@ public class MongoDbFindOperationTest extends AbstractMongoDbTest {
         assertNotNull("Document in returned list should contain all fields", result.get(MONGO_ID));
         assertNotNull("Document in returned list should contain all fields", result.get("scientist"));
         assertNotNull("Document in returned list should contain all fields", result.get("fixedField"));
-        
+
     }
-    
+
     @Test
     public void testFindOneById() throws Exception {
         // Test that the collection has 0 documents in it
         assertEquals(0, testCollection.count());
         pumpDataIntoTestCollection();
-        
+
         Document result = template.requestBody("direct:findById", "240", Document.class);
         assertTrue("Result is not of type Document", result instanceof Document);
 
         assertEquals("The ID of the retrieved Document should equal 240", "240", result.get(MONGO_ID));
         assertEquals("The scientist name of the retrieved Document should equal Einstein", "Einstein", result.get("scientist"));
-        
+
         assertNotNull("Document in returned list should contain all fields", result.get(MONGO_ID));
         assertNotNull("Document in returned list should contain all fields", result.get("scientist"));
         assertNotNull("Document in returned list should contain all fields", result.get("fixedField"));
-        
+
     }
-    
+
     @Test
     public void testFindOneByIdWithObjectId() throws Exception {
         // Test that the collection has 0 documents in it
@@ -225,34 +230,31 @@ public class MongoDbFindOperationTest extends AbstractMongoDbTest {
         testCollection.insertOne(insertObject);
         assertTrue("The ID of the inserted document should be ObjectId", insertObject.get(MONGO_ID) instanceof ObjectId);
         ObjectId id = insertObject.getObjectId(MONGO_ID);
-        
+
         Document result = template.requestBody("direct:findById", id, Document.class);
         assertTrue("Result is not of type Document", result instanceof Document);
 
         assertTrue("The ID of the retrieved Document should be ObjectId", result.get(MONGO_ID) instanceof ObjectId);
         assertEquals("The ID of the retrieved Document should equal to the inserted", id, result.get(MONGO_ID));
         assertEquals("The scientist name of the retrieved Document should equal Einstein", "Einstein", result.get("scientist"));
-        
+
         assertNotNull("Document in returned list should contain all fields", result.get(MONGO_ID));
         assertNotNull("Document in returned list should contain all fields", result.get("scientist"));
-        
+
     }
-    
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
 
-                from("direct:findAll")
-                    .to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findAll&dynamicity=true")
+                from("direct:findAll").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findAll&dynamicity=true")
                     .to("mock:resultFindAll");
-                
-                from("direct:findOneByQuery")
-                    .to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findOneByQuery&dynamicity=true")
+
+                from("direct:findOneByQuery").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findOneByQuery&dynamicity=true")
                     .to("mock:resultFindOneByQuery");
-                
-                from("direct:findById")
-                    .to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findById&dynamicity=true")
+
+                from("direct:findById").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findById&dynamicity=true")
                     .to("mock:resultFindById");
 
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/5715fce7/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbHeaderHandlingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbHeaderHandlingTest.java b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbHeaderHandlingTest.java
index 9006cd0..ee98189 100644
--- a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbHeaderHandlingTest.java
+++ b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbHeaderHandlingTest.java
@@ -16,21 +16,20 @@
  */
 package org.apache.camel.component.mongodb3;
 
-import static com.mongodb.client.model.Filters.eq;
-import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
+import com.mongodb.client.result.UpdateResult;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mongodb3.MongoDbConstants;
 import org.bson.Document;
 import org.junit.Test;
 
-import com.mongodb.client.result.UpdateResult;
+import static com.mongodb.client.model.Filters.eq;
+import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
 
 public class MongoDbHeaderHandlingTest extends AbstractMongoDbTest {
 
-	@Test
+    @Test
     public void testInHeadersTransferredToOutOnCount() {
         // a read operation
         assertEquals(0, testCollection.count());
@@ -56,32 +55,31 @@ public class MongoDbHeaderHandlingTest extends AbstractMongoDbTest {
             }
         });
 
-        //TODO: WriteResult isn't return when inserting
-        //assertTrue(result.getOut().getBody() instanceof WriteResult);
+        // TODO: WriteResult isn't return when inserting
+        // assertTrue(result.getOut().getBody() instanceof WriteResult);
         assertEquals("An input header was not returned", "def", result.getOut().getHeader("abc"));
         Document b = testCollection.find(eq(MONGO_ID, "testInsertString")).first();
         assertNotNull("No record with 'testInsertString' _id", b);
     }
-    
+
     @Test
     public void testWriteResultAsHeaderWithWriteOp() {
         // Prepare test
         assertEquals(0, testCollection.count());
-        Object[] req = new Object[] {
-        		new Document(MONGO_ID, "testSave1").append("scientist", "Einstein").toJson(),
-        		new Document(MONGO_ID,"testSave2").append("scientist", "Copernicus").toJson()
-        		};
-//        Object result = 
-        		template.requestBody("direct:insert", req);
-        //assertTrue(result instanceof WriteResult);
+        Object[] req = new Object[] {new Document(MONGO_ID, "testSave1").append("scientist", "Einstein").toJson(),
+                                     new Document(MONGO_ID, "testSave2").append("scientist", "Copernicus").toJson()};
+        // Object result =
+        template.requestBody("direct:insert", req);
+        // assertTrue(result instanceof WriteResult);
         assertEquals("Number of records persisted must be 2", 2, testCollection.count());
-        
+
         // Testing the save logic
         final Document record1 = testCollection.find(eq(MONGO_ID, "testSave1")).first();
         assertEquals("Scientist field of 'testSave1' must equal 'Einstein'", "Einstein", record1.get("scientist"));
         record1.put("scientist", "Darwin");
-        
-        // test that as a payload, we get back exactly our input, but enriched with the CamelMongoDbWriteResult header
+
+        // test that as a payload, we get back exactly our input, but enriched
+        // with the CamelMongoDbWriteResult header
         Exchange resultExch = template.request("direct:save", new Processor() {
             @Override
             public void process(Exchange exchange) throws Exception {
@@ -96,7 +94,7 @@ public class MongoDbHeaderHandlingTest extends AbstractMongoDbTest {
         assertEquals("Scientist field of 'testSave1' must equal 'Darwin' after save operation", "Darwin", record2.get("scientist"));
 
     }
-    
+
     @Test
     public void testWriteResultAsHeaderWithReadOp() {
         Exchange resultExch = template.request("direct:getDbStats", new Processor() {
@@ -110,22 +108,21 @@ public class MongoDbHeaderHandlingTest extends AbstractMongoDbTest {
         assertNull(resultExch.getOut().getHeader(MongoDbConstants.WRITERESULT));
         assertEquals("def", resultExch.getOut().getHeader("abc"));
     }
-    
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                
+
                 // tested routes
                 from("direct:count").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=count&dynamicity=true");
-                from("direct:save").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=save&writeResultAsHeader=true");//&writeConcern=SAFE");
+                from("direct:save").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=save&writeResultAsHeader=true");
                 from("direct:getDbStats").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=getDbStats&writeResultAsHeader=true");
 
                 // supporting routes
-                from("direct:insert").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");//&writeConcern=SAFE");
-                
+                from("direct:insert").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
+
             }
         };
     }
 }
-

http://git-wip-us.apache.org/repos/asf/camel/blob/5715fce7/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbIndexTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbIndexTest.java b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbIndexTest.java
index 350e7db..9ce55b2 100644
--- a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbIndexTest.java
+++ b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbIndexTest.java
@@ -16,10 +16,6 @@
  */
 package org.apache.camel.component.mongodb3;
 
-import static com.mongodb.client.model.Filters.eq;
-import static com.mongodb.client.model.Indexes.*;
-import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -27,28 +23,30 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.StreamSupport;
 
+import com.mongodb.WriteResult;
+import com.mongodb.client.ListIndexesIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mongodb3.MongoDbConstants;
 import org.bson.Document;
 import org.bson.conversions.Bson;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import com.mongodb.WriteResult;
-import com.mongodb.client.ListIndexesIterable;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoCursor;
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Indexes.ascending;
+import static com.mongodb.client.model.Indexes.descending;
+import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
 
 public class MongoDbIndexTest extends AbstractMongoDbTest {
 
-	@Test
+    @Test
     public void testInsertDynamicityEnabledDBAndCollectionAndIndex() {
         assertEquals(0, testCollection.count());
         mongo.getDatabase("otherDB").drop();
         db.getCollection("otherCollection").drop();
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
 
         String body = "{\"_id\": \"testInsertDynamicityEnabledDBAndCollection\", \"a\" : 1, \"b\" : 2}";
         Map<String, Object> headers = new HashMap<>();
@@ -87,9 +85,7 @@ public class MongoDbIndexTest extends AbstractMongoDbTest {
         b = testCollection.find(new Document(MONGO_ID, "testInsertDynamicityEnabledDBOnly")).first();
         assertNull("There is a record with 'testInsertDynamicityEnabledDBAndCollection' _id in the test collection", b);
 
-        assertTrue("The otherDB database should exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertTrue("The otherDB database should exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
     }
 
     @Test
@@ -97,15 +93,13 @@ public class MongoDbIndexTest extends AbstractMongoDbTest {
         assertEquals(0, testCollection.count());
         mongo.getDatabase("otherDB").drop();
         db.getCollection("otherCollection").drop();
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
 
         String body = "{\"_id\": \"testInsertDynamicityEnabledCollectionAndIndex\", \"a\" : 1, \"b\" : 2}";
         Map<String, Object> headers = new HashMap<>();
         headers.put(MongoDbConstants.COLLECTION, "otherCollection");
 
-        List<Bson> objIndex = Arrays.asList(ascending("a"),descending("b"));
+        List<Bson> objIndex = Arrays.asList(ascending("a"), descending("b"));
         headers.put(MongoDbConstants.COLLECTION_INDEX, objIndex);
 
         Object result = template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
@@ -137,9 +131,7 @@ public class MongoDbIndexTest extends AbstractMongoDbTest {
         assertEquals(0, testCollection.count());
         mongo.getDatabase("otherDB").drop();
         db.getCollection("otherCollection").drop();
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
 
         String body = "{\"_id\": \"testInsertDynamicityEnabledCollectionOnlyAndURIIndex\", \"a\" : 1, \"b\" : 2}";
         Map<String, Object> headers = new HashMap<>();
@@ -163,9 +155,7 @@ public class MongoDbIndexTest extends AbstractMongoDbTest {
         b = testCollection.find(eq(MONGO_ID, "testInsertDynamicityEnabledCollectionOnlyAndURIIndex")).first();
         assertNull("There is a record with 'testInsertDynamicityEnabledCollectionOnlyAndURIIndex' _id in the test collection", b);
 
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
     }
 
     @Ignore
@@ -195,21 +185,18 @@ public class MongoDbIndexTest extends AbstractMongoDbTest {
         b = testCollection.find(eq(MONGO_ID, "testInsertAutoCreateCollectionAndURIIndex")).first();
         assertNull("There is a record with 'testInsertAutoCreateCollectionAndURIIndex' _id in the test collection", b);
 
-        assertFalse("The otherDB database should not exist",
-                StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
-                        .anyMatch("otherDB"::equals));
+        assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                from("direct:dynamicityEnabled")
-                        .to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert&dynamicity=true");//&writeConcern=SAFE");
+                from("direct:dynamicityEnabled").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert&dynamicity=true");
                 from("direct:dynamicityEnabledWithIndexUri")
-                        .to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&collectionIndex={\"a\":1}&operation=insert&dynamicity=true");//&writeConcern=SAFE");
+                    .to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&collectionIndex={\"a\":1}&operation=insert&dynamicity=true");
                 from("direct:dynamicityDisabled")
-                        .to("mongodb3:myDb?database={{mongodb.testDb}}&collection=otherCollection&collectionIndex={\"a\":1,\"b\":-1}&operation=insert&dynamicity=false");//&writeConcern=SAFE");
+                    .to("mongodb3:myDb?database={{mongodb.testDb}}&collection=otherCollection&collectionIndex={\"a\":1,\"b\":-1}&operation=insert&dynamicity=false");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/5715fce7/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbOperationsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbOperationsTest.java b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbOperationsTest.java
index 07a8d84..fb7e09d 100644
--- a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbOperationsTest.java
+++ b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbOperationsTest.java
@@ -16,421 +16,382 @@
  */
 package org.apache.camel.component.mongodb3;
 
-import static com.mongodb.client.model.Accumulators.sum;
-import static com.mongodb.client.model.Aggregates.group;
-import static com.mongodb.client.model.Aggregates.match;
-import static com.mongodb.client.model.Filters.eq;
-import static com.mongodb.client.model.Filters.or;
-import static com.mongodb.client.model.Updates.combine;
-import static com.mongodb.client.model.Updates.currentTimestamp;
-import static com.mongodb.client.model.Updates.set;
-import static java.util.Arrays.asList;
-import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
-
 import java.util.Arrays;
 import java.util.Formatter;
 import java.util.HashMap;
 import java.util.List;
 
+import static java.util.Arrays.asList;
+
+import com.mongodb.MongoClient;
+import com.mongodb.client.result.DeleteResult;
+import com.mongodb.client.result.UpdateResult;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mongodb3.MongoDbConstants;
-import org.apache.camel.component.mongodb3.MongoDbOperation;
 import org.bson.Document;
 import org.bson.conversions.Bson;
 import org.bson.types.ObjectId;
 import org.junit.Test;
 
-import com.mongodb.MongoClient;
-import com.mongodb.client.result.DeleteResult;
-import com.mongodb.client.result.UpdateResult;
+import static com.mongodb.client.model.Accumulators.sum;
+import static com.mongodb.client.model.Aggregates.group;
+import static com.mongodb.client.model.Aggregates.match;
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Filters.or;
+import static com.mongodb.client.model.Updates.combine;
+import static com.mongodb.client.model.Updates.currentTimestamp;
+import static com.mongodb.client.model.Updates.set;
+import static org.apache.camel.component.mongodb3.MongoDbConstants.MONGO_ID;
 
 public class MongoDbOperationsTest extends AbstractMongoDbTest {
 
-	@Test
-	public void testCountOperation() throws Exception {
-		// Test that the collection has 0 documents in it
-		assertEquals(0, testCollection.count());
-		Object result = template.requestBody("direct:count", "irrelevantBody");
-		assertTrue("Result is not of type Long", result instanceof Long);
-		assertEquals("Test collection should not contain any records", 0L, result);
-
-		// Insert a record and test that the endpoint now returns 1
-		testCollection.insertOne(Document.parse("{a:60}"));
-		result = template.requestBody("direct:count", "irrelevantBody");
-		assertTrue("Result is not of type Long", result instanceof Long);
-		assertEquals("Test collection should contain 1 record", 1L, result);
-		testCollection.deleteOne(new Document());
-
-		// test dynamicity
-		dynamicCollection.insertOne(Document.parse("{a:60}"));
-		result = template.requestBodyAndHeader("direct:count", "irrelevantBody", MongoDbConstants.COLLECTION,
-				dynamicCollectionName);
-		assertTrue("Result is not of type Long", result instanceof Long);
-		assertEquals("Dynamic collection should contain 1 record", 1L, result);
-
-	}
-
-	@Test
-	public void testInsertString() throws Exception {
-		assertEquals(0, testCollection.count());
-		Object result = template.requestBody("direct:insert",
-				new Document(MONGO_ID, "testInsertString").append("scientist", "Einstein").toJson());
-		assertTrue(result instanceof Document);
-		Document b = testCollection.find(eq(MONGO_ID, "testInsertString")).first();
-		assertNotNull("No record with 'testInsertString' _id", b);
-	}
-
-	@Test
-	public void testStoreOidOnInsert() throws Exception {
-		Document document = new Document();
-		ObjectId oid = template.requestBody("direct:testStoreOidOnInsert", document, ObjectId.class);
-		assertEquals(document.get(MONGO_ID), oid);
-	}
-
-	@Test
-	public void testStoreOidsOnInsert() throws Exception {
-		Document firsDocument = new Document();
-		Document secondDoocument = new Document();
-		List<?> oids = template.requestBody("direct:testStoreOidOnInsert", asList(firsDocument, secondDoocument),
-				List.class);
-		assertTrue(oids.contains(firsDocument.get(MONGO_ID)));
-		assertTrue(oids.contains(secondDoocument.get(MONGO_ID)));
-	}
-
-	@Test
-	public void testSave() throws Exception {
-		// Prepare test
-		assertEquals(0, testCollection.count());
-		Object[] req = new Object[] {
-				new Document(MONGO_ID, "testSave1").append("scientist", "Einstein").toJson(),
-				new Document(MONGO_ID, "testSave2").append("scientist", "Copernicus").toJson() };
-		Object result = template.requestBody("direct:insert", req);
-		assertTrue(result instanceof List);
-		assertEquals("Number of records persisted must be 2", 2, testCollection.count());
-
-		// Testing the save logic
-		Document record1 = testCollection.find(eq(MONGO_ID, "testSave1")).first();
-		assertEquals("Scientist field of 'testSave1' must equal 'Einstein'", "Einstein", record1.get("scientist"));
-		record1.put("scientist", "Darwin");
-
-		result = template.requestBody("direct:save", record1);
-		assertTrue(result instanceof UpdateResult);
-
-		record1 = testCollection.find(eq(MONGO_ID, "testSave1")).first();
-		assertEquals("Scientist field of 'testSave1' must equal 'Darwin' after save operation", "Darwin",
-				record1.get("scientist"));
-
-	}
-
-	@Test
-	public void testSaveWithoutId() {
-		// Prepare test
-		assertEquals(0, testCollection.count());
-		// This document should not be modified
-		Document doc = new Document("scientist", "Copernic");
-		template.requestBody("direct:insert", doc);
-		// save (upsert) a document without Id => insert with new Id
-		doc = new Document("scientist", "Einstein");
-		assertNull(doc.get(MONGO_ID));
-		UpdateResult result = template.requestBody("direct:save", doc, UpdateResult.class);
-		assertNotNull(result.getUpsertedId());
-		// Without Id save perform an insert not an update.
-		assertEquals(0, result.getModifiedCount());
-		// Testing the save logic
-		Document record1 = testCollection.find(eq(MONGO_ID, result.getUpsertedId())).first();
-		assertEquals("Scientist field of '" + result.getUpsertedId() + "' must equal 'Einstein'", "Einstein",
-				record1.get("scientist"));
-	}
-
-	@Test
-	public void testStoreOidOnSaveWithoutId() throws Exception {
-		Document document = new Document();
-		ObjectId oid = template.requestBody("direct:testStoreOidOnSave", document, ObjectId.class);
-		assertNotNull(oid);
-	}
-
-	@Test
-	public void testStoreOidOnSave() throws Exception {
-		Document document = new Document(MONGO_ID, new ObjectId("5847e39e0824d6b54194e197"));
-		ObjectId oid = template.requestBody("direct:testStoreOidOnSave", document, ObjectId.class);
-		assertEquals(document.get(MONGO_ID), oid);
-	}
-
-	@Test
-	public void testUpdate() throws Exception {
-		// Prepare test
-		assertEquals(0, testCollection.count());
-		for (int i = 1; i <= 100; i++) {
-			String body = null;
-			try (Formatter f = new Formatter();) {
-				if (i % 2 == 0) {
-					body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
-				} else {
-					body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i)
-							.toString();
-				}
-				f.close();
-			}
-			template.requestBody("direct:insert", body);
-		}
-		assertEquals(100L, testCollection.count());
-
-		// Testing the update logic
-		Bson extraField = eq("extraField", true);
-		assertEquals("Number of records with 'extraField' flag on must equal 50", 50L,
-				testCollection.count(extraField));
-		assertEquals("Number of records with 'scientist' field = Darwin on must equal 0", 0,
-				testCollection.count(new Document("scientist", "Darwin")));
-
-		Bson updateObj = combine(set("scientist", "Darwin"), currentTimestamp("lastModified"));
-
-		Exchange resultExchange = template.request("direct:update", new Processor() {
-			@Override
-			public void process(Exchange exchange) throws Exception {
-				exchange.getIn().setBody(new Bson[] { extraField, updateObj });
-				exchange.getIn().setHeader(MongoDbConstants.MULTIUPDATE, true);
-			}
-		});
-		Object result = resultExchange.getOut().getBody();
-		assertTrue(result instanceof UpdateResult);
-		assertEquals("Number of records updated header should equal 50", 50L,
-				resultExchange.getOut().getHeader(MongoDbConstants.RECORDS_AFFECTED));
-
-		assertEquals("Number of records with 'scientist' field = Darwin on must equal 50 after update", 50,
-				testCollection.count(new Document("scientist", "Darwin")));
-	}
-
-	@Test
-	public void testUpdateFromString() throws Exception {
-		// Prepare test
-		assertEquals(0, testCollection.count());
-		for (int i = 1; i <= 100; i++) {
-			String body = null;
-			try (Formatter f = new Formatter();) {
-				if (i % 2 == 0) {
-					body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
-				} else {
-					body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i)
-							.toString();
-				}
-				f.close();
-			}
-			template.requestBody("direct:insert", body);
-		}
-		assertEquals(100L, testCollection.count());
-
-		// Testing the update logic
-		Bson extraField = eq("extraField", true);
-		assertEquals("Number of records with 'extraField' flag on must equal 50", 50L,
-				testCollection.count(extraField));
-		assertEquals("Number of records with 'scientist' field = Darwin on must equal 0", 0,
-				testCollection.count(new Document("scientist", "Darwin")));
-
-		Bson updateObj = combine(set("scientist", "Darwin"), currentTimestamp("lastModified"));
-
-		 String updates = "[" +
-		extraField.toBsonDocument(Document.class,  MongoClient.getDefaultCodecRegistry()).toJson() +","+
-		 updateObj.toBsonDocument(Document.class,  MongoClient.getDefaultCodecRegistry()).toJson() +"]";
-		
-		Exchange resultExchange = template.request("direct:update", new Processor() {
-			@Override
-			public void process(Exchange exchange) throws Exception {
-				exchange.getIn().setBody(updates);
-				exchange.getIn().setHeader(MongoDbConstants.MULTIUPDATE, true);
-			}
-		});
-		Object result = resultExchange.getOut().getBody();
-		assertTrue(result instanceof UpdateResult);
-		assertEquals("Number of records updated header should equal 50", 50L,
-				resultExchange.getOut().getHeader(MongoDbConstants.RECORDS_AFFECTED));
-
-		assertEquals("Number of records with 'scientist' field = Darwin on must equal 50 after update", 50,
-				testCollection.count(new Document("scientist", "Darwin")));
-	}
-
-	@Test
-	public void testUpdateUsingFieldsFilterHeader() throws Exception {
-		// Prepare test
-		assertEquals(0, testCollection.count());
-		for (int i = 1; i <= 100; i++) {
-			String body = null;
-			try (Formatter f = new Formatter();) {
-				if (i % 2 == 0) {
-					body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
-				} else {
-					body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i)
-							.toString();
-				}
-				f.close();
-			}
-			template.requestBody("direct:insert", body);
-		}
-		assertEquals(100L, testCollection.count());
-
-		// Testing the update logic
-		Bson extraField = eq("extraField", true);
-		assertEquals("Number of records with 'extraField' flag on must equal 50", 50L,
-				testCollection.count(extraField));
-		assertEquals("Number of records with 'scientist' field = Darwin on must equal 0", 0,
-				testCollection.count(new Document("scientist", "Darwin")));
-
-		Bson updateObj = combine(set("scientist", "Darwin"), currentTimestamp("lastModified"));
-		HashMap<String, Object> headers = new HashMap<>();
-		headers.put(MongoDbConstants.MULTIUPDATE, true);
-		headers.put(MongoDbConstants.CRITERIA, extraField);
-		Object result = template.requestBodyAndHeaders("direct:update", updateObj, headers);
-		assertTrue(result instanceof UpdateResult);
-		assertEquals("Number of records updated header should equal 50", 50L,
-				UpdateResult.class.cast(result).getModifiedCount());
-		assertEquals("Number of records with 'scientist' field = Darwin on must equal 50 after update", 50,
-				testCollection.count(new Document("scientist", "Darwin")));
-	}
-
-	@Test
-	public void testRemove() throws Exception {
-		// Prepare test
-		assertEquals(0, testCollection.count());
-		for (int i = 1; i <= 100; i++) {
-			String body = null;
-			try (Formatter f = new Formatter();) {
-				if (i % 2 == 0) {
-					body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
-				} else {
-					body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i)
-							.toString();
-				}
-				f.close();
-			}
-			template.requestBody("direct:insert", body);
-		}
-		assertEquals(100L, testCollection.count());
-
-		// Testing the update logic
-		Document extraField = new Document("extraField", true);
-		assertEquals("Number of records with 'extraField' flag on must equal 50", 50L,
-				testCollection.count(extraField));
-
-		Exchange resultExchange = template.request("direct:remove", new Processor() {
-			@Override
-			public void process(Exchange exchange) throws Exception {
-				exchange.getIn().setBody(extraField);
-			}
-		});
-		Object result = resultExchange.getOut().getBody();
-		assertTrue(result instanceof DeleteResult);
-		assertEquals("Number of records deleted header should equal 50", 50L,
-				resultExchange.getOut().getHeader(MongoDbConstants.RECORDS_AFFECTED));
-
-		assertEquals("Number of records with 'extraField' flag on must be 0 after remove", 0,
-				testCollection.count(extraField));
-
-	}
-
-	@Test
-	public void testAggregate() throws Exception {
-		// Test that the collection has 0 documents in it
-		assertEquals(0, testCollection.count());
-		pumpDataIntoTestCollection();
-
-		// Repeat ten times, obtain 10 batches of 100 results each time
-		List<Bson> aggregate = Arrays.asList(match(or(eq("scientist", "Darwin"), eq("scientist", "Einstein"))),
-				group("$scientist", sum("count", 1)));
-		Object result = template.requestBody("direct:aggregate", aggregate);
-		assertTrue("Result is not of type List", result instanceof List);
-
-		@SuppressWarnings("unchecked")
-		List<Document> resultList = (List<Document>) result;
-		assertListSize("Result does not contain 2 elements", resultList, 2);
-		// TODO Add more asserts
-	}
-
-	@Test
-	public void testDbStats() throws Exception {
-		assertEquals(0, testCollection.count());
-		Object result = template.requestBody("direct:getDbStats", "irrelevantBody");
-		assertTrue("Result is not of type Document", result instanceof Document);
-		assertTrue("The result should contain keys", Document.class.cast(result).keySet().size() > 0);
-	}
-
-	@Test
-	public void testColStats() throws Exception {
-		assertEquals(0, testCollection.count());
-
-		// Add some records to the collection (and do it via camel-mongodb)
-		for (int i = 1; i <= 100; i++) {
-			String body = null;
-			try (Formatter f = new Formatter();) {
-				body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
-				f.close();
-			}
-			template.requestBody("direct:insert", body);
-		}
-
-		Object result = template.requestBody("direct:getColStats", "irrelevantBody");
-		assertTrue("Result is not of type Document", result instanceof Document);
-		assertTrue("The result should contain keys", Document.class.cast(result).keySet().size() > 0);
-	}
-
-	@Test
-	public void testCommand() throws Exception {
-		// Call hostInfo, command working with every configuration
-		Object result = template.requestBody("direct:command", "{\"hostInfo\":\"1\"}");
-		assertTrue("Result is not of type Document", result instanceof Document);
-		assertTrue("The result should contain keys", Document.class.cast(result).keySet().size() > 0);
-	}
-
-	@Test
-	public void testOperationHeader() throws Exception {
-		// Test that the collection has 0 documents in it
-		assertEquals(0, testCollection.count());
-
-		// check that the count operation was invoked instead of the insert
-		// operation
-		Object result = template.requestBodyAndHeader("direct:insert", "irrelevantBody",
-				MongoDbConstants.OPERATION_HEADER, "count");
-		assertTrue("Result is not of type Long", result instanceof Long);
-		assertEquals("Test collection should not contain any records", 0L, result);
-
-		// check that the count operation was invoked instead of the insert
-		// operation
-		result = template.requestBodyAndHeader("direct:insert", "irrelevantBody", MongoDbConstants.OPERATION_HEADER,
-				MongoDbOperation.count);
-		assertTrue("Result is not of type Long", result instanceof Long);
-		assertEquals("Test collection should not contain any records", 0L, result);
-
-	}
-
-	@Override
-	protected RouteBuilder createRouteBuilder() throws Exception {
-		return new RouteBuilder() {
-			public void configure() {
-
-				from("direct:count").to(
-						"mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=count&dynamicity=true");
-				from("direct:insert").to(
-						"mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
-				from("direct:testStoreOidOnInsert")
-						.to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert")
-						.setBody().header(MongoDbConstants.OID);
-				from("direct:save").to(
-						"mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=save");
-				from("direct:testStoreOidOnSave")
-						.to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=save")
-						.setBody().header(MongoDbConstants.OID);
-				from("direct:update").to(
-						"mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=update");
-				from("direct:remove").to(
-						"mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=remove");
-				from("direct:aggregate").to(
-						"mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=aggregate");
-				from("direct:getDbStats").to("mongodb3:myDb?database={{mongodb.testDb}}&operation=getDbStats");
-				from("direct:getColStats").to(
-						"mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=getColStats");
-				from("direct:command").to("mongodb3:myDb?database={{mongodb.testDb}}&operation=command");
-
-			}
-		};
-	}
+    @Test
+    public void testCountOperation() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        Object result = template.requestBody("direct:count", "irrelevantBody");
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Test collection should not contain any records", 0L, result);
+
+        // Insert a record and test that the endpoint now returns 1
+        testCollection.insertOne(Document.parse("{a:60}"));
+        result = template.requestBody("direct:count", "irrelevantBody");
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Test collection should contain 1 record", 1L, result);
+        testCollection.deleteOne(new Document());
+
+        // test dynamicity
+        dynamicCollection.insertOne(Document.parse("{a:60}"));
+        result = template.requestBodyAndHeader("direct:count", "irrelevantBody", MongoDbConstants.COLLECTION, dynamicCollectionName);
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Dynamic collection should contain 1 record", 1L, result);
+
+    }
+
+    @Test
+    public void testInsertString() throws Exception {
+        assertEquals(0, testCollection.count());
+        Object result = template.requestBody("direct:insert", new Document(MONGO_ID, "testInsertString").append("scientist", "Einstein").toJson());
+        assertTrue(result instanceof Document);
+        Document b = testCollection.find(eq(MONGO_ID, "testInsertString")).first();
+        assertNotNull("No record with 'testInsertString' _id", b);
+    }
+
+    @Test
+    public void testStoreOidOnInsert() throws Exception {
+        Document document = new Document();
+        ObjectId oid = template.requestBody("direct:testStoreOidOnInsert", document, ObjectId.class);
+        assertEquals(document.get(MONGO_ID), oid);
+    }
+
+    @Test
+    public void testStoreOidsOnInsert() throws Exception {
+        Document firsDocument = new Document();
+        Document secondDoocument = new Document();
+        List<?> oids = template.requestBody("direct:testStoreOidOnInsert", asList(firsDocument, secondDoocument), List.class);
+        assertTrue(oids.contains(firsDocument.get(MONGO_ID)));
+        assertTrue(oids.contains(secondDoocument.get(MONGO_ID)));
+    }
+
+    @Test
+    public void testSave() throws Exception {
+        // Prepare test
+        assertEquals(0, testCollection.count());
+        Object[] req = new Object[] {new Document(MONGO_ID, "testSave1").append("scientist", "Einstein").toJson(),
+                                     new Document(MONGO_ID, "testSave2").append("scientist", "Copernicus").toJson()};
+        Object result = template.requestBody("direct:insert", req);
+        assertTrue(result instanceof List);
+        assertEquals("Number of records persisted must be 2", 2, testCollection.count());
+
+        // Testing the save logic
+        Document record1 = testCollection.find(eq(MONGO_ID, "testSave1")).first();
+        assertEquals("Scientist field of 'testSave1' must equal 'Einstein'", "Einstein", record1.get("scientist"));
+        record1.put("scientist", "Darwin");
+
+        result = template.requestBody("direct:save", record1);
+        assertTrue(result instanceof UpdateResult);
+
+        record1 = testCollection.find(eq(MONGO_ID, "testSave1")).first();
+        assertEquals("Scientist field of 'testSave1' must equal 'Darwin' after save operation", "Darwin", record1.get("scientist"));
+
+    }
+
+    @Test
+    public void testSaveWithoutId() {
+        // Prepare test
+        assertEquals(0, testCollection.count());
+        // This document should not be modified
+        Document doc = new Document("scientist", "Copernic");
+        template.requestBody("direct:insert", doc);
+        // save (upsert) a document without Id => insert with new Id
+        doc = new Document("scientist", "Einstein");
+        assertNull(doc.get(MONGO_ID));
+        UpdateResult result = template.requestBody("direct:save", doc, UpdateResult.class);
+        assertNotNull(result.getUpsertedId());
+        // Without Id save perform an insert not an update.
+        assertEquals(0, result.getModifiedCount());
+        // Testing the save logic
+        Document record1 = testCollection.find(eq(MONGO_ID, result.getUpsertedId())).first();
+        assertEquals("Scientist field of '" + result.getUpsertedId() + "' must equal 'Einstein'", "Einstein", record1.get("scientist"));
+    }
+
+    @Test
+    public void testStoreOidOnSaveWithoutId() throws Exception {
+        Document document = new Document();
+        ObjectId oid = template.requestBody("direct:testStoreOidOnSave", document, ObjectId.class);
+        assertNotNull(oid);
+    }
+
+    @Test
+    public void testStoreOidOnSave() throws Exception {
+        Document document = new Document(MONGO_ID, new ObjectId("5847e39e0824d6b54194e197"));
+        ObjectId oid = template.requestBody("direct:testStoreOidOnSave", document, ObjectId.class);
+        assertEquals(document.get(MONGO_ID), oid);
+    }
+
+    @Test
+    public void testUpdate() throws Exception {
+        // Prepare test
+        assertEquals(0, testCollection.count());
+        for (int i = 1; i <= 100; i++) {
+            String body = null;
+            try (Formatter f = new Formatter();) {
+                if (i % 2 == 0) {
+                    body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
+                } else {
+                    body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i).toString();
+                }
+                f.close();
+            }
+            template.requestBody("direct:insert", body);
+        }
+        assertEquals(100L, testCollection.count());
+
+        // Testing the update logic
+        Bson extraField = eq("extraField", true);
+        assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
+        assertEquals("Number of records with 'scientist' field = Darwin on must equal 0", 0, testCollection.count(new Document("scientist", "Darwin")));
+
+        Bson updateObj = combine(set("scientist", "Darwin"), currentTimestamp("lastModified"));
+
+        Exchange resultExchange = template.request("direct:update", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(new Bson[] {extraField, updateObj});
+                exchange.getIn().setHeader(MongoDbConstants.MULTIUPDATE, true);
+            }
+        });
+        Object result = resultExchange.getOut().getBody();
+        assertTrue(result instanceof UpdateResult);
+        assertEquals("Number of records updated header should equal 50", 50L, resultExchange.getOut().getHeader(MongoDbConstants.RECORDS_AFFECTED));
+
+        assertEquals("Number of records with 'scientist' field = Darwin on must equal 50 after update", 50, testCollection.count(new Document("scientist", "Darwin")));
+    }
+
+    @Test
+    public void testUpdateFromString() throws Exception {
+        // Prepare test
+        assertEquals(0, testCollection.count());
+        for (int i = 1; i <= 100; i++) {
+            String body = null;
+            try (Formatter f = new Formatter();) {
+                if (i % 2 == 0) {
+                    body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
+                } else {
+                    body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i).toString();
+                }
+                f.close();
+            }
+            template.requestBody("direct:insert", body);
+        }
+        assertEquals(100L, testCollection.count());
+
+        // Testing the update logic
+        Bson extraField = eq("extraField", true);
+        assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
+        assertEquals("Number of records with 'scientist' field = Darwin on must equal 0", 0, testCollection.count(new Document("scientist", "Darwin")));
+
+        Bson updateObj = combine(set("scientist", "Darwin"), currentTimestamp("lastModified"));
+
+        String updates = "[" + extraField.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()).toJson() + ","
+                         + updateObj.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()).toJson() + "]";
+
+        Exchange resultExchange = template.request("direct:update", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(updates);
+                exchange.getIn().setHeader(MongoDbConstants.MULTIUPDATE, true);
+            }
+        });
+        Object result = resultExchange.getOut().getBody();
+        assertTrue(result instanceof UpdateResult);
+        assertEquals("Number of records updated header should equal 50", 50L, resultExchange.getOut().getHeader(MongoDbConstants.RECORDS_AFFECTED));
+
+        assertEquals("Number of records with 'scientist' field = Darwin on must equal 50 after update", 50, testCollection.count(new Document("scientist", "Darwin")));
+    }
+
+    @Test
+    public void testUpdateUsingFieldsFilterHeader() throws Exception {
+        // Prepare test
+        assertEquals(0, testCollection.count());
+        for (int i = 1; i <= 100; i++) {
+            String body = null;
+            try (Formatter f = new Formatter();) {
+                if (i % 2 == 0) {
+                    body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
+                } else {
+                    body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i).toString();
+                }
+                f.close();
+            }
+            template.requestBody("direct:insert", body);
+        }
+        assertEquals(100L, testCollection.count());
+
+        // Testing the update logic
+        Bson extraField = eq("extraField", true);
+        assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
+        assertEquals("Number of records with 'scientist' field = Darwin on must equal 0", 0, testCollection.count(new Document("scientist", "Darwin")));
+
+        Bson updateObj = combine(set("scientist", "Darwin"), currentTimestamp("lastModified"));
+        HashMap<String, Object> headers = new HashMap<>();
+        headers.put(MongoDbConstants.MULTIUPDATE, true);
+        headers.put(MongoDbConstants.CRITERIA, extraField);
+        Object result = template.requestBodyAndHeaders("direct:update", updateObj, headers);
+        assertTrue(result instanceof UpdateResult);
+        assertEquals("Number of records updated header should equal 50", 50L, UpdateResult.class.cast(result).getModifiedCount());
+        assertEquals("Number of records with 'scientist' field = Darwin on must equal 50 after update", 50, testCollection.count(new Document("scientist", "Darwin")));
+    }
+
+    @Test
+    public void testRemove() throws Exception {
+        // Prepare test
+        assertEquals(0, testCollection.count());
+        for (int i = 1; i <= 100; i++) {
+            String body = null;
+            try (Formatter f = new Formatter();) {
+                if (i % 2 == 0) {
+                    body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
+                } else {
+                    body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i).toString();
+                }
+                f.close();
+            }
+            template.requestBody("direct:insert", body);
+        }
+        assertEquals(100L, testCollection.count());
+
+        // Testing the update logic
+        Document extraField = new Document("extraField", true);
+        assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
+
+        Exchange resultExchange = template.request("direct:remove", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(extraField);
+            }
+        });
+        Object result = resultExchange.getOut().getBody();
+        assertTrue(result instanceof DeleteResult);
+        assertEquals("Number of records deleted header should equal 50", 50L, resultExchange.getOut().getHeader(MongoDbConstants.RECORDS_AFFECTED));
+
+        assertEquals("Number of records with 'extraField' flag on must be 0 after remove", 0, testCollection.count(extraField));
+
+    }
+
+    @Test
+    public void testAggregate() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        pumpDataIntoTestCollection();
+
+        // Repeat ten times, obtain 10 batches of 100 results each time
+        List<Bson> aggregate = Arrays.asList(match(or(eq("scientist", "Darwin"), eq("scientist", "Einstein"))), group("$scientist", sum("count", 1)));
+        Object result = template.requestBody("direct:aggregate", aggregate);
+        assertTrue("Result is not of type List", result instanceof List);
+
+        @SuppressWarnings("unchecked")
+        List<Document> resultList = (List<Document>)result;
+        assertListSize("Result does not contain 2 elements", resultList, 2);
+        // TODO Add more asserts
+    }
+
+    @Test
+    public void testDbStats() throws Exception {
+        assertEquals(0, testCollection.count());
+        Object result = template.requestBody("direct:getDbStats", "irrelevantBody");
+        assertTrue("Result is not of type Document", result instanceof Document);
+        assertTrue("The result should contain keys", Document.class.cast(result).keySet().size() > 0);
+    }
+
+    @Test
+    public void testColStats() throws Exception {
+        assertEquals(0, testCollection.count());
+
+        // Add some records to the collection (and do it via camel-mongodb)
+        for (int i = 1; i <= 100; i++) {
+            String body = null;
+            try (Formatter f = new Formatter();) {
+                body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
+                f.close();
+            }
+            template.requestBody("direct:insert", body);
+        }
+
+        Object result = template.requestBody("direct:getColStats", "irrelevantBody");
+        assertTrue("Result is not of type Document", result instanceof Document);
+        assertTrue("The result should contain keys", Document.class.cast(result).keySet().size() > 0);
+    }
+
+    @Test
+    public void testCommand() throws Exception {
+        // Call hostInfo, command working with every configuration
+        Object result = template.requestBody("direct:command", "{\"hostInfo\":\"1\"}");
+        assertTrue("Result is not of type Document", result instanceof Document);
+        assertTrue("The result should contain keys", Document.class.cast(result).keySet().size() > 0);
+    }
+
+    @Test
+    public void testOperationHeader() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+
+        // check that the count operation was invoked instead of the insert
+        // operation
+        Object result = template.requestBodyAndHeader("direct:insert", "irrelevantBody", MongoDbConstants.OPERATION_HEADER, "count");
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Test collection should not contain any records", 0L, result);
+
+        // check that the count operation was invoked instead of the insert
+        // operation
+        result = template.requestBodyAndHeader("direct:insert", "irrelevantBody", MongoDbConstants.OPERATION_HEADER, MongoDbOperation.count);
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Test collection should not contain any records", 0L, result);
+
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+
+                from("direct:count").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=count&dynamicity=true");
+                from("direct:insert").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
+                from("direct:testStoreOidOnInsert").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert").setBody()
+                    .header(MongoDbConstants.OID);
+                from("direct:save").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=save");
+                from("direct:testStoreOidOnSave").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=save").setBody()
+                    .header(MongoDbConstants.OID);
+                from("direct:update").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=update");
+                from("direct:remove").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=remove");
+                from("direct:aggregate").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=aggregate");
+                from("direct:getDbStats").to("mongodb3:myDb?database={{mongodb.testDb}}&operation=getDbStats");
+                from("direct:getColStats").to("mongodb3:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=getColStats");
+                from("direct:command").to("mongodb3:myDb?database={{mongodb.testDb}}&operation=command");
+
+            }
+        };
+    }
 }


Mime
View raw message