Updated Branches: refs/heads/camel-2.12.x e6fe5fa08 -> e010cc659
CAMEL-6805: Fixed the failing MongoDbIndexTest. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e010cc65 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e010cc65 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e010cc65 Branch: refs/heads/camel-2.12.x Commit: e010cc6599ad662d9ae3a54568d48a3079f9d8e2 Parents: e6fe5fa Author: Babak Vahdat <bvah...@apache.org> Authored: Tue Oct 1 13:52:58 2013 +0200 Committer: Babak Vahdat <bvah...@apache.org> Committed: Tue Oct 1 13:54:24 2013 +0200 ---------------------------------------------------------------------- .../camel/component/mongodb/MongoDbEndpoint.java | 5 ++++- .../camel/component/mongodb/MongoDbIndexTest.java | 17 +++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/e010cc65/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java index c216ccb..3bcfa9e 100644 --- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java +++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java @@ -218,7 +218,10 @@ public class MongoDbEndpoint extends DefaultEndpoint { for (Map.Entry<String, String> set : indexMap.entrySet()) { DBObject index = new BasicDBObject(); - index.put(set.getKey(), set.getValue()); + // MongoDB 2.4 upwards is restrictive about the type of the 'single field index' being in use so that + // we should convert the index value to an Integer, see also: + // http://docs.mongodb.org/manual/release-notes/2.4/#improved-validation-of-index-types + index.put(set.getKey(), Integer.valueOf(set.getValue())); indexList.add(index); } http://git-wip-us.apache.org/repos/asf/camel/blob/e010cc65/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbIndexTest.java ---------------------------------------------------------------------- diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbIndexTest.java b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbIndexTest.java index 25468f5..8081577 100644 --- a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbIndexTest.java +++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbIndexTest.java @@ -59,11 +59,9 @@ public class MongoDbIndexTest extends AbstractMongoDbTest { List<DBObject> indexInfos = dynamicCollection.getIndexInfo(); - BasicDBObject key1 = (BasicDBObject) indexInfos.get(1).get("key"); - BasicDBObject key2 = (BasicDBObject) indexInfos.get(2).get("key"); + BasicDBObject key = (BasicDBObject) indexInfos.get(0).get("key"); - assertTrue("No index on the field a", key1.containsField("a") && "1".equals(key1.getString("a"))); - assertTrue("No index on the field b", key2.containsField("b") && "-1".equals(key2.getString("b"))); + assertTrue("The field _id with the expected value not found", key.containsField("_id") && "1".equals(key.getString("_id"))); DBObject b = dynamicCollection.findOne("testInsertDynamicityEnabledDBAndCollection"); assertNotNull("No record with 'testInsertDynamicityEnabledDBAndCollection' _id", b); @@ -102,11 +100,9 @@ public class MongoDbIndexTest extends AbstractMongoDbTest { List<DBObject> indexInfos = dynamicCollection.getIndexInfo(); - BasicDBObject key1 = (BasicDBObject) indexInfos.get(1).get("key"); - BasicDBObject key2 = (BasicDBObject) indexInfos.get(2).get("key"); + BasicDBObject key = (BasicDBObject) indexInfos.get(0).get("key"); - assertTrue("No index on the field a", key1.containsField("a") && "1".equals(key1.getString("a"))); - assertTrue("No index on the field b", key2.containsField("b") && "-1".equals(key2.getString("b"))); + assertTrue("The field _id with the expected value not found", key.containsField("_id") && "1".equals(key.getString("_id"))); DBObject b = dynamicCollection.findOne("testInsertDynamicityEnabledCollectionAndIndex"); assertNotNull("No record with 'testInsertDynamicityEnabledCollectionAndIndex' _id", b); @@ -133,11 +129,12 @@ public class MongoDbIndexTest extends AbstractMongoDbTest { assertEquals("Response isn't of type WriteResult", WriteResult.class, result.getClass()); DBCollection dynamicCollection = db.getCollection("otherCollection"); + List<DBObject> indexInfos = dynamicCollection.getIndexInfo(); - BasicDBObject key1 = (BasicDBObject) indexInfos.get(1).get("key"); + BasicDBObject key = (BasicDBObject)indexInfos.get(0).get("key"); - assertFalse("No index on the field a", key1.containsField("a") && "-1".equals(key1.getString("a"))); + assertTrue("The field _id with the expected value not found", key.containsField("_id") && "1".equals(key.getString("_id"))); DBObject b = dynamicCollection.findOne("testInsertDynamicityEnabledCollectionOnlyAndURIIndex"); assertNotNull("No record with 'testInsertDynamicityEnabledCollectionOnlyAndURIIndex' _id", b);