|
Play Framework/Scala example source code file (HttpSpec.scala)
The HttpSpec.scala Play Framework example source code
/*
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package play.api.mvc
import org.specs2.mutable._
object HttpSpec extends Specification {
"HTTP" title
val headers = new Headers {
val data = Seq(("a", Seq("a1", "a2")), ("b", Seq("b1", "b2")))
}
"Headers" should {
"return the header value associated with a" in {
headers.get("a") must beSome("a1")
}
"return the header values associated with b" in {
headers.getAll("b") must be_==(Seq("b1", "b2"))
}
"not return an empty sequence of values associated with an unknown key" in {
headers.getAll("z") must beEmpty
}
"should return all keys" in {
headers.keys must be_==(Set("a", "b"))
}
"should return a simple map" in {
headers.toSimpleMap must be_==(Map("a" -> "a1", "b" -> "b1"))
}
"return the value from a map by case insensitive" in {
(headers.toMap.get("A") must_== Some(Seq("a1", "a2"))) and
(headers.toMap.get("b") must_== Some(Seq("b1", "b2")))
}
"return the value from a simple map by case insensitive" in {
(headers.toSimpleMap.get("A") must beSome("a1")) and
(headers.toSimpleMap.get("b") must beSome("b1"))
}
}
"Cookies" should {
"merge two cookies" in {
val cookies = Seq(
Cookie("foo", "bar"),
Cookie("bar", "qux"))
Cookies.merge("", cookies) must ===("foo=bar; Path=/; HTTPOnly; bar=qux; Path=/; HTTPOnly")
}
"merge and remove duplicates" in {
val cookies = Seq(
Cookie("foo", "bar"),
Cookie("foo", "baz"),
Cookie("foo", "bar", domain=Some("Foo")),
Cookie("foo", "baz", domain=Some("FoO")),
Cookie("foo", "baz", secure=true),
Cookie("foo", "baz", httpOnly=false),
Cookie("foo", "bar", path="/blah"),
Cookie("foo", "baz", path="/blah"))
Cookies.merge("", cookies) must ===(
"foo=baz; Path=/; Domain=FoO; HTTPOnly" + "; " + // Cookie("foo", "baz", domain=Some("FoO"))
"foo=baz; Path=/" + "; " + // Cookie("foo", "baz", httpOnly=false)
"foo=baz; Path=/blah; HTTPOnly" // Cookie("foo", "baz", path="/blah")
)
}
}
}
Other Play Framework source code examplesHere is a short list of links related to this Play Framework HttpSpec.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.