adding test case for writing a new document when overwrite=true (#156)
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 @@
}
}
- 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 @@
}
}
+ 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