You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/10/28 08:09:14 UTC

camel git commit: CAMEL-10414 query is ignored if filed filter header is set

Repository: camel
Updated Branches:
  refs/heads/master 4f9448d83 -> 7e2db36e7


CAMEL-10414 query is ignored if filed filter header is set


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

Branch: refs/heads/master
Commit: 7e2db36e7e4c00bd304830381b1d657585836854
Parents: 4f9448d
Author: Kevin Earls <ke...@kevinearls.com>
Authored: Fri Oct 28 09:39:00 2016 +0200
Committer: Kevin Earls <ke...@kevinearls.com>
Committed: Fri Oct 28 09:39:00 2016 +0200

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


http://git-wip-us.apache.org/repos/asf/camel/blob/7e2db36e/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 76cfca1..8b8437c 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
@@ -315,6 +315,8 @@ public class MongoDbProducer extends DefaultProducer {
                 ret = dbCol.find(new BasicDBObject());
             } else if (fieldFilter == null) {
                 ret = dbCol.find(query);
+            } else if (query != null) {
+                ret = dbCol.find(query).projection(fieldFilter);
             } else {
                 ret = dbCol.find(new BasicDBObject()).projection(fieldFilter);
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/7e2db36e/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 0f28f67..fca6ef4 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
@@ -58,7 +58,62 @@ public class MongoDbFindOperationTest extends AbstractMongoDbTest {
         assertEquals("Result page size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_PAGE_SIZE));
 
     }
-    
+
+    @Test
+    public void testFindAllWithQueryAndNoFIlter() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        pumpDataIntoTestCollection();
+
+        DBObject query = BasicDBObjectBuilder.start("scientist", "Einstein").get();
+        Object result = template.requestBody("direct:findAll", query);
+        assertTrue("Result is not of type List", result instanceof List);
+
+        @SuppressWarnings("unchecked")
+        List<DBObject> resultList = (List<DBObject>) 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'
+        for (DBObject dbObject : resultList) {
+            assertNotNull("DBObject in returned list should not contain field _id", dbObject.get("_id"));
+            assertNotNull("DBObject in returned list does not contain field 'scientist'", dbObject.get("scientist"));
+            assertNotNull("DBObject in returned list should not contain field fixedField", dbObject.get("fixedField"));
+            assertEquals("DBOject.scientist should only be Einstein", "Einstein", dbObject.get("scientist"));
+        }
+
+        Exchange resultExchange = getMockEndpoint("mock:resultFindAll").getReceivedExchanges().get(0);
+        assertEquals("Result page size header should equal 100", 100, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_PAGE_SIZE));
+    }
+
+    @Test
+    public void testFindAllWithQueryAndFilter() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        pumpDataIntoTestCollection();
+
+        DBObject fieldFilter = BasicDBObjectBuilder.start().add("_id", 0).add("fixedField", 0).get();
+        DBObject query = BasicDBObjectBuilder.start("scientist", "Einstein").get();
+        Object result = template.requestBodyAndHeader("direct:findAll", query, MongoDbConstants.FIELDS_FILTER, fieldFilter);
+        assertTrue("Result is not of type List", result instanceof List);
+
+        @SuppressWarnings("unchecked")
+        List<DBObject> resultList = (List<DBObject>) 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'
+        for (DBObject dbObject : resultList) {
+            assertNull("DBObject in returned list should not contain field _id", dbObject.get("_id"));
+            assertNotNull("DBObject in returned list does not contain field 'scientist'", dbObject.get("scientist"));
+            assertNull("DBObject in returned list should not contain field fixedField", dbObject.get("fixedField"));
+            assertEquals("DBOject.scientist should only be Einstein", "Einstein", dbObject.get("scientist"));
+        }
+
+        Exchange resultExchange = getMockEndpoint("mock:resultFindAll").getReceivedExchanges().get(0);
+        assertEquals("Result page size header should equal 100", 100, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_PAGE_SIZE));
+    }
+
     @Test
     public void testFindAllNoCriteriaWithFilterOperation() throws Exception {
         // Test that the collection has 0 documents in it