dubeejw closed pull request #2895: Update the test cases about rules with REST 
implementation
URL: https://github.com/apache/incubator-openwhisk/pull/2895
 
 
   

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/rest/WskRest.scala 
b/tests/src/test/scala/common/rest/WskRest.scala
index 155fa06a4c..d31ade1bf4 100644
--- a/tests/src/test/scala/common/rest/WskRest.scala
+++ b/tests/src/test/scala/common/rest/WskRest.scala
@@ -137,15 +137,16 @@ trait ListOrGetFromCollectionRest extends 
BaseListOrGetFromCollection {
                     limit: Option[Int] = None,
                     nameSort: Option[Boolean] = None,
                     expectedExitCode: Int = OK.intValue)(implicit wp: 
WskProps): RestResult = {
-    val (ns, name) = getNamespaceEntityName(resolve(namespace))
-    val pathToList = s"$basePath/namespaces/$ns/$noun"
-    val entPath =
-      if (name != "") Path(s"$pathToList/$name/")
-      else Path(s"$pathToList")
+
+    val entPath = namespace map { ns =>
+      val (ns, name) = getNamespaceEntityName(resolve(namespace))
+      Path(s"$basePath/namespaces/$ns/$noun/$name/")
+    } getOrElse Path(s"$basePath/namespaces/${wp.namespace}/$noun")
+
     val paramMap = Map[String, String]() ++ { Map("skip" -> "0", "docs" -> 
true.toString) } ++ {
       limit map { l =>
         Map("limit" -> l.toString)
-      } getOrElse Map[String, String]("limit" -> "30")
+      } getOrElse Map[String, String]()
     }
     val resp = requestEntity(GET, entPath, paramMap)
     val r = new RestResult(resp.status, getRespData(resp))
@@ -631,14 +632,14 @@ class WskRestActivation extends RunWskRestCmd with 
HasActivationRest with WaitFo
     var paramMap = Map("skip" -> "0", "docs" -> docs.toString) ++ {
       limit map { l =>
         Map("limit" -> l.toString)
-      } getOrElse Map("limit" -> "30")
+      } getOrElse Map[String, String]()
     } ++ {
       filter map { f =>
-        Map("limit" -> f.toString)
+        Map("name" -> f.toString)
       } getOrElse Map[String, String]()
     } ++ {
       since map { s =>
-        Map("limit" -> s.toEpochMilli().toString)
+        Map("since" -> s.toEpochMilli().toString)
       } getOrElse Map[String, String]()
     }
     val resp = requestEntity(GET, entityPath, paramMap)
diff --git a/tests/src/test/scala/system/basic/WskCliRuleTests.scala 
b/tests/src/test/scala/system/basic/WskCliRuleTests.scala
new file mode 100644
index 0000000000..6c630772f8
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskCliRuleTests.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 system.basic
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.Wsk
+
+@RunWith(classOf[JUnitRunner])
+class WskCliRuleTests extends WskRuleTests {
+  override val wsk: Wsk = new Wsk
+}
diff --git a/tests/src/test/scala/system/basic/WskRestRuleTests.scala 
b/tests/src/test/scala/system/basic/WskRestRuleTests.scala
new file mode 100644
index 0000000000..b1fe57c63a
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskRestRuleTests.scala
@@ -0,0 +1,44 @@
+/*
+ * 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 system.basic
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.TestUtils.RunResult
+import common.rest.WskRest
+import common.rest.RestResult
+
+@RunWith(classOf[JUnitRunner])
+class WskRestRuleTests extends WskRuleTests {
+  override val wsk: common.rest.WskRest = new WskRest
+
+  override def verifyRuleList(ruleListResult: RunResult,
+                              ruleNameEnable: String,
+                              ruleName: String): org.scalatest.Assertion = {
+    val ruleListResultRest = ruleListResult.asInstanceOf[RestResult]
+    val rules = ruleListResultRest.getBodyListJsObject()
+    val ruleEnable = wsk.rule.get(ruleNameEnable)
+    ruleEnable.getField("status") shouldBe "active"
+    val ruleDisable = wsk.rule.get(ruleName)
+    ruleDisable.getField("status") shouldBe "inactive"
+    rules.exists(rule => RestResult.getField(rule, "name") == ruleNameEnable)
+    rules.exists(rule => RestResult.getField(rule, "name") == ruleName)
+    ruleListResultRest.respData should not include ("Unknown")
+  }
+}
diff --git a/tests/src/test/scala/system/basic/WskRuleTests.scala 
b/tests/src/test/scala/system/basic/WskRuleTests.scala
index e7a2b1e2de..e110c284a7 100644
--- a/tests/src/test/scala/system/basic/WskRuleTests.scala
+++ b/tests/src/test/scala/system/basic/WskRuleTests.scala
@@ -21,7 +21,8 @@ import org.junit.runner.RunWith
 import org.scalatest.junit.JUnitRunner
 import common.TestHelpers
 import common.TestUtils
-import common.Wsk
+import common.TestUtils.RunResult
+import common.BaseWsk
 import common.WskProps
 import common.WskTestHelpers
 import spray.json._
@@ -29,10 +30,10 @@ import spray.json.DefaultJsonProtocol._
 import java.time.Instant
 
 @RunWith(classOf[JUnitRunner])
-class WskRuleTests extends TestHelpers with WskTestHelpers {
+abstract class WskRuleTests extends TestHelpers with WskTestHelpers {
 
   implicit val wskprops = WskProps()
-  val wsk = new Wsk
+  val wsk: BaseWsk
   val defaultAction = TestUtils.getTestActionFilename("wc.js")
   val secondAction = TestUtils.getTestActionFilename("hello.js")
   val testString = "this is a test"
@@ -413,10 +414,15 @@ class WskRuleTests extends TestHelpers with 
WskTestHelpers {
         assetHelper)
 
       wsk.rule.disable(ruleName)
-      val listOutput = wsk.rule.list().stdout.lines
-      listOutput.find(_.contains(ruleName2)).get should (include(ruleName2) 
and include("active"))
-      listOutput.find(_.contains(ruleName)).get should (include(ruleName) and 
include("inactive"))
-      wsk.rule.list().stdout should not include ("Unknown")
+      val ruleListResult = wsk.rule.list()
+      verifyRuleList(ruleListResult, ruleName2, ruleName)
   }
 
+  def verifyRuleList(ruleListResult: RunResult, ruleNameEnable: String, 
ruleName: String) = {
+    val ruleList = ruleListResult.stdout
+    val listOutput = ruleList.lines
+    listOutput.find(_.contains(ruleNameEnable)).get should 
(include(ruleNameEnable) and include("active"))
+    listOutput.find(_.contains(ruleName)).get should (include(ruleName) and 
include("inactive"))
+    ruleList should not include ("Unknown")
+  }
 }


 

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