dubeejw commented on a change in pull request #2621: Replace the test cases with REST implementation URL: https://github.com/apache/incubator-openwhisk/pull/2621#discussion_r137960710
########## File path: tests/src/test/scala/common/rest/WskRest.scala ########## @@ -0,0 +1,1614 @@ +/* + * 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 akka.util.Timeout + +import java.io.File +import java.time.Clock +import java.time.Instant +import java.util.Base64 + +import org.apache.commons.io.FileUtils +import org.scalatest.Matchers +import org.scalatest.FlatSpec +import org.scalatest.concurrent.ScalaFutures +import org.scalatest.time.Span.convertDurationToSpan + +import scala.Left +import scala.Right +import scala.collection.JavaConversions.mapAsJavaMap +import scala.collection.mutable.Buffer +import scala.concurrent.duration.Duration +import scala.concurrent.duration.DurationInt +import scala.language.postfixOps +import scala.util.Failure +import scala.util.Success +import scala.util.Try +import scala.util.{Success, Failure} +import scala.concurrent.Future +import scala.concurrent.duration.DurationInt + +import akka.http.scaladsl.model.StatusCode +import akka.http.scaladsl.model.StatusCodes.BadRequest +import akka.http.scaladsl.model.StatusCodes.OK +import akka.http.scaladsl.model.HttpRequest +import akka.http.scaladsl.model.HttpMethod +import akka.http.scaladsl.model.HttpResponse +import akka.http.scaladsl.model.headers.Authorization +import akka.http.scaladsl.model.HttpEntity +import akka.http.scaladsl.model.ContentTypes +import akka.http.scaladsl.Http +import spray.json.JsObject +import spray.json.JsValue +import spray.json.pimpString +import spray.json.DefaultJsonProtocol._ + +import scala.collection.immutable.Seq + +import akka.http.scaladsl.model.StatusCodes.Accepted +import akka.http.scaladsl.model.StatusCodes.BadRequest +import akka.http.scaladsl.model.StatusCodes.NotFound +import akka.http.scaladsl.model.StatusCodes.OK + +import akka.http.scaladsl.model.headers.BasicHttpCredentials +import akka.http.scaladsl.model.Uri +import akka.http.scaladsl.model.Uri.Path + +import akka.http.scaladsl.model.HttpMethods.DELETE +import akka.http.scaladsl.model.HttpMethods.GET +import akka.http.scaladsl.model.HttpMethods.POST +import akka.http.scaladsl.model.HttpMethods.PUT + +import akka.stream.ActorMaterializer +/*import spray.client.pipelining.Get +import spray.client.pipelining.WithTransformerConcatenation +import spray.client.pipelining.addCredentials +import spray.client.pipelining.sendReceive +import spray.http.BasicHttpCredentials +import spray.http.HttpEntity +import spray.http.StatusCode +import spray.http.ContentTypes +import spray.http.HttpRequest +import spray.http.HttpResponse +import spray.http.HttpHeader +import spray.httpx.unmarshalling.FromResponseUnmarshaller +import spray.httpx.unmarshalling.MalformedContent +import spray.httpx.unmarshalling._ +import spray.httpx.PipelineException +import spray.client.pipelining.Put +import spray.client.pipelining.Post +import spray.client.pipelining.Delete*/ +//import spray.json.JsObject +//import spray.json.JsValue +//import spray.json.JsArray +//import spray.json.pimpString +import spray.json._ +import spray.json.DefaultJsonProtocol._ + +import common.TestUtils +import common.TestUtils.SUCCESS_EXIT +import common.TestUtils.DONTCARE_EXIT +import common.TestUtils.ANY_ERROR_EXIT +import common.TestUtils.DONTCARE_EXIT +import common.TestUtils.RunResult +import common.RunWskCmd +import common.WskProps +import common.WaitFor +import common.WskActorSystem +import common.WhiskProperties +import common.DeleteFromCollection +import common.FullyQualifiedNames +import common.ListOrGetFromCollection +import common.HasActivation +import common._ +import common.TestUtils.RunResult + +import whisk.core.entity.ByteSize +import whisk.utils.retry + +class WskRest() extends BaseWsk { + override implicit val action = new WskRestAction("actions") + override implicit val trigger = new WskRestTrigger("triggers") + override implicit val rule = new WskRestRule("rules") + override implicit val activation = new WskRestActivation("activations") + override implicit val pkg = new WskRestPackage("packages") + override implicit val namespace = new WskRestNamespace("namespaces") + override implicit val api = new WskRestApi("apis") + override implicit val apiexperimental = new WskApiExperimental +} + +trait FullyQualifiedNamesRest extends FullyQualifiedNames { + + def getExt(filePath: String)(implicit wp: WskProps) = { + val sep = "." + if (filePath.contains(sep)) filePath.substring(filePath.lastIndexOf(sep), filePath.length()) + else null + } +} + +trait ListOrGetFromCollectionRest extends ListOrGetFromCollection + with FullyQualifiedNamesRest { + self: RunWskRestCmd => + + /** + * List entities in collection. + * + * @param namespace (optional) if specified must be fully qualified namespace + * @param expectedExitCode (optional) the expected exit code for the command + * if the code is anything but DONTCARE_EXIT, assert the code is as expected + */ + override def list( + namespace: Option[String] = None, + limit: Option[Int] = None, + nameSort: Option[Boolean] = None, + expectedExitCode: Int = OK.intValue)( + implicit wp: WskProps): RestResult = { + val NS = if (namespace == None) "" else namespace.get + val (ns, name) = getNamespaceActionName(NS) + + val entPath = if (name != "") Path(s"$basePath/namespaces/$ns/$entityName/$name/") else Path(s"$basePath/namespaces/$ns/$entityName") + println("list path is " + entPath) + var paramMap = Map("skip" -> "0".toString, "docs" -> true.toString) + if (limit != None) + paramMap += ("limit" -> limit.get.toString) + else + paramMap += ("limit" -> "30".toString) + val resp = getWhiskEntity(entPath, paramMap).futureValue + //if (resp == None) { Review comment: Remove commetted out code and `println` calls from this file. ---------------------------------------------------------------- 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
