camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-10443: fixing findById with ObjectId
Date Mon, 07 Nov 2016 09:38:18 GMT
CAMEL-10443: fixing findById with ObjectId


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f04f785a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f04f785a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f04f785a

Branch: refs/heads/camel-2.18.x
Commit: f04f785ab7e8bed46327dd2a9a4d595833b5364c
Parents: c69e59a
Author: Nick Busy <nbusy@enfoll.com>
Authored: Sun Nov 6 00:04:05 2016 +1100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Nov 7 10:38:08 2016 +0100

----------------------------------------------------------------------
 .../component/mongodb/MongoDbProducer.java      |  2 +-
 .../mongodb/MongoDbFindOperationTest.java       | 23 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f04f785a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
index 8b8437c..9a72e7e 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
@@ -478,7 +478,7 @@ public class MongoDbProducer extends DefaultProducer {
         return exchange1 -> {
             try {
                 MongoCollection<BasicDBObject> dbCol = calculateCollection(exchange1);
-                String id = exchange1.getIn().getMandatoryBody(String.class);
+                Object id = exchange1.getIn().getMandatoryBody();
                 BasicDBObject o = new BasicDBObject("_id", id);
                 DBObject ret;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/f04f785a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java
b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java
index fca6ef4..148a020 100644
--- a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java
+++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java
@@ -20,12 +20,14 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.mongodb.BasicDBObject;
 import com.mongodb.BasicDBObjectBuilder;
 import com.mongodb.DBObject;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 
+import org.bson.types.ObjectId;
 import org.junit.Test;
 
 public class MongoDbFindOperationTest extends AbstractMongoDbTest {
@@ -215,6 +217,27 @@ public class MongoDbFindOperationTest extends AbstractMongoDbTest {
         
     }
     
+    @Test
+    public void testFindOneByIdWithObjectId() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        BasicDBObject insertObject = new BasicDBObject("scientist", "Einstein");
+        testCollection.insertOne(insertObject);
+        assertTrue("The ID of the inserted document should be ObjectId", insertObject.get("_id")
instanceof ObjectId);
+        ObjectId id = (ObjectId) insertObject.get("_id");
+        
+        DBObject result = template.requestBody("direct:findById", id, DBObject.class);
+        assertTrue("Result is not of type DBObject", result instanceof DBObject);
+
+        assertTrue("The ID of the retrieved DBObject should be ObjectId", result.get("_id")
instanceof ObjectId);
+        assertEquals("The ID of the retrieved DBObject should equal to the inserted", id,
result.get("_id"));
+        assertEquals("The scientist name of the retrieved DBObject should equal Einstein",
"Einstein", result.get("scientist"));
+        
+        assertNotNull("DBObject in returned list should contain all fields", result.get("_id"));
+        assertNotNull("DBObject in returned list should contain all fields", result.get("scientist"));
+        
+    }
+    
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {


Mime
View raw message