openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csantan...@apache.org
Subject [incubator-openwhisk-package-cloudant] branch master updated: setup step is performed twice in a few tests (#149)
Date Mon, 04 Dec 2017 16:11:08 GMT
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-cloudant.git


The following commit(s) were added to refs/heads/master by this push:
     new 390e031  setup step is performed twice in a few tests (#149)
390e031 is described below

commit 390e031fbd860c58d6c9ecc6268bb5ab62b3bbb7
Author: Jason Peterson <jasonpet@us.ibm.com>
AuthorDate: Mon Dec 4 11:11:06 2017 -0500

    setup step is performed twice in a few tests (#149)
---
 tests/dat/filterdesigndoc.txt                      |   3 +-
 .../system/health/CloudantHealthFeedTests.scala    | 338 ++++++++++-----------
 .../system/packages/CloudantFeedWebTests.scala     |  12 +-
 3 files changed, 176 insertions(+), 177 deletions(-)

diff --git a/tests/dat/filterdesigndoc.txt b/tests/dat/filterdesigndoc.txt
index 5baaece..c62bd45 100644
--- a/tests/dat/filterdesigndoc.txt
+++ b/tests/dat/filterdesigndoc.txt
@@ -1,6 +1,7 @@
 {
   "_id": "_design/test_filter",
     "filters": {
-      "fruit": "function (doc, req) { return doc.kind === 'fruit' || (req && req.query
&& req.query.type === doc.type); }"
+      "fruit": "function (doc, req) { return doc.kind === 'fruit' || (req && req.query
&& req.query.type === doc.type); }",
+      "vegetable": "function (doc, req) { return doc.kind === 'vegetable' || (req &&
req.query && req.query.type === doc.type); }"
     }
 }
diff --git a/tests/src/test/scala/system/health/CloudantHealthFeedTests.scala b/tests/src/test/scala/system/health/CloudantHealthFeedTests.scala
index b75c1dc..c9e3d01 100644
--- a/tests/src/test/scala/system/health/CloudantHealthFeedTests.scala
+++ b/tests/src/test/scala/system/health/CloudantHealthFeedTests.scala
@@ -52,7 +52,7 @@ class CloudantHealthFeedTests
 
     override def beforeEach() = {
         CloudantUtil.setUp(myCloudantCreds)
-        CloudantUtil.createDocument(myCloudantCreds, "{\"_id\":\"testid\"}")
+        CloudantUtil.createDocument(myCloudantCreds, "{\"_id\":\"testid\", \"kind\":\"vegetable\",
\"type\":\"tomato\"}")
     }
 
     override def afterEach() = {
@@ -194,191 +194,189 @@ class CloudantHealthFeedTests
     }
 
     it should "return correct status and configuration" in withAssetCleaner(wskprops) {
-        val currentTime = s"${System.currentTimeMillis}"
-
         (wp, assetHelper) =>
             implicit val wskProps = wp
             val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}"
             val packageName = "dummyCloudantPackage"
             val feed = "changes"
 
