houshengbo commented on a change in pull request #2592: Make the result of 
response consistent for both Wsk CLI and REST
URL: 
https://github.com/apache/incubator-openwhisk/pull/2592#discussion_r133816983
 
 

 ##########
 File path: tests/src/test/scala/common/rest/WskRest.scala
 ##########
 @@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package common.rest
+
+import scala.util.Try
+
+import akka.http.scaladsl.model.StatusCode
+import akka.http.scaladsl.model.StatusCodes.BadRequest
+import spray.json.JsObject
+import spray.json.JsValue
+import spray.json.pimpString
+import spray.json.DefaultJsonProtocol._
+
+import common.TestUtils.RunResult
+
+class WskRest() {
+}
+
+object RestResult {
+
+    val codeConversion = 256
+
+    def getField(obj: JsObject, key: String): String = {
+        val list = obj.getFields(key)
+        if (list.size == 0) {
+            ""
+        }
+        else {
+            Try {
+                list(0).convertTo[String]
+            } getOrElse
+                list(0).convertTo[Int].toString
+        }
+    }
+
+    def getFieldJsObject(obj: JsObject, key: String): JsObject = {
+        val list = obj.getFields(key)
+        if (list.size == 0) JsObject() else list(0).toJson.asJsObject
+    }
+
+    def getFieldJsValue(obj: JsObject, key: String): JsValue = {
+        val list = obj.getFields(key)
+        if (list.size == 0) JsObject() else list(0).toJson
+    }
+
+    def getFieldListJsObject(obj: JsObject, key: String): Vector[JsObject] = {
+        val list = obj.getFields(key)
+        if (list.size == 0) Vector(JsObject()) else 
list(0).toJson.convertTo[Vector[JsObject]]
+    }
 
 Review comment:
   I would like to use 
obj.fields.get(key).map(_.convertTo[String]).getOrElse("") instead of 
obj.fields.get(key).map(_.compactPrint).getOrElse("") for getField(obj, key), 
because I would like to pick the string instead of JsString. Do you think it is 
OK?
 
----------------------------------------------------------------
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