Make the mongodb test grab the needed configuration from runtime system property
authorChristos KK Loverdos <loverdos@gmail.com>
Thu, 24 Nov 2011 10:08:46 +0000 (12:08 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Thu, 24 Nov 2011 10:08:57 +0000 (12:08 +0200)
logic/src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBConnection.scala
logic/src/test/resources/mongodb/aquarium-message-store.xml [new file with mode: 0644]
logic/src/test/resources/mongodb/local-message-store.xml
logic/src/test/scala/gr/grnet/aquarium/LogicTestsAssumptions.scala
logic/src/test/scala/gr/grnet/aquarium/PropertyNames.scala [new file with mode: 0644]
logic/src/test/scala/gr/grnet/aquarium/store/mongodb/MongoDBStoreTest.scala

index cb9c731..8267fbb 100644 (file)
@@ -52,7 +52,7 @@ class MongoDBConnection(val confModel: MongoDBConfigurationModel) extends Loggab
     val serverAddresses = hosts.map(sacm => new ServerAddress(sacm.host, sacm.port))
 
     val mongo = MongoConnection(serverAddresses)
-    logger.info("Created MongoDB connection %s".format(mongo))
+    logger.info("Created MongoDB connection %s for hosts %s".format(mongo, confModel.hosts.map(h => "%s:%s".format(h.host, h.port)).mkString(", ")))
 
     if(confModel.slaveOK) {
       mongo.slaveOk()
@@ -73,6 +73,7 @@ object MongoDBConnection {
 
   object PropFiles {
     val local_message_store = "local-message-store.xml"
+    val aquarium_message_store = "aquarium-message-store.xml"
   }
   
   object DBNames {
diff --git a/logic/src/test/resources/mongodb/aquarium-message-store.xml b/logic/src/test/resources/mongodb/aquarium-message-store.xml
new file mode 100644 (file)
index 0000000..a50a83a
--- /dev/null
@@ -0,0 +1,10 @@
+<MongoDBConfigurationModel>
+  <slaveOK>true</slaveOK>
+  <writeConcern>SAFE</writeConcern>
+  <hosts class="List">
+    <ServerAddressConfigurationModel>
+      <host>aquarium.dev.grnet.gr</host>
+      <port>27017</port>
+    </ServerAddressConfigurationModel>
+  </hosts>
+</MongoDBConfigurationModel>
index a50a83a..c4875fd 100644 (file)
@@ -3,7 +3,7 @@
   <writeConcern>SAFE</writeConcern>
   <hosts class="List">
     <ServerAddressConfigurationModel>
-      <host>aquarium.dev.grnet.gr</host>
+      <host>localhost</host>
       <port>27017</port>
     </ServerAddressConfigurationModel>
   </hosts>
index dab9c9c..a8c0368 100644 (file)
@@ -62,6 +62,6 @@ object LogicTestsAssumptions {
 
   private def testPropertyFalse(name: String): Boolean = !testPropertyTrue(name)
 
-  val EnableRabbitMQTests = testPropertyFalse("test.skip.rabbitmq")
-  val EnableMongoDBTests  = testPropertyFalse("test.skip.mongodb")
+  val EnableRabbitMQTests = testPropertyFalse(PropertyNames.TestSkipRabbitMQ)
+  val EnableMongoDBTests  = testPropertyFalse(PropertyNames.TestSkipMongoDB)
 }
\ No newline at end of file
diff --git a/logic/src/test/scala/gr/grnet/aquarium/PropertyNames.scala b/logic/src/test/scala/gr/grnet/aquarium/PropertyNames.scala
new file mode 100644 (file)
index 0000000..714f432
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium
+
+/**
+ * Test-related proeprty names.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+object PropertyNames {
+  // Test enabling/disabling
+  val TestSkipRabbitMQ = "test.skip.rabbitmq"
+  val TestSkipMongoDB = "test.skip.mongodb"
+
+  // Test configuration files used
+  val MongoDBLocalStoreConf = "mongodb.store.conf"
+}
\ No newline at end of file
index 1b2db4b..20eecdc 100644 (file)
@@ -46,16 +46,24 @@ import com.ckkloverdos.resource.DefaultResourceContext
 import MongoDBConnection.{RCFolders, PropFiles, DBNames, CollectionNames}
 import gr.grnet.aquarium.util.xstream.XStreamHelpers
 import com.mongodb.casbah.commons.MongoDBObject
+import com.ckkloverdos.sys.SysProp
+import util.Loggable
 
 /**
  * 
  * @author Christos KK Loverdos <loverdos@gmail.com>.
  */
-class MongoDBStoreTest {
+class MongoDBStoreTest extends Loggable {
   val baseRC = DefaultResourceContext
   val mongodbRC = baseRC / RCFolders.mongodb
   val xs = XStreamHelpers.newXStream
 
+  lazy val MongoDBPropFile = {
+    val filename = SysProp(PropertyNames.MongoDBLocalStoreConf).value.getOr(PropFiles.local_message_store)
+    logger.debug("Using mongodb configuration from %s".format(filename))
+    filename
+  }
+
   private def _getTestConf: String = {
     val address1 = ServerAddressConfigurationModel("aquarium.dev.grnet.gr", 27017)
     val model = new MongoDBConfigurationModel(List(address1), true, "SAFE")
@@ -65,7 +73,7 @@ class MongoDBStoreTest {
 
   @Test
   def testConfigurationExists: Unit = {
-    assertTrue(mongodbRC.getLocalResource(PropFiles.local_message_store).isJust)
+    assertTrue(mongodbRC.getLocalResource(MongoDBPropFile).isJust)
   }
 
   @Test
@@ -73,19 +81,19 @@ class MongoDBStoreTest {
     assumeTrue(LogicTestsAssumptions.EnableMongoDBTests)
 
     for {
-      confResource <- mongodbRC.getLocalResource(PropFiles.local_message_store)
+      confResource <- mongodbRC.getLocalResource(MongoDBPropFile)
     } {
       val xs = XStreamHelpers.newXStream
+      logger.debug("Reading mongodb configuration from %s".format(confResource.url))
+      logger.debug("mongodb configuration is:\n%s".format(confResource.stringContent.getOr("")))
       val maybeModel = XStreamHelpers.parseType[MongoDBConfigurationModel](confResource, xs)
       assertTrue(maybeModel.isJust)
+      val obj = MongoDBObject("1" -> "one", "2" -> "two")
+      logger.debug("Inserting %s into mongodb".format(obj))
       for(model <- maybeModel) {
         val mongo = new MongoDBConnection(model)
-        println(mongo._mongoConnection)
-        println(mongo._mongoConnection.getAllAddress())
-        println(mongo._mongoConnection.getConnectPoint())
         val db = mongo._mongoConnection(DBNames.test)
         val collection = db.apply(CollectionNames.test)
-        val obj = MongoDBObject("1" -> "one", "2" -> "two")
         collection.insert(obj)
       }
     }