houshengbo closed pull request #2955: Re-implement the test cases under 
whisk.core.cli.test package in REST
URL: https://github.com/apache/incubator-openwhisk/pull/2955
 
 
   

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/tests/src/test/scala/common/BaseWsk.scala 
b/tests/src/test/scala/common/BaseWsk.scala
index 9d7cafe980..0917fa6942 100644
--- a/tests/src/test/scala/common/BaseWsk.scala
+++ b/tests/src/test/scala/common/BaseWsk.scala
@@ -274,7 +274,7 @@ trait BaseActivation extends BaseRunWsk {
   def pollFor(N: Int,
               entity: Option[String],
               limit: Option[Int] = None,
-              since: Option[Instant],
+              since: Option[Instant] = None,
               retries: Int,
               pollPeriod: Duration = 1.second)(implicit wp: WskProps): 
Seq[String]
 
diff --git a/tests/src/test/scala/common/rest/WskRest.scala 
b/tests/src/test/scala/common/rest/WskRest.scala
index 2f620c2fba..71551a65f4 100644
--- a/tests/src/test/scala/common/rest/WskRest.scala
+++ b/tests/src/test/scala/common/rest/WskRest.scala
@@ -141,8 +141,9 @@ trait ListOrGetFromCollectionRest extends 
BaseListOrGetFromCollection {
                     expectedExitCode: Int = OK.intValue)(implicit wp: 
WskProps): RestResult = {
 
     val entPath = namespace map { ns =>
-      val (ns, name) = getNamespaceEntityName(resolve(namespace))
-      Path(s"$basePath/namespaces/$ns/$noun/$name/")
+      val (nspace, name) = getNamespaceEntityName(resolve(namespace))
+      if (name.isEmpty) Path(s"$basePath/namespaces/$nspace/$noun")
+      else Path(s"$basePath/namespaces/$nspace/$noun/$name/")
     } getOrElse Path(s"$basePath/namespaces/${wp.namespace}/$noun")
 
     val paramMap = Map[String, String]() ++ { Map("skip" -> "0", "docs" -> 
true.toString) } ++ {
@@ -1259,7 +1260,6 @@ class RunWskRestCmd() extends FlatSpec with RunWskCmd 
with Matchers with ScalaFu
   }
 
   def convertStringIntoKeyValue(file: String, feed: Option[String] = None, 
web: Option[String] = None): JsArray = {
-    var paramsList = Vector[JsObject]()
     val input = FileUtils.readFileToString(new File(file))
     val in = input.parseJson.convertTo[Map[String, JsValue]]
     convertMapIntoKeyValue(in, feed, web)
@@ -1273,9 +1273,21 @@ class RunWskRestCmd() extends FlatSpec with RunWskCmd 
with Matchers with ScalaFu
     paramsList = feed map { f =>
       paramsList :+ JsObject("key" -> "feed".toJson, "value" -> f.toJson)
     } getOrElse paramsList
-    paramsList = web map { w =>
-      paramsList :+ JsObject("key" -> "web-export".toJson, "value" -> w.toJson)
-    } getOrElse paramsList
+    paramsList = web match {
+      case Some("true") =>
+        paramsList :+ JsObject("key" -> "web-export".toJson, "value" -> 
true.toJson) :+ JsObject(
+          "key" -> "raw-http".toJson,
+          "value" -> false.toJson) :+ JsObject("key" -> "final".toJson, 
"value" -> true.toJson)
+      case Some("false") =>
+        paramsList :+ JsObject("key" -> "web-export".toJson, "value" -> 
false.toJson) :+ JsObject(
+          "key" -> "raw-http".toJson,
+          "value" -> false.toJson) :+ JsObject("key" -> "final".toJson, 
"value" -> false.toJson)
+      case Some("raw") =>
+        paramsList :+ JsObject("key" -> "web-export".toJson, "value" -> 
true.toJson) :+ JsObject(
+          "key" -> "raw-http".toJson,
+          "value" -> true.toJson) :+ JsObject("key" -> "final".toJson, "value" 
-> true.toJson)
+      case _ => paramsList
+    }
     JsArray(paramsList)
   }
 
@@ -1318,8 +1330,10 @@ class RunWskRestCmd() extends FlatSpec with RunWskCmd 
with Matchers with ScalaFu
       case Array(empty, namespace, entityName) if empty.isEmpty => (namespace, 
entityName)
       // Example: namespace/package_name/entity_name
       case Array(namespace, packageName, entityName) => (namespace, 
s"$packageName/$entityName")
+      // Example: /namespace
+      case Array(empty, namespace) if empty.isEmpty => (namespace, "")
       // Example: package_name/entity_name
-      case Array(packageName, entityName) => (wp.namespace, 
s"$packageName/$entityName")
+      case Array(packageName, entityName) if !packageName.isEmpty => 
(wp.namespace, s"$packageName/$entityName")
       // Example: entity_name
       case Array(entityName) => (wp.namespace, entityName)
       case _                 => (wp.namespace, name)
diff --git 
a/tests/src/test/scala/whisk/core/cli/test/SequenceMigrationTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/SequenceMigrationTests.scala
index 977505f4f1..acc0361867 100644
--- a/tests/src/test/scala/whisk/core/cli/test/SequenceMigrationTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/SequenceMigrationTests.scala
@@ -29,7 +29,7 @@ import org.scalatest.junit.JUnitRunner
 import akka.stream.ActorMaterializer
 import common.TestHelpers
 import common.TestUtils
-import common.Wsk
+import common.rest.WskRest
 import common.WskProps
 import common.WskTestHelpers
 import spray.json._
@@ -47,7 +47,7 @@ class SequenceMigrationTests extends TestHelpers with 
BeforeAndAfter with DbUtil
 
   implicit val matzerializer = ActorMaterializer()
   implicit val wskprops = WskProps()
-  val wsk = new Wsk
+  val wsk = new WskRest
   val whiskConfig = new WhiskConfig(WhiskEntityStore.requiredProperties)
   // handle on the entity datastore
   val entityStore = WhiskEntityStore.datastore(whiskConfig)
diff --git a/tests/src/test/scala/whisk/core/cli/test/Swift3Tests.scala 
b/tests/src/test/scala/whisk/core/cli/test/Swift3Tests.scala
index 513cf9405a..5d4c02fa6c 100644
--- a/tests/src/test/scala/whisk/core/cli/test/Swift3Tests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/Swift3Tests.scala
@@ -24,7 +24,7 @@ import org.scalatest.Matchers
 import org.scalatest.junit.JUnitRunner
 import common.TestHelpers
 import common.TestUtils
-import common.Wsk
+import common.rest.WskRest
 import common.WskProps
 import common.WskTestHelpers
 import spray.json.DefaultJsonProtocol.StringJsonFormat
@@ -34,7 +34,7 @@ import spray.json.pimpAny
 class Swift3Tests extends TestHelpers with WskTestHelpers with Matchers {
 
   implicit val wskprops = WskProps()
-  val wsk = new Wsk
+  val wsk = new WskRest
   val expectedDuration = 45 seconds
   val activationPollDuration = 60 seconds
 
diff --git 
a/tests/src/test/scala/whisk/core/cli/test/WskActionSequenceTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/WskActionSequenceTests.scala
index b547cb48a9..39b9efdc14 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskActionSequenceTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskActionSequenceTests.scala
@@ -22,9 +22,10 @@ import org.scalatest.junit.JUnitRunner
 
 import common.TestHelpers
 import common.TestUtils
-import common.Wsk
+import common.BaseWsk
 import common.WskProps
 import common.WskTestHelpers
+import TestUtils.RunResult
 import spray.json._
 import whisk.core.entity.EntityPath
 
@@ -32,10 +33,10 @@ import whisk.core.entity.EntityPath
  * Tests creation and retrieval of a sequence action
  */
 @RunWith(classOf[JUnitRunner])
-class WskActionSequenceTests extends TestHelpers with WskTestHelpers {
+abstract class WskActionSequenceTests extends TestHelpers with WskTestHelpers {
 
   implicit val wskprops = WskProps()
-  val wsk = new Wsk
+  val wsk: BaseWsk
   val defaultNamespace = EntityPath.DEFAULT.asString
   val namespace = wsk.namespace.whois()
 
@@ -75,7 +76,12 @@ class WskActionSequenceTests extends TestHelpers with 
WskTestHelpers {
       action.create(name, Some(artifacts), kind = Some("sequence"))
     }
 
-    val stdout = wsk.action.get(name).stdout
+    val action = wsk.action.get(name)
+    verifyActionSequence(action, name, compValue, kindValue)
+  }
+
+  def verifyActionSequence(action: RunResult, name: String, compValue: 
JsArray, kindValue: JsString): Unit = {
+    val stdout = action.stdout
     assert(stdout.startsWith(s"ok: got action $name\n"))
     wsk.parseJsonString(stdout).fields("exec").asJsObject.fields("components") 
shouldBe compValue
     wsk.parseJsonString(stdout).fields("exec").asJsObject.fields("kind") 
shouldBe kindValue
diff --git 
a/tests/src/test/scala/whisk/core/cli/test/WskCliActionSequenceTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/WskCliActionSequenceTests.scala
new file mode 100644
index 0000000000..06da3489ed
--- /dev/null
+++ b/tests/src/test/scala/whisk/core/cli/test/WskCliActionSequenceTests.scala
@@ -0,0 +1,28 @@
+/*
+ * 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 whisk.core.cli.test
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.Wsk
+
+@RunWith(classOf[JUnitRunner])
+class WskCliActionSequenceTests extends WskActionSequenceTests {
+  override lazy val wsk = new Wsk
+}
diff --git 
a/tests/src/test/scala/whisk/core/cli/test/WskCliEntitlementTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/WskCliEntitlementTests.scala
new file mode 100644
index 0000000000..e25369cbc1
--- /dev/null
+++ b/tests/src/test/scala/whisk/core/cli/test/WskCliEntitlementTests.scala
@@ -0,0 +1,34 @@
+/*
+ * 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 whisk.core.cli.test
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.Wsk
+import common.TestUtils.FORBIDDEN
+import common.TestUtils.TIMEOUT
+import common.TestUtils.NOT_FOUND
+
+@RunWith(classOf[JUnitRunner])
+class WskCliEntitlementTests extends WskEntitlementTests {
+  override lazy val wsk = new Wsk
+  override lazy val forbiddenCode = FORBIDDEN
+  override lazy val timeoutCode = TIMEOUT
+  override lazy val notFoundCode = NOT_FOUND
+}
diff --git 
a/tests/src/test/scala/whisk/core/cli/test/WskCliWebActionsTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/WskCliWebActionsTests.scala
new file mode 100644
index 0000000000..048fdced5b
--- /dev/null
+++ b/tests/src/test/scala/whisk/core/cli/test/WskCliWebActionsTests.scala
@@ -0,0 +1,28 @@
+/*
+ * 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 whisk.core.cli.test
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.Wsk
+
+@RunWith(classOf[JUnitRunner])
+class WskCliWebActionsTests extends WskWebActionsTests {
+  override lazy val wsk: common.Wsk = new Wsk
+}
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskEntitlementTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/WskEntitlementTests.scala
index cd58febd28..99e839fbfe 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskEntitlementTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskEntitlementTests.scala
@@ -23,10 +23,8 @@ import org.scalatest.junit.JUnitRunner
 
 import common.TestHelpers
 import common.TestUtils
-import common.TestUtils.FORBIDDEN
-import common.TestUtils.NOT_FOUND
-import common.TestUtils.TIMEOUT
-import common.Wsk
+import common.TestUtils.RunResult
+import common.BaseWsk
 import common.WskProps
 import common.WskTestHelpers
 import spray.json._
@@ -35,11 +33,14 @@ import whisk.core.entity.Subject
 import whisk.core.entity.WhiskPackage
 
 @RunWith(classOf[JUnitRunner])
-class WskEntitlementTests extends TestHelpers with WskTestHelpers with 
BeforeAndAfterAll {
+abstract class WskEntitlementTests extends TestHelpers with WskTestHelpers 
with BeforeAndAfterAll {
 
-  val wsk = new Wsk
+  val wsk: BaseWsk
   lazy val defaultWskProps = WskProps()
   lazy val guestWskProps = getAdditionalTestSubject(Subject().asString)
+  val forbiddenCode: Int
+  val timeoutCode: Int
+  val notFoundCode: Int
 
   override def afterAll() = {
     disposeAdditionalTestSubject(guestWskProps.namespace)
@@ -61,12 +62,13 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
       }
 
       val fullyQualifiedActionName = s"/$guestNamespace/$privateAction"
-      wsk.action.get(fullyQualifiedActionName, expectedExitCode = 
FORBIDDEN)(defaultWskProps).stderr should include(
-        "not authorized")
+      wsk.action
+        .get(fullyQualifiedActionName, expectedExitCode = 
forbiddenCode)(defaultWskProps)
+        .stderr should include("not authorized")
 
       withAssetCleaner(defaultWskProps) { (wp, assetHelper) =>
         assetHelper.withCleaner(wsk.action, fullyQualifiedActionName, 
confirmDelete = false) { (action, name) =>
-          val rr = action.create(name, None, update = true, expectedExitCode = 
FORBIDDEN)(wp)
+          val rr = action.create(name, None, update = true, expectedExitCode = 
forbiddenCode)(wp)
           rr.stderr should include("not authorized")
           rr
         }
@@ -77,17 +79,19 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
             Some(fullyQualifiedActionName),
             kind = Some("sequence"),
             update = true,
-            expectedExitCode = FORBIDDEN)(wp)
+            expectedExitCode = forbiddenCode)(wp)
           rr.stderr should include("not authorized")
           rr
         }
       }
 
-      wsk.action.delete(fullyQualifiedActionName, expectedExitCode = 
FORBIDDEN)(defaultWskProps).stderr should include(
-        "not authorized")
+      wsk.action
+        .delete(fullyQualifiedActionName, expectedExitCode = 
forbiddenCode)(defaultWskProps)
+        .stderr should include("not authorized")
 
-      wsk.action.invoke(fullyQualifiedActionName, expectedExitCode = 
FORBIDDEN)(defaultWskProps).stderr should include(
-        "not authorized")
+      wsk.action
+        .invoke(fullyQualifiedActionName, expectedExitCode = 
forbiddenCode)(defaultWskProps)
+        .stderr should include("not authorized")
   }
 
   it should "reject deleting action in shared package not owned by authkey" in 
withAssetCleaner(guestWskProps) {
@@ -104,7 +108,7 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
 
       val fullyQualifiedActionName = s"/$guestNamespace/$fullSampleActionName"
       wsk.action.get(fullyQualifiedActionName)(defaultWskProps)
-      wsk.action.delete(fullyQualifiedActionName, expectedExitCode = 
FORBIDDEN)(defaultWskProps)
+      wsk.action.delete(fullyQualifiedActionName, expectedExitCode = 
forbiddenCode)(defaultWskProps)
   }
 
   it should "reject create action in shared package not owned by authkey" in 
withAssetCleaner(guestWskProps) {
@@ -118,7 +122,7 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
 
       withAssetCleaner(defaultWskProps) { (wp, assetHelper) =>
         assetHelper.withCleaner(wsk.action, fullyQualifiedActionName, 
confirmDelete = false) { (action, name) =>
-          action.create(name, file, expectedExitCode = FORBIDDEN)(wp)
+          action.create(name, file, expectedExitCode = forbiddenCode)(wp)
         }
       }
   }
@@ -136,7 +140,8 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
       }
 
       val fullyQualifiedActionName = s"/$guestNamespace/$fullSampleActionName"
-      wsk.action.create(fullyQualifiedActionName, None, update = true, 
expectedExitCode = FORBIDDEN)(defaultWskProps)
+      wsk.action.create(fullyQualifiedActionName, None, update = true, 
expectedExitCode = forbiddenCode)(
+        defaultWskProps)
   }
 
   behavior of "Wsk Package Listing"
@@ -146,9 +151,13 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
       pkg.create(samplePackage, shared = Some(true))(wp)
     }
 
-    val fullyQualifiedPackageName = s"/$guestNamespace/$samplePackage"
-    val result = 
wsk.pkg.list(Some(s"/$guestNamespace"))(defaultWskProps).stdout
-    result should include regex (fullyQualifiedPackageName + """\s+shared""")
+    val packageList = wsk.pkg.list(Some(s"/$guestNamespace"))(defaultWskProps)
+    verifyPackageSharedList(packageList, guestNamespace, samplePackage)
+  }
+
+  def verifyPackageSharedList(packageList: RunResult, namespace: String, 
packageName: String): Unit = {
+    val fullyQualifiedPackageName = s"/$namespace/$packageName"
+    packageList.stdout should include regex (fullyQualifiedPackageName + 
"""\s+shared""")
   }
 
   it should "not list private packages" in withAssetCleaner(guestWskProps) { 
(wp, assetHelper) =>
@@ -156,9 +165,13 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
       pkg.create(samplePackage)(wp)
     }
 
-    val fullyQualifiedPackageName = s"/$guestNamespace/$samplePackage"
-    val result = 
wsk.pkg.list(Some(s"/$guestNamespace"))(defaultWskProps).stdout
-    result should not include regex(fullyQualifiedPackageName)
+    val packageList = wsk.pkg.list(Some(s"/$guestNamespace"))(defaultWskProps)
+    verifyPackageNotSharedList(packageList, guestNamespace, samplePackage)
+  }
+
+  def verifyPackageNotSharedList(packageList: RunResult, namespace: String, 
packageName: String): Unit = {
+    val fullyQualifiedPackageName = s"/$namespace/$packageName"
+    packageList.stdout should not include regex(fullyQualifiedPackageName)
   }
 
   it should "list shared package actions" in withAssetCleaner(guestWskProps) { 
(wp, assetHelper) =>
@@ -173,9 +186,13 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
     }
 
     val fullyQualifiedPackageName = s"/$guestNamespace/$samplePackage"
-    val fullyQualifiedActionName = s"/$guestNamespace/$fullSampleActionName"
-    val result = 
wsk.action.list(Some(fullyQualifiedPackageName))(defaultWskProps).stdout
-    result should include regex (fullyQualifiedActionName)
+    val packageList = 
wsk.action.list(Some(fullyQualifiedPackageName))(defaultWskProps)
+    verifyPackageList(packageList, guestNamespace, samplePackage, sampleAction)
+  }
+
+  def verifyPackageList(packageList: RunResult, namespace: String, 
packageName: String, actionName: String): Unit = {
+    val result = packageList.stdout
+    result should include regex (s"/$namespace/$packageName/$actionName")
   }
 
   behavior of "Wsk Package Binding"
@@ -212,7 +229,7 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
     val provider = s"/$guestNamespace/$samplePackage"
     withAssetCleaner(defaultWskProps) { (wp, assetHelper) =>
       assetHelper.withCleaner(wsk.pkg, name, confirmDelete = false) { (pkg, _) 
=>
-        pkg.bind(provider, name, expectedExitCode = FORBIDDEN)(wp)
+        pkg.bind(provider, name, expectedExitCode = forbiddenCode)(wp)
       }
     }
   }
@@ -231,12 +248,8 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
     }
 
     val fullyQualifiedActionName = s"/$guestNamespace/$fullSampleActionName"
-    val stdout = 
wsk.action.get(fullyQualifiedActionName)(defaultWskProps).stdout
-    stdout should include("name")
-    stdout should include("parameters")
-    stdout should include("limits")
-    stdout should include regex (""""key": "a"""")
-    stdout should include regex (""""value": "A"""")
+    val action = wsk.action.get(fullyQualifiedActionName)(defaultWskProps)
+    verifyAction(action)
 
     val run = wsk.action.invoke(fullyQualifiedActionName)(defaultWskProps)
 
@@ -245,6 +258,15 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
     })(defaultWskProps)
   }
 
+  def verifyAction(action: RunResult) = {
+    val stdout = action.stdout
+    stdout should include("name")
+    stdout should include("parameters")
+    stdout should include("limits")
+    stdout should include regex (""""key": "a"""")
+    stdout should include regex (""""value": "A"""")
+  }
+
   it should "invoke an action sequence from package" in 
withAssetCleaner(guestWskProps) { (wp, assetHelper) =>
     assetHelper.withCleaner(wsk.pkg, samplePackage) { (pkg, _) =>
       pkg.create(samplePackage, parameters = Map("a" -> "A".toJson), shared = 
Some(true))(wp)
@@ -294,7 +316,7 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
 
       // change package visibility
       wsk.pkg.create(privateSamplePackage, update = true, shared = 
Some(false))(guestwp)
-      wsk.action.invoke("sequence", expectedExitCode = 
FORBIDDEN)(defaultWskProps)
+      wsk.action.invoke("sequence", expectedExitCode = 
forbiddenCode)(defaultWskProps)
     }
   }
 
@@ -342,9 +364,9 @@ class WskEntitlementTests extends TestHelpers with 
WskTestHelpers with BeforeAnd
       val fullyQualifiedFeedName = s"/$guestNamespace/$sampleFeed"
       withAssetCleaner(defaultWskProps) { (wp, assetHelper) =>
         assetHelper.withCleaner(wsk.trigger, "badfeed", confirmDelete = false) 
{ (trigger, name) =>
-          trigger.create(name, feed = Some(fullyQualifiedFeedName), 
expectedExitCode = TIMEOUT)(wp)
+          trigger.create(name, feed = Some(fullyQualifiedFeedName), 
expectedExitCode = timeoutCode)(wp)
         }
-        wsk.trigger.get("badfeed", expectedExitCode = NOT_FOUND)(wp)
+        wsk.trigger.get("badfeed", expectedExitCode = notFoundCode)(wp)
       }
   }
 
diff --git 
a/tests/src/test/scala/whisk/core/cli/test/WskRestActionSequenceTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/WskRestActionSequenceTests.scala
new file mode 100644
index 0000000000..f8cec3e89a
--- /dev/null
+++ b/tests/src/test/scala/whisk/core/cli/test/WskRestActionSequenceTests.scala
@@ -0,0 +1,37 @@
+/*
+ * 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 whisk.core.cli.test
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import spray.json._
+
+import common.rest.WskRest
+import common.rest.RestResult
+import common.TestUtils.RunResult
+
+@RunWith(classOf[JUnitRunner])
+class WskRestActionSequenceTests extends WskActionSequenceTests {
+  override lazy val wsk: common.rest.WskRest = new WskRest
+
+  override def verifyActionSequence(action: RunResult, name: String, 
compValue: JsArray, kindValue: JsString): Unit = {
+    val actionResultRest = action.asInstanceOf[RestResult]
+    actionResultRest.respBody.fields("exec").asJsObject.fields("components") 
shouldBe compValue
+    actionResultRest.respBody.fields("exec").asJsObject.fields("kind") 
shouldBe kindValue
+  }
+}
diff --git 
a/tests/src/test/scala/whisk/core/cli/test/WskRestEntitlementTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/WskRestEntitlementTests.scala
new file mode 100644
index 0000000000..4a890a8367
--- /dev/null
+++ b/tests/src/test/scala/whisk/core/cli/test/WskRestEntitlementTests.scala
@@ -0,0 +1,71 @@
+/*
+ * 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 whisk.core.cli.test
+
+import akka.http.scaladsl.model.StatusCodes.BadGateway
+import akka.http.scaladsl.model.StatusCodes.Forbidden
+import akka.http.scaladsl.model.StatusCodes.NotFound
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.rest.WskRest
+import common.rest.RestResult
+import common.TestUtils.RunResult
+
+@RunWith(classOf[JUnitRunner])
+class WskRestEntitlementTests extends WskEntitlementTests {
+  override lazy val wsk: common.rest.WskRest = new WskRest
+  override lazy val forbiddenCode = Forbidden.intValue
+  override lazy val timeoutCode = BadGateway.intValue
+  override lazy val notFoundCode = NotFound.intValue
+
+  override def verifyAction(action: RunResult): org.scalatest.Assertion = {
+    val stdout = action.stdout
+    stdout should include("name")
+    stdout should include("parameters")
+    stdout should include("limits")
+    stdout should include regex (""""key":"a"""")
+    stdout should include regex (""""value":"A"""")
+  }
+
+  override def verifyPackageList(packageList: RunResult,
+                                 namespace: String,
+                                 packageName: String,
+                                 actionName: String): Unit = {
+    val packageListResultRest = packageList.asInstanceOf[RestResult]
+    val packages = packageListResultRest.getBodyListJsObject()
+    val ns = s"$namespace/$packageName"
+    packages.exists(pack =>
+      RestResult.getField(pack, "namespace") == ns && 
RestResult.getField(pack, "name") == actionName)
+  }
+
+  override def verifyPackageSharedList(packageList: RunResult, namespace: 
String, packageName: String): Unit = {
+    val packageListResultRest = packageList.asInstanceOf[RestResult]
+    val packages = packageListResultRest.getBodyListJsObject()
+    packages.exists(pack =>
+      RestResult.getField(pack, "namespace") == namespace && 
RestResult.getField(pack, "name") == packageName)
+  }
+
+  override def verifyPackageNotSharedList(packageList: RunResult, namespace: 
String, packageName: String): Unit = {
+    val packageListResultRest = packageList.asInstanceOf[RestResult]
+    val packages = packageListResultRest.getBodyListJsObject()
+    packages.exists(pack => RestResult.getField(pack, "namespace") != 
namespace)
+    packages.exists(pack => RestResult.getField(pack, "name") != packageName)
+  }
+}
diff --git 
a/tests/src/test/scala/whisk/core/cli/test/WskRestWebActionsTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/WskRestWebActionsTests.scala
new file mode 100644
index 0000000000..832d36558d
--- /dev/null
+++ b/tests/src/test/scala/whisk/core/cli/test/WskRestWebActionsTests.scala
@@ -0,0 +1,28 @@
+/*
+ * 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 whisk.core.cli.test
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.rest.WskRest
+
+@RunWith(classOf[JUnitRunner])
+class WskRestWebActionsTests extends WskWebActionsTests {
+  override lazy val wsk: common.rest.WskRest = new WskRest
+}
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
index 45c77ef84a..6009f1578d 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
@@ -33,7 +33,7 @@ import com.jayway.restassured.response.Header
 import common.TestHelpers
 import common.TestUtils
 import common.WhiskProperties
-import common.Wsk
+import common.BaseWsk
 import common.WskProps
 import common.WskTestHelpers
 import spray.json._
@@ -48,10 +48,10 @@ import whisk.core.entity.Subject
  * Tests web actions.
  */
 @RunWith(classOf[JUnitRunner])
-class WskWebActionsTests extends TestHelpers with WskTestHelpers with RestUtil 
with BeforeAndAfterAll {
+abstract class WskWebActionsTests extends TestHelpers with WskTestHelpers with 
RestUtil with BeforeAndAfterAll {
   val MAX_URL_LENGTH = 8192 // 8K matching nginx default
 
-  val wsk = new Wsk
+  val wsk: BaseWsk
   private implicit val wskprops = WskProps()
   val namespace = wsk.namespace.whois()
 
@@ -270,10 +270,8 @@ class WskWebActionsTests extends TestHelpers with 
WskTestHelpers with RestUtil w
 
     response.statusCode shouldBe 200
     val cookieHeaders = response.headers.getList("Set-Cookie")
-    cookieHeaders should contain allOf (
-      new Header("Set-Cookie", "a=b"),
-      new Header("Set-Cookie", "c=d")
-    )
+    cookieHeaders should contain allOf (new Header("Set-Cookie", "a=b"),
+    new Header("Set-Cookie", "c=d"))
   }
 
   it should "handle http web action with base64 encoded response" in 
withAssetCleaner(wskprops) { (wp, assetHelper) =>


 

----------------------------------------------------------------
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