mockws

package mockws

Members list

Type members

Classlikes

class FakeAhcResponse(result: Result, body: Array[Byte]) extends Response

A simulated response from the async-http-client.

A simulated response from the async-http-client.

The play.api.libs.ws.ahc.AhcWSResponse is intended to wrap this.

Implementation is mostly based upon org.asynchttpclient.netty.NettyResponse.

We're faking at this level as opposed to the play.api.libs.ws.WSResponse level to preserve any behavior specific to the NingWSResponse which is likely to be used in the real (non-fake) WSClient.

Attributes

Supertypes
trait Response
class Object
trait Matchable
class Any
case class FakeWSRequestHolder(routes: Routes, url: String, method: String, body: WSBody, cookies: Seq[WSCookie], headers: Map[String, Seq[String]], queryString: Map[String, Seq[String]], auth: Option[(String, String, WSAuthScheme)], requestTimeout: Option[Duration], timeoutProvider: TimeoutProvider, filters: Seq[WSRequestFilter])(implicit materializer: Materializer, notFoundBehaviour: RouteNotDefined) extends WSRequest

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait WSRequest
trait WSBodyWritables
trait XMLBodyWritables
trait JsonBodyWritables
trait DefaultBodyWritables
trait StandaloneWSRequest
class Object
trait Matchable
class Any
Show all
case class FakeWSResponseHeaders(status: Int, headers: Map[String, Seq[String]])

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
class MockWS(routes: Routes, shutdownHook: () => Unit)(implicit val materializer: Materializer, notFoundBehaviour: RouteNotDefined) extends WSClient

Mock implementation for the play.api.libs.ws.WSClient. Usage:

Mock implementation for the play.api.libs.ws.WSClient. Usage:

 val ws = MockWS {
   case ("GET", "/") => Action { Ok("index") }
   case ("GET", "/hi") => Action { Ok("world") }
 }

MockWS.Routes is a partial function. It is also possible to combine routes together:

 val index = MockWS.Routes {
   case ("GET", "/") => Action { Ok("index") }
 }
 val hiWorld = MockWS.Routes {
   case ("GET", "/hi") => Action { Ok("world") }
 }
 val ws = MockWS(index orElse hiWorld)

Value parameters

routes

routes defining the mock calls

Attributes

Companion
object
Supertypes
trait WSClient
trait Closeable
trait AutoCloseable
class Object
trait Matchable
class Any
Show all
object MockWS

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
MockWS.type

The trait provides a materializer you need in order to use MockWS and its Action { ... } definitions inside your testclasses.

The trait provides a materializer you need in order to use MockWS and its Action { ... } definitions inside your testclasses.

Mix this trait into the tests where you use MockWS. WARNING: you have to call shutdownHelpers() after usage to avoid memory leaks.

You can also use the object if you dislike traits and like to instead import the functionality.

Example:

class MySpec extends FreeSpec with Matchers with MockWSHelpers with BeforeAndAfterAll {
  ...

 override def afterAll(): Unit = {
   shutdownHelpers()
 }
}

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object MockWSHelpers
object MockWSHelpers extends MockWSHelpers

Tiny helper so that you can import the functionality of MockWSHelper instead of extending your test class with a trait.

Tiny helper so that you can import the functionality of MockWSHelper instead of extending your test class with a trait.

import mockws.MockWSHelpers._

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
case class Route(route: Routes) extends Routes

traces whether a route was called and how many times. Usage:

traces whether a route was called and how many times. Usage:

val route1 = Route {
  case (GET, "/route1") => Action { Ok("") }
}
val route2 = Route {
  case (GET, "/route2") => Action { Ok("") }
}

val ws = MockWS(route1 orElse route2)

await(ws.url("/route1").get())

route1.called == true
route2.called == false

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait PartialFunction[(String, String), EssentialAction]
trait ((String, String)) => EssentialAction
class Object
trait Matchable
class Any
Show all
trait RouteNotDefined extends () => Future[Result]

Attributes

Companion
object
Supertypes
trait () => Future[Result]
class Object
trait Matchable
class Any

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes