You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/02/07 14:14:40 UTC

[incubator-openwhisk-package-cloudant] branch master updated: adding test case for writing a new document when overwrite=true (#156)

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

rabbah 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 8ebb707  adding test case for writing a new document when overwrite=true (#156)
8ebb707 is described below

commit 8ebb707c9751bb10f0441816d0177e11ce692e1c
Author: Jason Peterson <ja...@us.ibm.com>
AuthorDate: Wed Feb 7 09:14:38 2018 -0500

    adding test case for writing a new document when overwrite=true (#156)
---
 .../packages/CloudantDatabaseActionsTests.scala    | 43 +++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/tests/src/test/scala/system/packages/CloudantDatabaseActionsTests.scala b/tests/src/test/scala/system/packages/CloudantDatabaseActionsTests.scala
index a7731ed..145250f 100644
--- a/tests/src/test/scala/system/packages/CloudantDatabaseActionsTests.scala
+++ b/tests/src/test/scala/system/packages/CloudantDatabaseActionsTests.scala
@@ -242,7 +242,7 @@ class CloudantDatabaseActionsTests extends FlatSpec
             }
     }
 
-    it should """write cloudant document with overwrite""" in withAssetCleaner(wskprops) {
+    it should """write existing cloudant document with overwrite""" in withAssetCleaner(wskprops) {
         (wp, assetHelper) =>
             implicit val wskprops = wp
             val packageName = "dummyCloudantPackage"
@@ -287,6 +287,47 @@ class CloudantDatabaseActionsTests extends FlatSpec
             }
     }
 
+    it should """write new cloudant document with overwrite""" in withAssetCleaner(wskprops) {
+        (wp, assetHelper) =>
+            implicit val wskprops = wp
+            val packageName = "dummyCloudantPackage"
+
+            try {
+                CloudantUtil.setUp(credential)
+
+                val packageGetResult = wsk.pkg.get("/whisk.system/cloudant")
+                println("Fetching cloudant package.")
+                packageGetResult.stdout should include("ok")
+
+                println("Creating cloudant package binding.")
+                assetHelper.withCleaner(wsk.pkg, packageName) {
+                    (pkg, name) =>
+                        pkg.bind("/whisk.system/cloudant", name,
+                            Map("username" -> credential.user.toJson,
+                                "password" -> credential.password.toJson,
+                                "host" -> credential.host().toJson,
+                                "dbname" -> credential.dbname.toJson))
+                }
+
+                val doc = CloudantUtil.createDocParameterForWhisk().get("doc").getAsString
+                val docJSObj = doc.parseJson.asJsObject
+
+                println("Invoking the write action.")
+                withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/write",
+                    Map("doc" -> docJSObj,
+                        "overwrite" -> "true".toJson))) {
+                    activation =>
+                        activation.response.success shouldBe true
+                        activation.response.result.get.fields.get("id") shouldBe defined
+                }
+                val getResponse = CloudantUtil.getDocument(credential, "testId")
+                Some(JsString(getResponse.get("date").getAsString)) shouldBe docJSObj.fields.get("date")
+            }
+            finally {
+                CloudantUtil.unsetUp(credential)
+            }
+    }
+
     it should """update cloudant document""" in withAssetCleaner(wskprops) {
         (wp, assetHelper) =>
             implicit val wskprops = wp

-- 
To stop receiving notification emails like this one, please contact
rabbah@apache.org.