camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1244980 [2/3] - in /camel/trunk: components/ components/camel-mongodb/ components/camel-mongodb/src/ components/camel-mongodb/src/main/ components/camel-mongodb/src/main/java/ components/camel-mongodb/src/main/java/org/ components/camel-mo...
Date Thu, 16 Feb 2012 14:09:57 GMT
Added: camel/trunk/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java (added)
+++ camel/trunk/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java Thu Feb 16 14:09:55 2012
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mongodb.converters;
+
+import java.util.Map;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBObject;
+import com.mongodb.util.JSON;
+
+import org.apache.camel.Converter;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@SuppressWarnings({"unchecked", "rawtypes"})
+@Converter
+public final class MongoDbBasicConverters {
+    
+    private static final transient Logger LOG = LoggerFactory.getLogger(MongoDbBasicConverters.class);
+
+    // Jackson's ObjectMapper is thread-safe, so no need to create a pool nor synchronize access to it
+    private static ObjectMapper objectMapper;
+    
+    // will attempt to load the Jackson ObjectMapper class using the class loader of MongoDbBasicConverters
+    // in an OSGi environment, if Jackson is present it would have already been wired since Jackson is an optional dependency (Import-Package)
+    static {
+        try {
+            Class<ObjectMapper> objectMapperC = (Class<ObjectMapper>) MongoDbBasicConverters.class.getClassLoader().loadClass("org.codehaus.jackson.map.ObjectMapper");
+            MongoDbBasicConverters.objectMapper = objectMapperC.newInstance();
+        } catch (Exception e) {
+            // do nothing, Jackson not found
+        }
+    }
+
+    private MongoDbBasicConverters() { }
+    
+    @Converter
+    public static DBObject fromMapToDBObject(Map<?, ?> map) {
+        return new BasicDBObject(map);
+    }
+    
+    @Converter
+    public static Map<String, Object> fromBasicDBObjectToMap(BasicDBObject basicDbObject) {
+        return basicDbObject;
+    }
+    
+    @Converter
+    public static DBObject fromStringToDBObject(String s) {
+        DBObject answer = null;
+        try {
+            answer = (DBObject) JSON.parse(s);
+        } catch (Exception e) {
+            LOG.warn("String -> DBObject conversion selected, but the following exception occurred. Returning null.", e);
+        }
+        
+        return answer;
+    }
+   
+    @Converter
+    public static DBObject fromAnyObjectToDBObject(Object value) {
+        if (MongoDbBasicConverters.objectMapper == null) {
+            LOG.warn("Conversion has fallen back to generic Object -> DBObject, but Jackson " 
+                         + "was not available on the classpath during initialization. Returning null.");
+            return null;
+        }
+        
+        BasicDBObject answer;
+        try {
+            Map m = MongoDbBasicConverters.objectMapper.convertValue(value, Map.class);
+            answer = new BasicDBObject(m);
+        } catch (Exception e) {
+            LOG.warn("Conversion has fallen back to generic Object -> DBObject, but unable to convert type {}. Returning null.", 
+                    value.getClass().getCanonicalName());
+            return null;
+        }
+        return answer;
+    }
+    
+}

Propchange: camel/trunk/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-mongodb/src/main/resources/LICENSE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/main/resources/LICENSE.txt?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/main/resources/LICENSE.txt (added)
+++ camel/trunk/components/camel-mongodb/src/main/resources/LICENSE.txt Thu Feb 16 14:09:55 2012
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+

Propchange: camel/trunk/components/camel-mongodb/src/main/resources/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mongodb/src/main/resources/LICENSE.txt
------------------------------------------------------------------------------
    svn:executable = *

Propchange: camel/trunk/components/camel-mongodb/src/main/resources/LICENSE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/components/camel-mongodb/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/main/resources/META-INF/services/org/apache/camel/TypeConverter (added)
+++ camel/trunk/components/camel-mongodb/src/main/resources/META-INF/services/org/apache/camel/TypeConverter Thu Feb 16 14:09:55 2012
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.camel.component.mongodb.converters.MongoDbBasicConverters
\ No newline at end of file

