alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (NingWSSpec.scala)

This example Play Framework source code file (NingWSSpec.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

bar, foo, get, lib, library, mockito, ningwsrequest, ningwsrequestholder, ningwsresponse, ningwsspec, play, play framework, seq, specification, web service, ws

The NingWSSpec.scala Play Framework example source code

package play.libs.ws.ning

import scala.collection.JavaConverters._

import org.specs2.mock.Mockito
import org.specs2.mutable._

import com.ning.http.client.{FluentCaseInsensitiveStringsMap, Response}

object NingWSSpec extends Specification with Mockito {

  val emptyMap = new java.util.HashMap[String, java.util.Collection[String]]

  "NingWSRequestHolder" should {

    "set virtualHost correctly" in {
      val client = mock[NingWSClient]
      val holder = new NingWSRequestHolder(client, "http://example.com")
      holder.setVirtualHost("foo.com")
      val actual = holder.getVirtualHost
      actual must beEqualTo("foo.com")
    }

  }

  "NingWSRequest" should {

    "should respond to getMethod" in {
      val client = mock[NingWSClient]
      val request : NingWSRequest = new NingWSRequest(client, "GET", "", emptyMap, emptyMap)
      request.getMethod must be_==("GET")
    }

    "should set virtualHost appropriately" in {
      val client = mock[NingWSClient]
      val request = new NingWSRequest(client, "GET", "", emptyMap, emptyMap)
      request.setVirtualHost("foo.com")
      val actual = request.getBuilder().build().getVirtualHost()
      actual must beEqualTo("foo.com")
    }

  }

  "NingWSResponse" should {

    "should get headers map which retrieves headers case insensitively" in {
      val srcResponse = mock[Response]
      val srcHeaders = new FluentCaseInsensitiveStringsMap()
        .add("Foo", "a")
        .add("foo", "b")
        .add("FOO", "b")
        .add("Bar", "baz")
      srcResponse.getHeaders returns srcHeaders
      val response = new NingWSResponse(srcResponse)
      val headers = response.getAllHeaders
      headers.get("foo").asScala must_== Seq("a", "b", "b")
      headers.get("BAR").asScala must_== Seq("baz")
    }

  }

}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework NingWSSpec.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.