camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hekon...@apache.org
Subject camel git commit: MongoDB OIDs are now copied to headers on 'save' as well.
Date Mon, 10 Nov 2014 19:42:23 GMT
Repository: camel
Updated Branches:
  refs/heads/master 247fe5507 -> 8382a60b5


MongoDB OIDs are now copied to headers on 'save' as well.


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

Branch: refs/heads/master
Commit: 8382a60b561953ec577100a451c6b9adc5e2f6d3
Parents: 247fe55
Author: Henryk Konsek <hekonsek@gmail.com>
Authored: Mon Nov 10 20:42:03 2014 +0100
Committer: Henryk Konsek <hekonsek@gmail.com>
Committed: Mon Nov 10 20:42:14 2014 +0100

----------------------------------------------------------------------
 .../component/mongodb/MongoDbProducer.java      |  1 +
 .../mongodb/MongoDbOperationsTest.java          | 20 ++++++++++++++++++++
 .../mongodb/mongoBasicOperationsTest.xml        |  8 ++++++++
 3 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8382a60b/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 c2aab61..90d27f3 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
@@ -210,6 +210,7 @@ public class MongoDbProducer extends DefaultProducer {
 
         WriteConcern wc = extractWriteConcern(exchange);
         WriteResult result = wc == null ? dbCol.save(saveObj) : dbCol.save(saveObj, wc);
+        exchange.getIn().setHeader(MongoDbConstants.OID, saveObj.get("_id"));
 
         prepareResponseMessage(exchange, MongoDbOperation.save);
         // we always return the WriteResult, because whether the getLastError was called
or not, the user will have the means to call it or 

http://git-wip-us.apache.org/repos/asf/camel/blob/8382a60b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
index db14075..24d4442 100644
--- a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
+++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
@@ -28,6 +28,7 @@ import com.mongodb.util.JSON;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.bson.types.ObjectId;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class MongoDbOperationsTest extends AbstractMongoDbTest {
@@ -101,6 +102,23 @@ public class MongoDbOperationsTest extends AbstractMongoDbTest {
         assertEquals("Scientist field of 'testSave1' must equal 'Darwin' after save operation",
"Darwin", record1.get("scientist"));
 
     }
+
+    @Test
+    public void testStoreOidOnSave() throws Exception {
+        DBObject dbObject = new BasicDBObject();
+        ObjectId oid = template.requestBody("direct:testStoreOidOnSave", dbObject, ObjectId.class);
+        assertEquals(dbObject.get("_id"), oid);
+    }
+
+    @Ignore
+    @Test
+    public void testStoreOidsOnSave() throws Exception {
+        DBObject firstDbObject = new BasicDBObject();
+        DBObject secondDbObject = new BasicDBObject();
+        List<?> oids = template.requestBody("direct:testStoreOidOnSave", asList(firstDbObject,
secondDbObject), List.class);
+        assertTrue(oids.contains(firstDbObject.get("_id")));
+        assertTrue(oids.contains(secondDbObject.get("_id")));
+    }
     
     @Test
     public void testUpdate() throws Exception {
@@ -235,6 +253,8 @@ public class MongoDbOperationsTest extends AbstractMongoDbTest {
                 from("direct:testStoreOidOnInsert").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert&writeConcern=SAFE").
                     setBody().header(MongoDbConstants.OID);
                 from("direct:save").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=save&writeConcern=SAFE");
+                from("direct:testStoreOidOnSave").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=save&writeConcern=SAFE").
+                    setBody().header(MongoDbConstants.OID);
                 from("direct:update").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=update&writeConcern=SAFE");
                 from("direct:remove").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=remove&writeConcern=SAFE");
                 from("direct:aggregate").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=aggregate&writeConcern=SAFE");

http://git-wip-us.apache.org/repos/asf/camel/blob/8382a60b/components/camel-mongodb/src/test/resources/org/apache/camel/component/mongodb/mongoBasicOperationsTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/test/resources/org/apache/camel/component/mongodb/mongoBasicOperationsTest.xml
b/components/camel-mongodb/src/test/resources/org/apache/camel/component/mongodb/mongoBasicOperationsTest.xml
index ed39871..0263c11 100644
--- a/components/camel-mongodb/src/test/resources/org/apache/camel/component/mongodb/mongoBasicOperationsTest.xml
+++ b/components/camel-mongodb/src/test/resources/org/apache/camel/component/mongodb/mongoBasicOperationsTest.xml
@@ -50,6 +50,14 @@
     </route>
 
     <route>
+        <from uri="direct:testStoreOidOnSave" />
+        <to uri="mongodb:myDb?database={{mongodb.testDb}}&amp;collection={{mongodb.testCollection}}&amp;operation=save&amp;writeConcern=SAFE"
/>
+        <setBody>
+          <header>CamelMongoOid</header>
+        </setBody>
+    </route>
+
+    <route>
         <from uri="direct:update" />
         <to uri="mongodb:myDb?database={{mongodb.testDb}}&amp;collection={{mongodb.testCollection}}&amp;operation=update&amp;writeConcern=SAFE"
/>
     </route>


Mime
View raw message