Added: camel/trunk/components/camel-mongodb/src/main/resources/META-INF/services/org/apache/camel/component/mongodb
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/main/resources/META-INF/services/org/apache/camel/component/mongodb?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/main/resources/META-INF/services/org/apache/camel/component/mongodb (added)
+++ camel/trunk/components/camel-mongodb/src/main/resources/META-INF/services/org/apache/camel/component/mongodb Thu Feb 16 14:09:55 2012
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class=org.apache.camel.component.mongodb.MongoDbComponent

Added: camel/trunk/components/camel-mongodb/src/main/resources/NOTICE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/main/resources/NOTICE.txt?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/main/resources/NOTICE.txt (added)
+++ camel/trunk/components/camel-mongodb/src/main/resources/NOTICE.txt Thu Feb 16 14:09:55 2012
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

Propchange: camel/trunk/components/camel-mongodb/src/main/resources/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mongodb/src/main/resources/NOTICE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/AbstractMongoDbTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/AbstractMongoDbTest.java?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/AbstractMongoDbTest.java (added)
+++ camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/AbstractMongoDbTest.java Thu Feb 16 14:09:55 2012
@@ -0,0 +1,128 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mongodb;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Formatter;
+import java.util.Properties;
+
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.Mongo;
+import com.mongodb.MongoURI;
+import com.mongodb.WriteConcern;
+import com.mongodb.util.JSON;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.springframework.context.ApplicationContext;
+
+public abstract class AbstractMongoDbTest extends CamelTestSupport {
+
+    protected static Mongo mongo;
+    protected static DB db;
+    protected static DBCollection testCollection;
+    protected static DBCollection dynamicCollection;
+    
+    protected static String dbName;
+    protected static String testCollectionName;
+    protected static String dynamicCollectionName;
+
+    protected static Properties properties;
+    
+    protected ApplicationContext applicationContext;
+    
+
+    public AbstractMongoDbTest() {
+        super();
+    }
+    
+    /**
+     * Checks whether Mongo is running using the connection URI defined in the mongodb.test.properties file
+     * @throws IOException 
+     */
+    @BeforeClass
+    public static void checkMongoRunning() throws IOException {
+        properties = new Properties();
+        InputStream is = MongoDbConversionsTest.class.getResourceAsStream("/mongodb.test.properties");
+        properties.load(is);
+        // ping Mongo and populate db and collection
+        try {
+            mongo = new Mongo(new MongoURI(properties.getProperty("mongodb.connectionURI")));
+            mongo.getDatabaseNames();
+            dbName = properties.getProperty("mongodb.testDb");
+            db = mongo.getDB(dbName);
+        } catch (Exception e) {
+            Assume.assumeNoException(e);
+        }
+        
+    }
+
+    @Before
+    public void initTestCase() {
+        // Refresh the test collection - drop it and recreate it. We don't do this for the database because MongoDB would create large
+        // store files each time
+        testCollectionName = properties.getProperty("mongodb.testCollection");
+        testCollection = db.getCollection(testCollectionName);
+        testCollection.drop();
+        testCollection = db.getCollection(testCollectionName);
+        
+        dynamicCollectionName = testCollectionName.concat("Dynamic");
+        dynamicCollection = db.getCollection(dynamicCollectionName);
+        dynamicCollection.drop();
+        dynamicCollection = db.getCollection(dynamicCollectionName);
+
+    }
+
+    @After
+    public void cleanup() {
+        testCollection.drop();
+        dynamicCollection.drop();
+    }
+
+    protected void pumpDataIntoTestCollection() {
+        // there should be 100 of each
+        String[] scientists = {"Einstein", "Darwin", "Copernicus", "Pasteur", "Curie", "Faraday", "Newton", "Bohr", "Galilei", "Maxwell"};
+        for (int i = 1; i <= 1000; i++) {
+            int index = i % scientists.length;
+            Formatter f = new Formatter();
+            String doc = f.format("{\"_id\":\"%d\", \"scientist\":\"%s\", \"fixedField\": \"fixedValue\"}", i, scientists[index]).toString();
+            testCollection.insert((DBObject) JSON.parse(doc), WriteConcern.SAFE);
+        }
+        assertEquals("Data pumping of 1000 entries did not complete entirely", 1000L, testCollection.count());
+    }
+
+    protected CamelMongoDbException extractAndAssertCamelMongoDbException(Object result, String message) {
+        assertTrue("Result is not an Exception", result instanceof Throwable);
+        assertTrue("Result is not an CamelExecutionException", result instanceof CamelExecutionException);
+        Throwable exc = ((CamelExecutionException) result).getCause();
+        assertTrue("Result is not an CamelMongoDbException", exc instanceof CamelMongoDbException);
+        CamelMongoDbException camelExc = ObjectHelper.cast(CamelMongoDbException.class, exc);
+        if (message != null) {
+            assertTrue("CamelMongoDbException doesn't contain desired message string", camelExc.getMessage().contains(message));
+        }
+        return camelExc;
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/AbstractMongoDbTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/AbstractMongoDbTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConversionsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConversionsTest.java?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConversionsTest.java (added)
+++ camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConversionsTest.java Thu Feb 16 14:09:55 2012
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mongodb;
+
+import java.util.HashMap;
+
+import com.mongodb.DBObject;
+import com.mongodb.WriteResult;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.spring.SpringCamelContext;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MongoDbConversionsTest extends AbstractMongoDbTest {
+    
+    @Test
+    public void testInsertMap() throws InterruptedException {
+        assertEquals(0, testCollection.count());
+        
+        HashMap<String, Object> m1 = new HashMap<String, Object>();
+        HashMap<String, String> m1Nested = new HashMap<String, String>();
+
+        m1Nested.put("nested1", "nestedValue1");
+        m1Nested.put("nested2", "nestedValue2");
+        
+        m1.put("field1", "value1");
+        m1.put("field2", "value2");
+        m1.put("nestedField", m1Nested);
+        m1.put("_id", "testInsertMap");
+
+        Object result = template.requestBody("direct:insertMap", m1);
+        assertTrue(result instanceof WriteResult);
+        DBObject b = testCollection.findOne("testInsertMap");
+        assertNotNull("No record with 'testInsertMap' _id", b);
+
+    }
+    
+    @Test
+    public void testInsertPojo() {
+        assertEquals(0, testCollection.count());
+        Object result = template.requestBody("direct:insertPojo", new MyPojoTest());
+        assertTrue(result instanceof WriteResult);
+        DBObject b = testCollection.findOne("testInsertPojo");
+        assertNotNull("No record with 'testInsertPojo' _id", b);
+    }
+    
+    @Test
+    public void testInsertJsonString() {
+        assertEquals(0, testCollection.count());
+        Object result = template.requestBody("direct:insertJsonString", "{\"fruits\": [\"apple\", \"banana\", \"papaya\"], \"veggie\": \"broccoli\", \"_id\": \"testInsertJsonString\"}");
+        assertTrue(result instanceof WriteResult);
+        DBObject b = testCollection.findOne("testInsertJsonString");
+        assertNotNull("No record with 'testInsertJsonString' _id", b);
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/mongodb/mongoComponentTest.xml");
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                
+                PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties");
+                context.addComponent("properties", pc);
+                
+                from("direct:insertMap").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
+                from("direct:insertPojo").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
+                from("direct:insertJsonString").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
+                from("direct:insertJsonStringWriteResultInString").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert").convertBodyTo(String.class);
+
+            }
+        };
+    }
+    
+    @SuppressWarnings("unused")
+    private class MyPojoTest {
+        public int number = 123;
+        public String text = "hello";
+        public String[] array = {"daVinci", "copernico", "einstein"};
+        // CHECKSTYLE:OFF
+        public String _id = "testInsertPojo";
+        // CHECKSTYLE:ON
+    }
+    
+}

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConversionsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConversionsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbDynamicityTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbDynamicityTest.java?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbDynamicityTest.java (added)
+++ camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbDynamicityTest.java Thu Feb 16 14:09:55 2012
@@ -0,0 +1,156 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mongodb;
+
+import java.util.HashMap;
+
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.WriteResult;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.spring.SpringCamelContext;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MongoDbDynamicityTest extends AbstractMongoDbTest {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/mongodb/mongoComponentTest.xml");
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+    
+    @Test
+    public void testInsertDynamicityDisabled() {
+        assertEquals(0, testCollection.count());
+        mongo.getDB("otherDB").dropDatabase();
+        assertFalse("The otherDB database should not exist", mongo.getDatabaseNames().contains("otherDB"));
+
+        String body = "{\"_id\": \"testInsertDynamicityDisabled\", \"a\" : \"1\"}";
+        HashMap<String, Object> headers = new HashMap<String, Object>();
+        headers.put(MongoDbConstants.DATABASE, "otherDB");
+        headers.put(MongoDbConstants.COLLECTION, "otherCollection");
+        Object result = template.requestBodyAndHeaders("direct:noDynamicity", body, headers);
+        assertEquals("Response isn't of type WriteResult", WriteResult.class, result.getClass());
+        
+        DBObject b = testCollection.findOne("testInsertDynamicityDisabled");
+        assertNotNull("No record with 'testInsertDynamicityDisabled' _id", b);
+        
+        body = "{\"_id\": \"testInsertDynamicityDisabledExplicitly\", \"a\" : \"1\"}";
+        result = template.requestBodyAndHeaders("direct:noDynamicityExplicit", body, headers);
+        assertEquals("Response isn't of type WriteResult", WriteResult.class, result.getClass());
+        
+        b = testCollection.findOne("testInsertDynamicityDisabledExplicitly");
+        assertNotNull("No record with 'testInsertDynamicityDisabledExplicitly' _id", b);
+        
+        assertFalse("The otherDB database should not exist", mongo.getDatabaseNames().contains("otherDB"));
+
+    }
+    
+    @Test
+    public void testInsertDynamicityEnabledDBOnly() {
+        assertEquals(0, testCollection.count());
+        mongo.getDB("otherDB").dropDatabase();
+        assertFalse("The otherDB database should not exist", mongo.getDatabaseNames().contains("otherDB"));
+
+        String body = "{\"_id\": \"testInsertDynamicityEnabledDBOnly\", \"a\" : \"1\"}";
+        HashMap<String, Object> headers = new HashMap<String, Object>();
+        headers.put(MongoDbConstants.DATABASE, "otherDB");
+        Object result = template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
+        
+        assertEquals("Response isn't of type WriteResult", WriteResult.class, result.getClass());
+        
+        DBCollection dynamicCollection = mongo.getDB("otherDB").getCollection(testCollection.getName());
+        
+        DBObject b = dynamicCollection.findOne("testInsertDynamicityEnabledDBOnly");
+        assertNotNull("No record with 'testInsertDynamicityEnabledDBOnly' _id", b);
+        
+        b = testCollection.findOne("testInsertDynamicityEnabledDBOnly");
+        assertNull("There is a record with 'testInsertDynamicityEnabledDBOnly' _id in the test collection", b);
+        
+        assertTrue("The otherDB database should exist", mongo.getDatabaseNames().contains("otherDB"));
+        
+    }
+    
+    @Test
+    public void testInsertDynamicityEnabledCollectionOnly() {
+        assertEquals(0, testCollection.count());
+        mongo.getDB("otherDB").dropDatabase();
+        assertFalse("The otherDB database should not exist", mongo.getDatabaseNames().contains("otherDB"));
+
+        String body = "{\"_id\": \"testInsertDynamicityEnabledCollectionOnly\", \"a\" : \"1\"}";
+        HashMap<String, Object> headers = new HashMap<String, Object>();
+        headers.put(MongoDbConstants.COLLECTION, "otherCollection");
+        Object result = template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
+        
+        assertEquals("Response isn't of type WriteResult", WriteResult.class, result.getClass());
+        
+        DBCollection dynamicCollection = db.getCollection("otherCollection");
+        
+        DBObject b = dynamicCollection.findOne("testInsertDynamicityEnabledCollectionOnly");
+        assertNotNull("No record with 'testInsertDynamicityEnabledCollectionOnly' _id", b);
+        
+        b = testCollection.findOne("testInsertDynamicityEnabledDBOnly");
+        assertNull("There is a record with 'testInsertDynamicityEnabledCollectionOnly' _id in the test collection", b);
+        
+        assertFalse("The otherDB database should not exist", mongo.getDatabaseNames().contains("otherDB"));
+    }
+    
+    @Test
+    public void testInsertDynamicityEnabledDBAndCollection() {
+        assertEquals(0, testCollection.count());
+        mongo.getDB("otherDB").dropDatabase();
+        assertFalse("The otherDB database should not exist", mongo.getDatabaseNames().contains("otherDB"));
+
+        String body = "{\"_id\": \"testInsertDynamicityEnabledDBAndCollection\", \"a\" : \"1\"}";
+        HashMap<String, Object> headers = new HashMap<String, Object>();
+        headers.put(MongoDbConstants.DATABASE, "otherDB");
+        headers.put(MongoDbConstants.COLLECTION, "otherCollection");
+        Object result = template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
+        
+        assertEquals("Response isn't of type WriteResult", WriteResult.class, result.getClass());
+        
+        DBCollection dynamicCollection = mongo.getDB("otherDB").getCollection("otherCollection");
+        
+        DBObject b = dynamicCollection.findOne("testInsertDynamicityEnabledDBAndCollection");
+        assertNotNull("No record with 'testInsertDynamicityEnabledDBAndCollection' _id", b);
+        
+        b = testCollection.findOne("testInsertDynamicityEnabledDBOnly");
+        assertNull("There is a record with 'testInsertDynamicityEnabledDBAndCollection' _id in the test collection", b);
+        
+        assertTrue("The otherDB database should exist", mongo.getDatabaseNames().contains("otherDB"));
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                
+                PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties");
+                context.addComponent("properties", pc);
+                                
+                from("direct:noDynamicity").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
+                from("direct:noDynamicityExplicit").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert&dynamicity=false");
+                from("direct:dynamicityEnabled").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert&dynamicity=true");
+
+            }
+        };
+    }
+}

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbDynamicityTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbDynamicityTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbExceptionHandlingTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbExceptionHandlingTest.java?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbExceptionHandlingTest.java (added)
+++ camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbExceptionHandlingTest.java Thu Feb 16 14:09:55 2012
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mongodb;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.spring.SpringCamelContext;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MongoDbExceptionHandlingTest extends AbstractMongoDbTest {    
+    
+    @Test
+    public void testInduceParseException() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        pumpDataIntoTestCollection();
+        
+        // notice missing quote at the end of Einstein
+        try {
+            template.requestBody("direct:findOneByQuery", "{\"scientist\": \"Einstein}");
+        } catch (Exception e) {
+            extractAndAssertCamelMongoDbException(e, null);
+        }
+    }
+    
+    @Test
+    public void testErroneousDynamicOperation() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        pumpDataIntoTestCollection();
+        
+        try {
+            template.requestBodyAndHeader("direct:findOneByQuery", "{\"scientist\": \"Einstein\"}", MongoDbConstants.OPERATION_HEADER, "dummyOp");
+        } catch (Exception e) {
+            extractAndAssertCamelMongoDbException(e, "Operation specified on header is not supported. Value: dummyOp");
+        }
+       
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/mongodb/mongoComponentTest.xml");
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                
+                PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties");
+                context.addComponent("properties", pc);
+                
+                from("direct:findAll")
+                    .to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findAll&dynamicity=true")
+                    .to("mock:resultFindAll");
+                
+                from("direct:findOneByQuery")
+                    .to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findOneByQuery&dynamicity=true")
+                    .to("mock:resultFindOneByQuery");
+                
+                from("direct:findById")
+                    .to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findById&dynamicity=true")
+                    .to("mock:resultFindById");
+
+            }
+        };
+    }
+}

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbExceptionHandlingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbExceptionHandlingTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java (added)
+++ camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java Thu Feb 16 14:09:55 2012
@@ -0,0 +1,185 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mongodb;
+
+import java.util.HashMap;
+import java.util.List;
+
+import com.mongodb.BasicDBObjectBuilder;
+import com.mongodb.DBObject;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.spring.SpringCamelContext;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MongoDbFindOperationTest extends AbstractMongoDbTest {
+ 
+    @Test
+    public void testFindAllNoCriteriaOperation() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        pumpDataIntoTestCollection();
+        
+        Object result = template.requestBody("direct:findAll", (Object) null);
+        assertTrue("Result is not of type List", result instanceof List);
+        
+        List<DBObject> resultList = (List<DBObject>) result;
+        assertListSize("Result does not contain all entries in collection", resultList, 1000);
+        
+        // Ensure that all returned documents contain all fields
+        for (DBObject dbObject : resultList) {
+            assertNotNull("DBObject in returned list should contain all fields", dbObject.get("_id"));
+            assertNotNull("DBObject in returned list should contain all fields", dbObject.get("scientist"));
+            assertNotNull("DBObject in returned list should contain all fields", dbObject.get("fixedField"));
+        }
+        
+        Exchange resultExchange = getMockEndpoint("mock:resultFindAll").getReceivedExchanges().get(0);
+        assertEquals("Result total size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_TOTAL_SIZE));
+        assertEquals("Result page size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_PAGE_SIZE));
+
+    }
+    
+    @Test
+    public void testFindAllNoCriteriaWithFilterOperation() 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();
+        Object result = template.requestBodyAndHeader("direct:findAll", (Object) null, MongoDbConstants.FIELDS_FILTER, fieldFilter);
+        assertTrue("Result is not of type List", result instanceof List);
+        
+        List<DBObject> resultList = (List<DBObject>) result;
+        assertListSize("Result does not contain all entries in collection", resultList, 1000);
+        
+        // Ensure that all returned documents contain all fields
+        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"));
+        }
+        
+        Exchange resultExchange = getMockEndpoint("mock:resultFindAll").getReceivedExchanges().get(0);
+        assertEquals("Result total size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_TOTAL_SIZE));
+        assertEquals("Result page size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_PAGE_SIZE));
+        
+    }
+    
+    @Test
+    public void testFindAllIterationOperation() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        pumpDataIntoTestCollection();
+        
+        // Repeat ten times, obtain 10 batches of 100 results each time
+        int numToSkip = 0;
+        final int limit = 100;
+        for (int i = 0; i < 10; i++) {
+            HashMap<String, Object> headers = new HashMap<String, Object>();
+            headers.put(MongoDbConstants.NUM_TO_SKIP, numToSkip);
+            headers.put(MongoDbConstants.LIMIT, 100);
+            Object result = template.requestBodyAndHeaders("direct:findAll", (Object) null, headers);
+            assertTrue("Result is not of type List", result instanceof List);
+            
+            List<DBObject> resultList = (List<DBObject>) result;
+            assertListSize("Result does not contain 100 elements", resultList, 100);
+            assertEquals("Id of first record is not as expected", numToSkip + 1, Integer.parseInt((String) resultList.get(0).get("_id")));
+            
+            // Ensure that all returned documents contain all fields
+            for (DBObject dbObject : resultList) {
+                assertNotNull("DBObject in returned list should contain all fields", dbObject.get("_id"));
+                assertNotNull("DBObject in returned list should contain all fields", dbObject.get("scientist"));
+                assertNotNull("DBObject in returned list should contain all fields", dbObject.get("fixedField"));
+            }
+            
+            numToSkip = numToSkip + limit;
+        }
+        
+        for (Exchange resultExchange : getMockEndpoint("mock:resultFindAll").getReceivedExchanges()) {
+            assertEquals("Result total size header should equal 1000", 1000, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_TOTAL_SIZE));
+            assertEquals("Result page size header should equal 100", 100, resultExchange.getIn().getHeader(MongoDbConstants.RESULT_PAGE_SIZE));
+        }
+    }
+    
+    @Test
+    public void testFindOneByQuery() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        pumpDataIntoTestCollection();
+        
+        DBObject query = BasicDBObjectBuilder.start("scientist", "Einstein").get();
+        DBObject result = template.requestBody("direct:findOneByQuery", query, DBObject.class);
+        assertTrue("Result is not of type DBObject", result instanceof DBObject);
+
+        assertNotNull("DBObject in returned list should contain all fields", result.get("_id"));
+        assertNotNull("DBObject in returned list should contain all fields", result.get("scientist"));
+        assertNotNull("DBObject in returned list should contain all fields", result.get("fixedField"));
+        
+    }
+    
+    @Test
+    public void testFindOneById() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        pumpDataIntoTestCollection();
+        
+        DBObject result = template.requestBody("direct:findById", "240", DBObject.class);
+        assertTrue("Result is not of type DBObject", result instanceof DBObject);
+
+        assertEquals("The ID of the retrieved DBObject should equal 240", "240", 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"));
+        assertNotNull("DBObject in returned list should contain all fields", result.get("fixedField"));
+        
+    }
+    
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/mongodb/mongoComponentTest.xml");
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                
+                PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties");
+                context.addComponent("properties", pc);
+                
+                from("direct:findAll")
+                    .to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findAll&dynamicity=true")
+                    .to("mock:resultFindAll");
+                
+                from("direct:findOneByQuery")
+                    .to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findOneByQuery&dynamicity=true")
+                    .to("mock:resultFindOneByQuery");
+                
+                from("direct:findById")
+                    .to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=findById&dynamicity=true")
+                    .to("mock:resultFindById");
+
+            }
+        };
+    }
+}

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbFindOperationTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java?rev=1244980&view=auto
==============================================================================
--- camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java (added)
+++ camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java Thu Feb 16 14:09:55 2012
@@ -0,0 +1,231 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mongodb;
+
+import java.util.Formatter;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBObject;
+import com.mongodb.WriteResult;
+import com.mongodb.util.JSON;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.spring.SpringCamelContext;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MongoDbOperationsTest extends AbstractMongoDbTest {
+
+    @Test
+    public void testCountOperation() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        Object result = template.requestBody("direct:count", "irrelevantBody");
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Test collection should not contain any records", 0L, result);
+
+        // Insert a record and test that the endpoint now returns 1
+        testCollection.insert((DBObject) JSON.parse("{a:60}"));
+        result = template.requestBody("direct:count", "irrelevantBody");
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Test collection should contain 1 record", 1L, result);
+        testCollection.remove(new BasicDBObject());
+        
+        // test dynamicity
+        dynamicCollection.insert((DBObject) JSON.parse("{a:60}"));
+        result = template.requestBodyAndHeader("direct:count", "irrelevantBody", MongoDbConstants.COLLECTION, dynamicCollectionName);
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Dynamic collection should contain 1 record", 1L, result);
+        
+    }
+    
+    @Test
+    public void testInsertString() throws Exception {
+        assertEquals(0, testCollection.count());
+        Object result = template.requestBody("direct:insert", "{\"_id\":\"testInsertString\", \"scientist\":\"Einstein\"}");
+        assertTrue(result instanceof WriteResult);
+        DBObject b = testCollection.findOne("testInsertString");
+        assertNotNull("No record with 'testInsertString' _id", b);
+    }
+    
+    @Test
+    public void testInsertArrayStrings() throws Exception {
+        assertEquals(0, testCollection.count());
+        Object[] req = new Object[] {"{\"_id\":\"testInsertArrayStrings\", \"scientist\":\"Einstein\"}", "{\"_id\":\"testInsertArrayStrings2\", \"scientist\":\"Copernicus\"}"};
+        Object result = template.requestBody("direct:insert", req);
+        assertTrue(result instanceof WriteResult);
+        DBObject b = testCollection.findOne("testInsertArrayStrings");
+        assertNotNull("No record with 'testInsertArrayStrings' _id", b);
+        b = testCollection.findOne("testInsertArrayStrings2");
+        assertNotNull("No record with 'testInsertArrayStrings2' _id", b);
+    }
+    
+    @Test
+    public void testSave() throws Exception {
+        // Prepare test
+        assertEquals(0, testCollection.count());
+        Object[] req = new Object[] {"{\"_id\":\"testSave1\", \"scientist\":\"Einstein\"}", "{\"_id\":\"testSave2\", \"scientist\":\"Copernicus\"}"};
+        Object result = template.requestBody("direct:insert", req);
+        assertTrue(result instanceof WriteResult);
+        assertEquals("Number of records persisted must be 2", 2, testCollection.count());
+        
+        // Testing the save logic
+        DBObject record1 = testCollection.findOne("testSave1");
+        assertEquals("Scientist field of 'testSave1' must equal 'Einstein'", "Einstein", record1.get("scientist"));
+        record1.put("scientist", "Darwin");
+        
+        result = template.requestBody("direct:save", record1);
+        assertTrue(result instanceof WriteResult);
+        
+        record1 = testCollection.findOne("testSave1");
+        assertEquals("Scientist field of 'testSave1' must equal 'Darwin' after save operation", "Darwin", record1.get("scientist"));
+        record1.put("scientist", "Darwin");
+
+    }
+    
+    @Test
+    public void testUpdate() throws Exception {
+        // Prepare test
+        assertEquals(0, testCollection.count());
+        for (int i = 1; i <= 100; i++) {
+            String body = null;
+            Formatter f = new Formatter();
+            if (i % 2 == 0) {
+                body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
+            } else {
+                body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i).toString();
+            }
+            template.requestBody("direct:insert", body);
+        }
+        assertEquals(100L, testCollection.count());
+        
+        // Testing the update logic
+        DBObject extraField = new BasicDBObject("extraField", true);
+        assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
+        assertEquals("Number of records with 'scientist' field = Darwin on must equal 0", 0, testCollection.count(new BasicDBObject("scientist", "Darwin")));
+
+        DBObject updateObj = new BasicDBObject("$set", new BasicDBObject("scientist", "Darwin"));
+        
+        Object result = template.requestBodyAndHeader("direct:update", new Object[] {extraField, updateObj}, MongoDbConstants.MULTIUPDATE, true);
+        assertTrue(result instanceof WriteResult);
+        
+        assertEquals("Number of records with 'scientist' field = Darwin on must equal 50 after update", 50, 
+                testCollection.count(new BasicDBObject("scientist", "Darwin")));
+
+    }
+    
+    @Test
+    public void testRemove() throws Exception {
+        // Prepare test
+        assertEquals(0, testCollection.count());
+        for (int i = 1; i <= 100; i++) {
+            String body = null;
+            Formatter f = new Formatter();
+            if (i % 2 == 0) {
+                body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
+            } else {
+                body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i).toString();
+            }
+            template.requestBody("direct:insert", body);
+        }
+        assertEquals(100L, testCollection.count());
+        
+        // Testing the update logic
+        DBObject extraField = new BasicDBObject("extraField", true);
+        assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
+        
+        Object result = template.requestBody("direct:remove", extraField);
+        assertTrue(result instanceof WriteResult);
+        
+        assertEquals("Number of records with 'extraField' flag on must be 0 after remove", 0, 
+                testCollection.count(extraField));
+
+    }
+    
+    @Test
+    public void testDbStats() throws Exception {
+        assertEquals(0, testCollection.count());
+        Object result = template.requestBody("direct:getDbStats", "irrelevantBody");
+        assertTrue("Result is not of type DBObject", result instanceof DBObject);
+        assertTrue("The result should contain keys", ((DBObject) result).keySet().size() > 0);
+    }
+    
+    @Test
+    public void testColStats() throws Exception {
+        assertEquals(0, testCollection.count());
+        
+        // Add some records to the collection (and do it via camel-mongodb)
+        for (int i = 1; i <= 100; i++) {
+            String body = null;
+            Formatter f = new Formatter();
+            body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
+            template.requestBody("direct:insert", body);
+        }
+        
+        Object result = template.requestBody("direct:getColStats", "irrelevantBody");
+        assertTrue("Result is not of type DBObject", result instanceof DBObject);
+        assertTrue("The result should contain keys", ((DBObject) result).keySet().size() > 0);
+    }
+    
+    @Test
+    public void testOperationHeader() throws Exception {
+        // Test that the collection has 0 documents in it
+        assertEquals(0, testCollection.count());
+        
+        // check that the count operation was invoked instead of the insert operation
+        Object result = template.requestBodyAndHeader("direct:insert", "irrelevantBody", MongoDbConstants.OPERATION_HEADER, "count");
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Test collection should not contain any records", 0L, result);
+        
+        
+        // check that the count operation was invoked instead of the insert operation
+        result = template.requestBodyAndHeader("direct:insert", "irrelevantBody", MongoDbConstants.OPERATION_HEADER, MongoDbOperation.count);
+        assertTrue("Result is not of type Long", result instanceof Long);
+        assertEquals("Test collection should not contain any records", 0L, result);
+        
+    }
+    
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/mongodb/mongoComponentTest.xml");
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                
+                PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties");
+                context.addComponent("properties", pc);
+                
+                from("direct:count").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=count&dynamicity=true");
+                from("direct:insert").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=insert");
+                from("direct:save").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=save");
+                from("direct:update").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=update");
+                from("direct:remove").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=remove");
+                from("direct:getDbStats").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=getDbStats");
+                from("direct:getColStats").to("mongodb:myDb?database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=getColStats");
+
+
+            }
+        };
+    }
+}
+

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message