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

[GitHub] csantanapr closed pull request #111: move positive trigger get test to health class

csantanapr closed pull request #111: move positive trigger get test to health class
URL: https://github.com/apache/incubator-openwhisk-package-alarms/pull/111
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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) =>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services