Add new discrete resource, test method to parse Maybe's
authorGeorgios Gousios <gousiosg@gmail.com>
Mon, 9 Jan 2012 12:25:02 +0000 (14:25 +0200)
committerGeorgios Gousios <gousiosg@gmail.com>
Mon, 9 Jan 2012 12:44:28 +0000 (14:44 +0200)
src/test/resources/policy.yaml
src/test/scala/gr/grnet/aquarium/logic/test/DSLTest.scala
src/test/scala/gr/grnet/aquarium/util/TestMethods.scala

index c920d61..3b276cc 100644 (file)
@@ -21,6 +21,11 @@ aquariumpolicy:
       unit: MB/hr
       complex: false
       costpolicy: continuous
+    - resource:
+      name: bookpages
+      unit: pages
+      complex: false
+      costpolicy: discrete
 
   implicitvars:
     - price
@@ -33,6 +38,7 @@ aquariumpolicy:
       bandwidthdown: $price times $volume
       vmtime: $price times $volume
       diskspace: $price times $volume
+      bookpages: $price times $volume
       effective:
         from: 0
     - algorithm:
@@ -55,6 +61,7 @@ aquariumpolicy:
       bandwidthdown: 0.02
       vmtime: 0.1
       diskspace: 0.05
+      bookpages: 0.1
       effective:
         from: 0
     - pricelist: 
index b0c842b..cafb859 100644 (file)
@@ -82,7 +82,7 @@ class DSLTest extends DSLTestBase with TestMethods {
   @Test
   def testParseResources = {
     before
-    assertEquals(4, dsl.resources.size)
+    assertEquals(5, dsl.resources.size)
     assertNotNone(dsl.findResource("vmtime"))
     assertTrue(dsl.findResource("vmtime").get.isInstanceOf[DSLComplexResource])
     assertEquals("vmid", dsl.findResource("vmtime").get.asInstanceOf[DSLComplexResource].descriminatorField)
index 1a437cf..2be8794 100644 (file)
@@ -36,6 +36,7 @@ package gr.grnet.aquarium.util
  */
 
 import org.junit.Assert.fail
+import com.ckkloverdos.maybe.{NoVal, Just, Maybe, Failed}
 
 /**
  * Some common Scala-related asserts
@@ -69,4 +70,15 @@ trait TestMethods {
     case x if x <= 0 => fail()
     case _ =>
   }
+  
+  def assertFailed[A <: Throwable, B <: Any](f: => Maybe[B])
+                                  (implicit m: ClassManifest[A]): Unit = {
+    f match {
+      case Failed(e,r) if (m.erasure.isAssignableFrom(e.getClass)) => return
+      case Failed(e,r) => fail("Expected exception of type " + m.erasure.getName +
+        " not thrown. Instead, " + e.getClass.getName + " was thrown")
+      case NoVal => fail("Operation not failed")
+      case Just(x) => fail("Operation not failed")
+    }
+  }
 }
\ No newline at end of file