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

dubeejw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 33b90e5  Add test for content-type with empty entity. (#2765)
33b90e5 is described below

commit 33b90e574da3a84ee21981b0538718954e00d52e
Author: rodric rabbah <rod...@gmail.com>
AuthorDate: Mon Sep 18 16:19:10 2017 -0400

    Add test for content-type with empty entity. (#2765)
---
 .../scala/whisk/core/controller/WebActions.scala   | 10 ++++++---
 .../core/controller/test/WebActionsApiTests.scala  | 25 +++++++++++++++++++++-
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git 
a/core/controller/src/main/scala/whisk/core/controller/WebActions.scala 
b/core/controller/src/main/scala/whisk/core/controller/WebActions.scala
index ee598fe1..9544ef0 100644
--- a/core/controller/src/main/scala/whisk/core/controller/WebActions.scala
+++ b/core/controller/src/main/scala/whisk/core/controller/WebActions.scala
@@ -544,9 +544,13 @@ trait WhiskWebActionsApi extends Directives with 
ValidateRequestSize with PostAc
         case Empty =>
           process(None, isRawHttpAction)
 
-        case HttpEntity.Strict(ContentTypes.`application/json`, _) if 
!isRawHttpAction =>
-          entity(as[JsObject]) { body =>
-            process(Some(body), isRawHttpAction)
+        case HttpEntity.Strict(ContentTypes.`application/json`, json) if 
!isRawHttpAction =>
+          if (json.nonEmpty) {
+            entity(as[JsValue]) { body =>
+              process(Some(body), isRawHttpAction)
+            }
+          } else {
+            process(None, isRawHttpAction)
           }
 
         case 
HttpEntity.Strict(ContentType(MediaTypes.`application/x-www-form-urlencoded`, 
_), _) if !isRawHttpAction =>
diff --git 
a/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala 
b/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala
index 36d2f6c..250ccb9 100644
--- a/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala
@@ -488,6 +488,30 @@ trait WebActionsApiTests extends ControllerTestCommon with 
BeforeAndAfterEach wi
       }
     }
 
+    it should s"invoke action which receives an empty entity (auth? 
${creds.isDefined})" in {
+      implicit val tid = transid()
+
+      Seq("", JsArray().compactPrint, JsObject().compactPrint, 
JsNull.compactPrint).foreach { arg =>
+        Seq(s"$systemId/proxy/export_c.json").foreach { path =>
+          allowedMethodsWithEntity.foreach { m =>
+            invocationsAllowed += 1
+            m(s"$testRoutePath/$path", 
HttpEntity(ContentTypes.`application/json`, arg)) ~> Route.seal(routes(creds)) 
~> check {
+              status should be(OK)
+              val response = responseAs[JsObject]
+              response shouldBe JsObject(
+                "pkg" -> s"$systemId/proxy".toJson,
+                "action" -> "export_c".toJson,
+                "content" -> metaPayload(
+                  m.method.name.toLowerCase,
+                  if (arg.nonEmpty && arg != "{}") 
JsObject(webApiDirectives.body -> arg.parseJson) else JsObject(),
+                  creds,
+                  pkgName = "proxy"))
+            }
+          }
+        }
+      }
+    }
+
     it should s"invoke action and merge query and body parameters (auth? 
${creds.isDefined})" in {
       implicit val tid = transid()
 
@@ -1006,7 +1030,6 @@ trait WebActionsApiTests extends ControllerTestCommon 
with BeforeAndAfterEach wi
                   "body" -> JsObject("field" -> "value".toJson)))
 
               m(s"$testRoutePath/$path") ~> Route.seal(routes(creds)) ~> check 
{
-                println(responseAs[String])
                 status should be(expectedCode)
 
                 if (expectedCode == OK) {

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

Reply via email to