markusthoemmes closed pull request #3340: Default activation response to empty 
JsObject.
URL: https://github.com/apache/incubator-openwhisk/pull/3340
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala 
b/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala
index 8c18a98a6b..74ec24c477 100644
--- a/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala
+++ b/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala
@@ -75,13 +75,13 @@ case class WhiskActivation(namespace: EntityPath,
   require(end != null, "end undefined")
   require(response != null, "response undefined")
 
-  def toJson = WhiskActivation.serdes.write(this).asJsObject
+  def toJson: JsObject = WhiskActivation.serdes.write(this).asJsObject
 
   /**
    * This the activation summary as computed by the database view.
    * Strictly used in view testing to enforce alignment.
    */
-  override def summaryAsJson = {
+  override def summaryAsJson: JsObject = {
     import WhiskActivation.instantSerdes
 
     def actionOrNot() = {
@@ -97,13 +97,13 @@ case class WhiskActivation(namespace: EntityPath,
       super.summaryAsJson.fields - "updated" +
         ("activationId" -> activationId.toJson) +
         ("start" -> start.toJson) ++
-        cause.map(("cause" -> _.toJson)) ++
+        cause.map("cause" -> _.toJson) ++
         actionOrNot())
   }
 
-  def resultAsJson = response.result.toJson.asJsObject
+  def resultAsJson: JsObject = 
response.result.map(_.toJson.asJsObject).getOrElse(JsObject.empty)
 
-  def toExtendedJson = {
+  def toExtendedJson: JsObject = {
     val JsObject(baseFields) = WhiskActivation.serdes.write(this).asJsObject
     val newFields = (baseFields - "response") + ("response" -> 
response.toExtendedJson)
     if (end != Instant.EPOCH) {
@@ -114,12 +114,12 @@ case class WhiskActivation(namespace: EntityPath,
     }
   }
 
-  def withoutLogsOrResult = {
+  def withoutLogsOrResult: WhiskActivation = {
     copy(response = response.withoutResult, logs = 
ActivationLogs()).revision[WhiskActivation](rev)
   }
 
-  def withoutLogs = copy(logs = 
ActivationLogs()).revision[WhiskActivation](rev)
-  def withLogs(logs: ActivationLogs) = copy(logs = 
logs).revision[WhiskActivation](rev)
+  def withoutLogs: WhiskActivation = copy(logs = 
ActivationLogs()).revision[WhiskActivation](rev)
+  def withLogs(logs: ActivationLogs): WhiskActivation = copy(logs = 
logs).revision[WhiskActivation](rev)
 }
 
 object WhiskActivation
@@ -163,13 +163,13 @@ object WhiskActivation
   private val filtersDdoc = dbConfig.activationsFilterDdoc
 
   /** The main view for activations, keyed by namespace, sorted by date. */
-  override lazy val view = WhiskEntityQueries.view(mainDdoc, collectionName)
+  override lazy val view: View = WhiskEntityQueries.view(mainDdoc, 
collectionName)
 
   /**
    * A view for activations in a namespace additionally keyed by action name
    * (and package name if present) sorted by date.
    */
-  lazy val filtersView = WhiskEntityQueries.view(filtersDdoc, collectionName)
+  lazy val filtersView: View = WhiskEntityQueries.view(filtersDdoc, 
collectionName)
 
   override implicit val serdes = jsonFormat13(WhiskActivation.apply)
 
diff --git a/tests/src/test/scala/whisk/core/entity/test/WhiskEntityTests.scala 
b/tests/src/test/scala/whisk/core/entity/test/WhiskEntityTests.scala
index 1812f5ac20..edf9fcd728 100644
--- a/tests/src/test/scala/whisk/core/entity/test/WhiskEntityTests.scala
+++ b/tests/src/test/scala/whisk/core/entity/test/WhiskEntityTests.scala
@@ -34,7 +34,7 @@ import whisk.core.entity.Subject
 import whisk.core.entity.ActivationId
 import java.time.Instant
 
-import spray.json.JsString
+import spray.json.{JsObject, JsString}
 import whisk.core.entity.ActivationLogs
 import whisk.core.entity.WhiskTrigger
 import whisk.core.entity.ReducedRule
@@ -116,6 +116,12 @@ class WhiskEntityTests extends FlatSpec with ExecHelpers 
with Matchers {
     withoutLogs.rev shouldBe activation.rev
   }
 
+  it should "return an empty jsobject if no response is present" in {
+    val activation = WhiskActivation(namespace, name, Subject(), 
ActivationId(), Instant.now(), Instant.now())
+      .revision[WhiskActivation](revision)
+    activation.resultAsJson shouldBe JsObject.empty
+  }
+
   behavior of "WhiskTrigger"
 
   it should "add and remove rules and preserve revision in the process" in {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to