-            try {
-                CloudantUtil.setUp(myCloudantCreds)
-
-                // the package alarms should be there
-                val packageGetResult = wsk.pkg.get("/whisk.system/cloudant")
-                println("fetched package cloudant")
-                packageGetResult.stdout should include("ok")
-
-                // create package binding
-                assetHelper.withCleaner(wsk.pkg, packageName) {
-                    (pkg, name) => pkg.bind("/whisk.system/cloudant", name)
-                }
-
-                val username = myCloudantCreds.user
-                val password = myCloudantCreds.password
-                val host = myCloudantCreds.host()
-                val dbName = myCloudantCreds.dbname
-                val port = 443
-                val protocol = "https"
-                val since = "now"
-                val filter = "test_filter/fruit"
-                val queryParams = JsObject("type" -> JsString("tomato"))
-
-                // create whisk stuff
-                val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName,
confirmDelete = false) {
-                    (trigger, name) =>
-                        trigger.create(name, feed = Some(s"$packageName/$feed"), parameters
= Map(
-                            "username" -> username.toJson,
-                            "password" -> password.toJson,
-                            "host" -> host.toJson,
-                            "dbname" -> dbName.toJson,
-                            "filter" -> filter.toJson,
-                            "query_params" -> queryParams,
-                            "protocol" -> protocol.toJson,
-                            "port" -> port.toJson,
-                            "since" -> since.toJson
-                        ))
-                }
-                feedCreationResult.stdout should include("ok")
-
-                val actionName = s"$packageName/$feed"
-                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("username" -> username.toJson)
-                                config should contain("password" -> password.toJson)
-                                config should contain("dbname" -> dbName.toJson)
-                                config should contain("filter" -> filter.toJson)
-                                config should contain("query_params" -> queryParams)
-                                config should contain("protocol" -> protocol.toJson)
-                                config should contain("port" -> port.toJson)
-                                config should contain("since" -> since.toJson)
-                                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")
-                        }
-                }
-            } finally {
-                CloudantUtil.unsetUp(myCloudantCreds)
+            // the package alarms should be there
+            val packageGetResult = wsk.pkg.get("/whisk.system/cloudant")
+            println("fetched package cloudant")
+            packageGetResult.stdout should include("ok")
+
+            // create package binding
+            assetHelper.withCleaner(wsk.pkg, packageName) {
+                (pkg, name) => pkg.bind("/whisk.system/cloudant", name)
             }
+
+            //Create filter design doc
+            val filterDesignDoc = CloudantUtil.createDesignFromFile(CloudantUtil.FILTER_DDOC_PATH).toString
+            val getResponse = CloudantUtil.createDocument(myCloudantCreds, filterDesignDoc)
+            getResponse.get("ok").getAsString shouldBe "true"
+
+            val username = myCloudantCreds.user
+            val password = myCloudantCreds.password
+            val host = myCloudantCreds.host()
+            val dbName = myCloudantCreds.dbname
+            val port = 443
+            val protocol = "https"
+            val since = "0"
+            val filter = "test_filter/fruit"
+            val queryParams = JsObject("type" -> JsString("tomato"))
+
+            // create whisk stuff
+            val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete
= false) {
+                (trigger, name) =>
+                    trigger.create(name, feed = Some(s"$packageName/$feed"), parameters =
Map(
+                        "username" -> username.toJson,
+                        "password" -> password.toJson,
+                        "host" -> host.toJson,
+                        "dbname" -> dbName.toJson,
+                        "filter" -> filter.toJson,
+                        "query_params" -> queryParams,
+                        "protocol" -> protocol.toJson,
+                        "port" -> port.toJson,
+                        "since" -> since.toJson
+                    ))
+            }
+            feedCreationResult.stdout should include("ok")
+
+            val actionName = s"$packageName/$feed"
+            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("username" -> username.toJson)
+                            config should contain("password" -> password.toJson)
+                            config should contain("dbname" -> dbName.toJson)
+                            config should contain("filter" -> filter.toJson)
+                            config should contain("query_params" -> queryParams)
+                            config should contain("protocol" -> protocol.toJson)
+                            config should contain("port" -> port.toJson)
+                            config should contain("since" -> since.toJson)
+                            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 "update filter and query_params parameters" in withAssetCleaner(wskprops) {
-        val currentTime = s"${System.currentTimeMillis}"
-
         (wp, assetHelper) =>
             implicit val wskProps = wp
             val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}"
             val packageName = "dummyCloudantPackage"
             val feed = "changes"
 
