You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2017/11/16 17:25:17 UTC

[incubator-openwhisk-package-alarms] branch master updated: move positive trigger get test to health class (#111)

This is an automated email from the ASF dual-hosted git repository.

csantanapr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-alarms.git


The following commit(s) were added to refs/heads/master by this push:
     new 4f41b89  move positive trigger get test to health class (#111)
4f41b89 is described below

commit 4f41b89da323a0df017b505e12057b4866339a76
Author: Adnan Baruni <ab...@users.noreply.github.com>
AuthorDate: Thu Nov 16 11:25:15 2017 -0600

    move positive trigger get test to health class (#111)
---
 .../system/health/AlarmsHealthFeedTests.scala      | 69 +++++++++++++++++++++-
 .../scala/system/packages/AlarmsFeedTests.scala    | 69 +---------------------
 2 files changed, 68 insertions(+), 70 deletions(-)

diff --git a/tests/src/test/scala/system/health/AlarmsHealthFeedTests.scala b/tests/src/test/scala/system/health/AlarmsHealthFeedTests.scala
index 55069f1..fe70822 100644
--- a/tests/src/test/scala/system/health/AlarmsHealthFeedTests.scala
+++ b/tests/src/test/scala/system/health/AlarmsHealthFeedTests.scala
@@ -20,10 +20,10 @@ import java.time.{Clock, Instant}
 
 import common.{TestHelpers, Wsk, WskProps, WskTestHelpers}
 import org.junit.runner.RunWith
-import org.scalatest.FlatSpec
+import org.scalatest.{FlatSpec, Inside}
 import org.scalatest.junit.JUnitRunner
-import spray.json.DefaultJsonProtocol.{LongJsonFormat, StringJsonFormat}
-import spray.json.pimpAny
+import spray.json.DefaultJsonProtocol.{LongJsonFormat, StringJsonFormat, BooleanJsonFormat}
+import spray.json.{JsObject, JsString, pimpAny}
 
 /**
  * Tests for alarms trigger service
@@ -32,6 +32,7 @@ import spray.json.pimpAny
 class AlarmsHealthFeedTests
     extends FlatSpec
     with TestHelpers
+    with Inside
     with WskTestHelpers {
 
     val wskprops = WskProps()
@@ -123,4 +124,66 @@ class AlarmsHealthFeedTests
             activations should be(1)
     }
 
+    it should "return correct status and configuration" in withAssetCleaner(wskprops) {
+        val currentTime = s"${System.currentTimeMillis}"
+
+        (wp, assetHelper) =>
+            implicit val wskProps = wp
+            val triggerName = s"dummyAlarmsTrigger-${System.currentTimeMillis}"
+            val packageName = "dummyAlarmsPackage"
+
+            // the package alarms should be there
+            val packageGetResult = wsk.pkg.get("/whisk.system/alarms")
+            println("fetched package alarms")
+            packageGetResult.stdout should include("ok")
+
+            // create package binding
+            assetHelper.withCleaner(wsk.pkg, packageName) {
+                (pkg, name) => pkg.bind("/whisk.system/alarms", name)
+            }
+
+            val triggerPayload = JsObject(
+                "test" -> JsString("alarmsTest")
+            )
+            val cronString = "* * * * * *"
+            val maxTriggers = -1
+
+            // create whisk stuff
+            val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName) {
+                (trigger, name) =>
+                    trigger.create(name, feed = Some(s"$packageName/alarm"), parameters = Map(
+                        "trigger_payload" -> triggerPayload,
+                        "cron" -> cronString.toJson))
+            }
+            feedCreationResult.stdout should include("ok")
+
+            val actionName = s"$packageName/alarm"
+            val run = wsk.action.invoke(actionName, parameters = Map(
+                "triggerName" -> triggerName.toJson,
+                "lifecycleEvent" -> "READ".toJson,
+                "authKey" -> wskProps.authKey.toJson
+            ))
+
+            withActivation(wsk.activation, run) {
+                activation =>
+                    activation.response.success shouldBe true
+
+                    inside (activation.response.result) {
+                        case Some(result) =>
+                            val config = result.getFields("config").head.asInstanceOf[JsObject].fields
+                            val status = result.getFields("status").head.asInstanceOf[JsObject].fields
+
+                            config should contain("name" -> triggerName.toJson)
+                            config should contain("cron" -> cronString.toJson)
+                            config should contain("payload" -> triggerPayload)
+                            config should contain key "namespace"
+
+                            status should contain("active" -> true.toJson)
+                            status should contain key "dateChanged"
+                            status should contain key "dateChangedISO"
+                            status should not(contain key "reason")
+                    }
+            }
+
+    }
 }
diff --git a/tests/src/test/scala/system/packages/AlarmsFeedTests.scala b/tests/src/test/scala/system/packages/AlarmsFeedTests.scala
index f430270..45ec618 100644
--- a/tests/src/test/scala/system/packages/AlarmsFeedTests.scala
+++ b/tests/src/test/scala/system/packages/AlarmsFeedTests.scala
@@ -17,7 +17,7 @@
 package system.packages
 
 import org.junit.runner.RunWith
-import org.scalatest.{FlatSpec, Inside}
+import org.scalatest.FlatSpec
 import org.scalatest.junit.JUnitRunner
 import common.TestHelpers
 import common.Wsk
@@ -25,8 +25,7 @@ import common.WskProps
 import common.WskTestHelpers
 import spray.json.DefaultJsonProtocol.IntJsonFormat
 import spray.json.DefaultJsonProtocol.{LongJsonFormat, StringJsonFormat}
-import spray.json.DefaultJsonProtocol.BooleanJsonFormat
-import spray.json.{JsObject, JsString, pimpAny}
+import spray.json.pimpAny
 
 /**
  * Tests for alarms trigger service
@@ -34,7 +33,6 @@ import spray.json.{JsObject, JsString, pimpAny}
 @RunWith(classOf[JUnitRunner])
 class AlarmsFeedTests
     extends FlatSpec
-    with Inside
     with TestHelpers
     with WskTestHelpers {
 
@@ -75,69 +73,6 @@ class AlarmsFeedTests
         activations should be(3)
     }
 
-    it should "return correct status and configuration" in withAssetCleaner(wskprops) {
-        val currentTime = s"${System.currentTimeMillis}"
-
-        (wp, assetHelper) =>
-            implicit val wskProps = wp
-            val triggerName = s"dummyAlarmsTrigger-${System.currentTimeMillis}"
-            val packageName = "dummyAlarmsPackage"
-
-            // the package alarms should be there
-            val packageGetResult = wsk.pkg.get("/whisk.system/alarms")
-            println("fetched package alarms")
-            packageGetResult.stdout should include("ok")
-
-            // create package binding
-            assetHelper.withCleaner(wsk.pkg, packageName) {
-                (pkg, name) => pkg.bind("/whisk.system/alarms", name)
-            }
-
-            val triggerPayload = JsObject(
-                "test" -> JsString("alarmsTest")
-            )
-            val cronString = "* * * * * *"
-            val maxTriggers = -1
-
-            // create whisk stuff
-            val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName) {
-                (trigger, name) =>
-                    trigger.create(name, feed = Some(s"$packageName/alarm"), parameters = Map(
-                        "trigger_payload" -> triggerPayload,
-                        "cron" -> cronString.toJson))
-            }
-            feedCreationResult.stdout should include("ok")
-
-            val actionName = s"$packageName/alarm"
-            val run = wsk.action.invoke(actionName, parameters = Map(
-                "triggerName" -> triggerName.toJson,
-                "lifecycleEvent" -> "READ".toJson,
-                "authKey" -> wskProps.authKey.toJson
-            ))
-
-            withActivation(wsk.activation, run) {
-                activation =>
-                    activation.response.success shouldBe true
-
-                    inside (activation.response.result) {
-                        case Some(result) =>
-                            val config = result.getFields("config").head.asInstanceOf[JsObject].fields
-                            val status = result.getFields("status").head.asInstanceOf[JsObject].fields
-
-                            config should contain("name" -> triggerName.toJson)
-                            config should contain("cron" -> cronString.toJson)
-                            config should contain("payload" -> triggerPayload)
-                            config should contain key "namespace"
-
-                            status should contain("active" -> true.toJson)
-                            status should contain key "dateChanged"
-                            status should contain key "dateChangedISO"
-                            status should not(contain key "reason")
-                    }
-            }
-
-    }
-
     it should "return error message when alarm action does not include cron parameter" in withAssetCleaner(wskprops) {
 
         (wp, assetHelper) =>

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].