camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-10414 query is ignored if filed filter header is set
Date Fri, 28 Oct 2016 08:12:07 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x c6a90ce40 -> 9143e2c5b


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/9143e2c5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9143e2c5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9143e2c5

Branch: refs/heads/camel-2.17.x
Commit: 9143e2c5b3b7ba230739fe3977dba87fdf63f439
Parents: c6a90ce
Author: Kevin Earls <kevin@kevinearls.com>
Authored: Fri Oct 28 09:39:00 2016 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri Oct 28 10:11:35 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/9143e2c5/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 207f564..b52a36e 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
@@ -309,6 +309,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(query, fieldFilter);
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/9143e2c5/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 1db0912..32db5a6 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
@@ -57,7 +57,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


Mime
View raw message