-            try {
-                CloudantUtil.setUp(myCloudantCreds)
-
-                // the package alarms should be there
-                val packageGetResult = wsk.pkg.get("/whisk.system/cloudant")
-                println("fetched package cloudant")
-                packageGetResult.stdout should include("ok")
-
-                // create package binding
-                assetHelper.withCleaner(wsk.pkg, packageName) {
-                    (pkg, name) => pkg.bind("/whisk.system/cloudant", name)
-                }
-
-                val username = myCloudantCreds.user
-                val password = myCloudantCreds.password
-                val host = myCloudantCreds.host()
-                val dbName = myCloudantCreds.dbname
-                val filter = "test_filter/fruit"
-                val queryParams = JsObject("type" -> JsString("tomato"))
-
-                // create whisk stuff
-                val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName,
confirmDelete = false) {
-                    (trigger, name) =>
-                        trigger.create(name, feed = Some(s"$packageName/$feed"), parameters
= Map(
-                            "username" -> username.toJson,
-                            "password" -> password.toJson,
-                            "host" -> host.toJson,
-                            "dbname" -> dbName.toJson,
-                            "filter" -> filter.toJson,
-                            "query_params" -> queryParams
-                        ))
-                }
-                feedCreationResult.stdout should include("ok")
-
-                val actionName = s"$packageName/$feed"
-                val readRunResult = wsk.action.invoke(actionName, parameters = Map(
-                    "triggerName" -> triggerName.toJson,
-                    "lifecycleEvent" -> "READ".toJson,
-                    "authKey" -> wskProps.authKey.toJson
-                ))
-
-                withActivation(wsk.activation, readRunResult) {
-                    activation =>
-                        activation.response.success shouldBe true
-
-                        inside(activation.response.result) {
-                            case Some(result) =>
-                                val config = result.getFields("config").head.asInstanceOf[JsObject].fields
-
-                                config should contain("filter" -> filter.toJson)
-                                config should contain("query_params" -> queryParams)
-                        }
-                }
-
-                val updatedFilter = "test_filter/vegetable"
-                val updatedQueryParams = JsObject("type" -> JsString("celery"))
-
-                val updateRunAction = wsk.action.invoke(actionName, parameters = Map(
-                    "triggerName" -> triggerName.toJson,
-                    "lifecycleEvent" -> "UPDATE".toJson,
-                    "authKey" -> wskProps.authKey.toJson,
-                    "filter" -> updatedFilter.toJson,
-                    "query_params" -> updatedQueryParams
-                ))
-
-                withActivation(wsk.activation, updateRunAction) {
-                    activation =>
-                        activation.response.success shouldBe true
-                }
-
-                val runResult = wsk.action.invoke(actionName, parameters = Map(
-                    "triggerName" -> triggerName.toJson,
-                    "lifecycleEvent" -> "READ".toJson,
-                    "authKey" -> wskProps.authKey.toJson
-                ))
-
-                withActivation(wsk.activation, runResult) {
-                    activation =>
-                        activation.response.success shouldBe true
-
-                        inside(activation.response.result) {
-                            case Some(result) =>
-                                val config = result.getFields("config").head.asInstanceOf[JsObject].fields
-
-                                config should contain("filter" -> updatedFilter.toJson)
-                                config should contain("query_params" -> updatedQueryParams)
-                        }
-                }
-            } finally {
-                CloudantUtil.unsetUp(myCloudantCreds)
+            // the package alarms should be there
+            val packageGetResult = wsk.pkg.get("/whisk.system/cloudant")
+            println("fetched package cloudant")
+            packageGetResult.stdout should include("ok")
+
+            // create package binding
+            assetHelper.withCleaner(wsk.pkg, packageName) {
+                (pkg, name) => pkg.bind("/whisk.system/cloudant", name)
+            }
+
+            //Create filter design doc
+            val filterDesignDoc = CloudantUtil.createDesignFromFile(CloudantUtil.FILTER_DDOC_PATH).toString
+            val getResponse = CloudantUtil.createDocument(myCloudantCreds, filterDesignDoc)
+            getResponse.get("ok").getAsString shouldBe "true"
+
+            val username = myCloudantCreds.user
+            val password = myCloudantCreds.password
+            val host = myCloudantCreds.host()
+            val dbName = myCloudantCreds.dbname
+            val filter = "test_filter/fruit"
+            val queryParams = JsObject("type" -> JsString("tomato"))
+
+            // create whisk stuff
+            val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete
= false) {
+                (trigger, name) =>
+                    trigger.create(name, feed = Some(s"$packageName/$feed"), parameters =
Map(
+                        "username" -> username.toJson,
+                        "password" -> password.toJson,
+                        "host" -> host.toJson,
+                        "dbname" -> dbName.toJson,
+                        "filter" -> filter.toJson,
+                        "query_params" -> queryParams,
+                        "since" -> "0".toJson
+                    ))
             }
