You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by du...@apache.org on 2017/10/31 17:09:46 UTC

[incubator-openwhisk] branch master updated: Update the test cases about rules with REST implementation (#2895)

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 1bd8dd7  Update the test cases about rules with REST implementation (#2895)
1bd8dd7 is described below

commit 1bd8dd77db2345945cb436bddf564e60d43f6bde
Author: Vincent <sh...@us.ibm.com>
AuthorDate: Tue Oct 31 13:09:44 2017 -0400

    Update the test cases about rules with REST implementation (#2895)
---
 tests/src/test/scala/common/rest/WskRest.scala     | 19 +++++-----
 .../test/scala/system/basic/WskCliRuleTests.scala  | 28 ++++++++++++++
 .../test/scala/system/basic/WskRestRuleTests.scala | 44 ++++++++++++++++++++++
 .../src/test/scala/system/basic/WskRuleTests.scala | 20 ++++++----
 4 files changed, 95 insertions(+), 16 deletions(-)

diff --git a/tests/src/test/scala/common/rest/WskRest.scala b/tests/src/test/scala/common/rest/WskRest.scala
index 155fa06..d31ade1 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 0000000..6c63077
--- /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 0000000..b1fe57c
--- /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 e7a2b1e..e110c28 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")
+  }
 }

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