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:26:36 UTC

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

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-kafka.git


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

commit 66f55a41506c43534ac8f8ca63d1cca8d64cd513
Author: Adnan Baruni <ab...@users.noreply.github.com>
AuthorDate: Thu Nov 16 11:26:35 2017 -0600

    move positive trigger get test to health class (#226)
---
 .../test/scala/system/health/BasicHealthTest.scala | 83 +++++++++++++++++++---
 .../system/packages/MessageHubFeedTests.scala      | 61 ----------------
 2 files changed, 75 insertions(+), 69 deletions(-)

diff --git a/tests/src/test/scala/system/health/BasicHealthTest.scala b/tests/src/test/scala/system/health/BasicHealthTest.scala
index 7443527..3db6bd8 100644
--- a/tests/src/test/scala/system/health/BasicHealthTest.scala
+++ b/tests/src/test/scala/system/health/BasicHealthTest.scala
@@ -24,13 +24,9 @@ import system.utils.KafkaUtils
 
 import scala.concurrent.duration.DurationInt
 import scala.language.postfixOps
-
 import org.junit.runner.RunWith
-import org.scalatest.BeforeAndAfterAll
-import org.scalatest.FlatSpec
-import org.scalatest.Matchers
+import org.scalatest.{BeforeAndAfterAll, FlatSpec, Inside, Matchers}
 import org.scalatest.junit.JUnitRunner
-
 import common.JsHelpers
 import common.TestHelpers
 import common.TestUtils.DONTCARE_EXIT
@@ -41,10 +37,8 @@ import common.WskActorSystem
 import common.WskProps
 import common.WskTestHelpers
 import spray.json.DefaultJsonProtocol._
-import spray.json.pimpAny
-
+import spray.json.{JsObject, pimpAny}
 import com.jayway.restassured.RestAssured
-
 import whisk.utils.retry;
 
 @RunWith(classOf[JUnitRunner])
@@ -55,6 +49,7 @@ class BasicHealthTest
   with BeforeAndAfterAll
   with TestHelpers
   with WskTestHelpers
+  with Inside
   with JsHelpers {
 
   val topic = "test"
@@ -189,4 +184,76 @@ class BasicHealthTest
         message.getFieldPath("key") shouldBe Some(key.toJson)
       }, N = 3)
   }
+
+  it should "return correct status and configuration" in withAssetCleaner(wskprops) {
+    val currentTime = s"${System.currentTimeMillis}"
+
+    (wp, assetHelper) =>
+      val messagingPackage = "/whisk.system/messaging"
+      val messageHubFeed = "messageHubFeed"
+      val actionName = s"${messagingPackage}/${messageHubFeed}"
+      val triggerName = s"/_/dummyMessageHubTrigger-$currentTime"
+      println(s"Creating trigger ${triggerName}")
+
+      val username = kafkaUtils.getAsJson("user")
+      val password = kafkaUtils.getAsJson("password")
+      val admin_url = kafkaUtils.getAsJson("kafka_admin_url")
+      val brokers = kafkaUtils.getAsJson("brokers")
+
+      val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName) {
+        (trigger, _) =>
+          trigger.create(triggerName, feed = Some(actionName), parameters = Map(
+            "user" -> username,
+            "password" -> password,
+            "api_key" -> kafkaUtils.getAsJson("api_key"),
+            "kafka_admin_url" -> admin_url,
+            "kafka_brokers_sasl" -> brokers,
+            "topic" -> topic.toJson,
+            "isBinaryKey" -> false.toJson,
+            "isBinaryValue" -> false.toJson
+          ))
+      }
+
+      withActivation(wsk.activation, feedCreationResult, initialWait = 5 seconds, totalWait = 60 seconds) {
+        activation =>
+          // should be successful
+          activation.response.success shouldBe true
+      }
+
+      val run = wsk.action.invoke(actionName, parameters = Map(
+        "triggerName" -> triggerName.toJson,
+        "lifecycleEvent" -> "READ".toJson,
+        "authKey" -> wp.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("kafka_brokers_sasl" -> brokers)
+              config should contain("isBinaryKey" -> false.toJson)
+              config should contain("isBinaryValue" -> false.toJson)
+              config should contain("isJSONData" -> false.toJson)
+              config should contain("kafka_admin_url" -> admin_url)
+              config should contain("password" -> password)
+              config should contain("topic" -> topic.toJson)
+              config should contain("user" -> username)
+              config("triggerName").convertTo[String].split("/").last should equal (triggerName.split("/").last)
+              config should not {
+                contain key "authKey"
+                contain key "triggerURL"
+                contain key "uuid"
+                contain key "worker"
+              }
+              status should contain("active" -> true.toJson)
+              status should contain key "dateChanged"
+              status should not(contain key "reason")
+          }
+      }
+  }
 }
diff --git a/tests/src/test/scala/system/packages/MessageHubFeedTests.scala b/tests/src/test/scala/system/packages/MessageHubFeedTests.scala
index 279772b..d3ab84a 100644
--- a/tests/src/test/scala/system/packages/MessageHubFeedTests.scala
+++ b/tests/src/test/scala/system/packages/MessageHubFeedTests.scala
@@ -274,67 +274,6 @@ class MessageHubFeedTests
       assert(matchingActivations.length == 0)
   }
 
-  it should "return correct status and configuration" in withAssetCleaner(wskprops) {
-    val currentTime = s"${System.currentTimeMillis}"
-
-    (wp, assetHelper) =>
-      val triggerName = s"/_/dummyMessageHubTrigger-$currentTime"
-      println(s"Creating trigger ${triggerName}")
-
-      val username = kafkaUtils.getAsJson("user")
-      val password = kafkaUtils.getAsJson("password")
-      val admin_url = kafkaUtils.getAsJson("kafka_admin_url")
-      val brokers = kafkaUtils.getAsJson("brokers")
-
-      createTrigger(assetHelper, triggerName, parameters = Map(
-        "user" -> username,
-        "password" -> password,
-        "api_key" -> kafkaUtils.getAsJson("api_key"),
-        "kafka_admin_url" -> admin_url,
-        "kafka_brokers_sasl" -> brokers,
-        "topic" -> topic.toJson,
-        "isBinaryKey" -> false.toJson,
-        "isBinaryValue" -> false.toJson
-      ))
-
-      val run = wsk.action.invoke(actionName, parameters = Map(
-        "triggerName" -> triggerName.toJson,
-        "lifecycleEvent" -> "READ".toJson,
-        "authKey" -> wp.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("brokers" -> brokers)
-              config should contain("isBinaryKey" -> false.toJson)
-              config should contain("isBinaryValue" -> false.toJson)
-              config should contain("isJSONData" -> false.toJson)
-              config should contain("isMessageHub" -> true.toJson)
-              config should contain("kafka_admin_url" -> admin_url)
-              config should contain("password" -> password)
-              config should contain("topic" -> topic.toJson)
-              config should contain("username" -> username)
-              config("triggerName").convertTo[String].split("/").last should equal (triggerName.split("/").last)
-              config should not {
-                contain key "authKey"
-                contain key "triggerURL"
-                contain key "uuid"
-                contain key "worker"
-              }
-              status should contain("active" -> true.toJson)
-              status should contain key "dateChanged"
-              status should not(contain key "reason")
-          }
-      }
-  }
-
   def createTrigger(assetHelper: AssetCleaner, name: String, parameters: Map[String, spray.json.JsValue]) = {
     val feedCreationResult = assetHelper.withCleaner(wsk.trigger, name) {
       (trigger, _) =>

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