+            feedCreationResult.stdout should include("ok")
+
+            val actionName = s"$packageName/$feed"
+            val readRunResult = wsk.action.invoke(actionName, parameters = Map(
+                "triggerName" -> triggerName.toJson,
+                "lifecycleEvent" -> "READ".toJson,
+                "authKey" -> wskProps.authKey.toJson
+            ))
+
+            withActivation(wsk.activation, readRunResult) {
+                activation =>
+                    activation.response.success shouldBe true
+
+                    inside(activation.response.result) {
+                        case Some(result) =>
+                            val config = result.getFields("config").head.asInstanceOf[JsObject].fields
+
+                            config should contain("filter" -> filter.toJson)
+                            config should contain("query_params" -> queryParams)
+                    }
+            }
+
+            val updatedFilter = "test_filter/vegetable"
+            val updatedQueryParams = JsObject("type" -> JsString("celery"))
+
+            val updateRunAction = wsk.action.invoke(actionName, parameters = Map(
+                "triggerName" -> triggerName.toJson,
+                "lifecycleEvent" -> "UPDATE".toJson,
+                "authKey" -> wskProps.authKey.toJson,
+                "filter" -> updatedFilter.toJson,
+                "query_params" -> updatedQueryParams
+            ))
+
+            withActivation(wsk.activation, updateRunAction) {
+                activation =>
+                    activation.response.success shouldBe true
+            }
+
+            val runResult = wsk.action.invoke(actionName, parameters = Map(
+                "triggerName" -> triggerName.toJson,
+                "lifecycleEvent" -> "READ".toJson,
+                "authKey" -> wskProps.authKey.toJson
+            ))
+
+            withActivation(wsk.activation, runResult) {
+                activation =>
+                    activation.response.success shouldBe true
+
+                    inside(activation.response.result) {
+                        case Some(result) =>
+                            val config = result.getFields("config").head.asInstanceOf[JsObject].fields
+
+                            config should contain("filter" -> updatedFilter.toJson)
+                            config should contain("query_params" -> updatedQueryParams)
+                    }
+            }
+
     }
 }
diff --git a/tests/src/test/scala/system/packages/CloudantFeedWebTests.scala b/tests/src/test/scala/system/packages/CloudantFeedWebTests.scala
index b1dc009..63dc28c 100644
--- a/tests/src/test/scala/system/packages/CloudantFeedWebTests.scala
+++ b/tests/src/test/scala/system/packages/CloudantFeedWebTests.scala
@@ -55,37 +55,37 @@ class CloudantFeedWebTests
         wsk.action.get(webAction, FORBIDDEN)
     }
 
-    it should "reject put of a trigger due to missing triggerName argument" in {
+    it should "reject post of a trigger due to missing triggerName argument" in {
         val params = JsObject(requiredParams.fields - "triggerName")
 
         makePostCallWithExpectedResult(params, JsObject("error" -> JsString("no trigger
name parameter was provided")), 400)
     }
 
-    it should "reject put of a trigger due to missing host argument" in {
+    it should "reject post of a trigger due to missing host argument" in {
         val params = JsObject(requiredParams.fields - "host")
 
         makePostCallWithExpectedResult(params, JsObject("error" -> JsString("cloudant
trigger feed: missing host parameter")), 400)
     }
 
-    it should "reject put of a trigger due to missing username argument" in {
+    it should "reject post of a trigger due to missing username argument" in {
         val params = JsObject(requiredParams.fields - "username")
 
         makePostCallWithExpectedResult(params, JsObject("error" -> JsString("cloudant
trigger feed: missing username parameter")), 400)
     }
 
-    it should "reject put of a trigger due to missing password argument" in {
+    it should "reject post of a trigger due to missing password argument" in {
         val params = JsObject(requiredParams.fields - "password")
 
         makePostCallWithExpectedResult(params, JsObject("error" -> JsString("cloudant
trigger feed: missing password parameter")), 400)
     }
 
-    it should "reject put of a trigger due to missing dbname argument" in {
+    it should "reject post of a trigger due to missing dbname argument" in {
         val params = JsObject(requiredParams.fields - "dbname")
 
         makePostCallWithExpectedResult(params, JsObject("error" -> JsString("cloudant
trigger feed: missing dbname parameter")), 400)
     }
 
-    it should "reject put of a trigger when authentication fails" in {
+    it should "reject post of a trigger when authentication fails" in {
 
         makePostCallWithExpectedResult(requiredParams, JsObject("error" -> JsString("Trigger
authentication request failed.")), 401)
     }

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

Mime
View raw message