Package

mockws

Permalink

package mockws

Visibility
  1. Public
  2. All

Type Members

  1. class FakeAhcResponse extends Response

    Permalink

    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.

  2. case class FakeWSRequestHolder(routes: Routes, url: String, method: String = "GET", body: WSBody = EmptyBody, cookies: Seq[WSCookie] = Seq.empty, headers: Map[String, Seq[String]] = Map.empty, queryString: Map[String, Seq[String]] = Map.empty, auth: Option[(String, String, WSAuthScheme)] = None, requestTimeout: Option[Int] = None, timeoutProvider: TimeoutProvider = ...)(implicit materializer: ActorMaterializer, notFoundBehaviour: RouteNotDefined) extends WSRequest with Product with Serializable

    Permalink
  3. case class FakeWSResponseHeaders(status: Int, headers: Map[String, Seq[String]]) extends Product with Serializable

    Permalink
  4. class MockWS extends WSClient

    Permalink

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

    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)
  5. trait MockWSHelpers extends AnyRef

    Permalink

    The trait provides a materializer you need in order to use MockWS and its Action { ...

    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()
      }
    }
  6. case class Route(route: Routes) extends Routes with Product with Serializable

    Permalink

    traces whether a route was called and how many times.

    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
  7. trait RouteNotDefined extends () ⇒ Future[Result]

    Permalink
  8. trait TimeoutProvider extends AnyRef

    Permalink

Value Members

  1. object FakeWSResponseHeaders extends Serializable

    Permalink
  2. object MockWS

    Permalink
  3. object MockWSHelpers extends MockWSHelpers

    Permalink

    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._
  4. object RouteNotDefined

    Permalink
  5. object SchedulerExecutorServiceTimeoutProvider extends TimeoutProvider

    Permalink

Ungrouped