Implement property-based infrastructure to run tests conditionally
authorChristos KK Loverdos <loverdos@gmail.com>
Wed, 23 Nov 2011 10:10:25 +0000 (12:10 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Wed, 23 Nov 2011 10:10:47 +0000 (12:10 +0200)
logic/src/test/scala/gr/grnet/aquarium/LogicTestsAssumptions.scala [new file with mode: 0644]
logic/src/test/scala/gr/grnet/aquarium/messaging/MessagingTest.scala
logic/src/test/scala/gr/grnet/aquarium/store/mongodb/MongoDBStoreTest.scala

diff --git a/logic/src/test/scala/gr/grnet/aquarium/LogicTestsAssumptions.scala b/logic/src/test/scala/gr/grnet/aquarium/LogicTestsAssumptions.scala
new file mode 100644 (file)
index 0000000..dab9c9c
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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
+
+import com.ckkloverdos.sys.SysProp
+import com.ckkloverdos.maybe.Just
+import com.ckkloverdos.props.Props
+import com.ckkloverdos.convert.Converters
+
+/**
+ * These are used to enable/disable several tests based on system properties.
+ *
+ * Very handy when a test is based upon an external system which sometimes we may not control.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+object LogicTestsAssumptions {
+  private def testPropertyTrue(name: String): Boolean = {
+    implicit val converters = Converters.DefaultConverters
+    SysProp(name).value match {
+      case Just(value) =>
+        Props((name, value)).getBoolean(name) match {
+          case Just(flag) => flag
+          case _ => false
+        }
+      case _ => false
+    }
+  }
+
+  private def testPropertyFalse(name: String): Boolean = !testPropertyTrue(name)
+
+  val EnableRabbitMQTests = testPropertyFalse("test.skip.rabbitmq")
+  val EnableMongoDBTests  = testPropertyFalse("test.skip.mongodb")
+}
\ No newline at end of file
index df10f04..722c672 100644 (file)
@@ -46,6 +46,8 @@ import gr.grnet.aquarium.util.xstream.XStreamHelpers
 import gr.grnet.aquarium.util.Loggable
 import com.ckkloverdos.props.Props
 import com.ckkloverdos.maybe.{Failed, NoVal, Just}
 import gr.grnet.aquarium.util.Loggable
 import com.ckkloverdos.props.Props
 import com.ckkloverdos.maybe.{Failed, NoVal, Just}
+import org.junit.Assume._
+import gr.grnet.aquarium.LogicTestsAssumptions
 
 /**
  * 
 
 /**
  * 
@@ -105,6 +107,8 @@ class MessagingTest extends Loggable {
 
   @Test
   def testLocalProducer {
 
   @Test
   def testLocalProducer {
+    assumeTrue(LogicTestsAssumptions.EnableRabbitMQTests)
+
     val maybeConfs = RabbitMQConfigurations(baseRC)
     assertTrue(maybeConfs.isJust)
     val maybeProducer = for {
     val maybeConfs = RabbitMQConfigurations(baseRC)
     assertTrue(maybeConfs.isJust)
     val maybeProducer = for {
@@ -129,6 +133,8 @@ class MessagingTest extends Loggable {
 
   @Test
   def testLocalConsumer {
 
   @Test
   def testLocalConsumer {
+    assumeTrue(LogicTestsAssumptions.EnableRabbitMQTests)
+
     val maybeConfs = RabbitMQConfigurations(baseRC)
     assertTrue(maybeConfs.isJust)
 
     val maybeConfs = RabbitMQConfigurations(baseRC)
     assertTrue(maybeConfs.isJust)
 
index 5f31646..1b2db4b 100644 (file)
  * or implied, of GRNET S.A.
  */
 
  * or implied, of GRNET S.A.
  */
 
-package gr.grnet.aquarium.store
+package gr.grnet.aquarium
+package store
 package mongodb
 
 import confmodel.{ServerAddressConfigurationModel, MongoDBConfigurationModel}
 import org.junit.Test
 import org.junit.Assert._
 package mongodb
 
 import confmodel.{ServerAddressConfigurationModel, MongoDBConfigurationModel}
 import org.junit.Test
 import org.junit.Assert._
+import org.junit.Assume.assumeTrue
 
 import com.ckkloverdos.resource.DefaultResourceContext
 import MongoDBConnection.{RCFolders, PropFiles, DBNames, CollectionNames}
 
 import com.ckkloverdos.resource.DefaultResourceContext
 import MongoDBConnection.{RCFolders, PropFiles, DBNames, CollectionNames}
@@ -68,6 +70,8 @@ class MongoDBStoreTest {
 
   @Test
   def testConnection: Unit = {
 
   @Test
   def testConnection: Unit = {
+    assumeTrue(LogicTestsAssumptions.EnableMongoDBTests)
+
     for {
       confResource <- mongodbRC.getLocalResource(PropFiles.local_message_store)
     } {
     for {
       confResource <- mongodbRC.getLocalResource(PropFiles.local_message_store)
     } {