diff options
author | Johannes Rudolph <johannes_rudolph@gmx.de> | 2012-05-30 16:31:25 +0200 |
---|---|---|
committer | Johannes Rudolph <johannes_rudolph@gmx.de> | 2012-05-30 16:31:25 +0200 |
commit | 6ad410959593435da5c5def4bf5c276ad99a1412 (patch) | |
tree | 2c1747164e9f9c05fc8ec76d6e37b050dd0a9c50 /src/test/scala | |
parent | bfec79404862911e7b33a377f91f4ae548d67f10 (diff) | |
download | spray-json-6ad410959593435da5c5def4bf5c276ad99a1412.tar.gz spray-json-6ad410959593435da5c5def4bf5c276ad99a1412.tar.bz2 spray-json-6ad410959593435da5c5def4bf5c276ad99a1412.zip |
added some tests from the json-path web-page to check against a 'real' example
Diffstat (limited to 'src/test/scala')
-rw-r--r-- | src/test/scala/cc/spray/json/JsonPathTests.scala | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/test/scala/cc/spray/json/JsonPathTests.scala b/src/test/scala/cc/spray/json/JsonPathTests.scala new file mode 100644 index 0000000..28e25b9 --- /dev/null +++ b/src/test/scala/cc/spray/json/JsonPathTests.scala @@ -0,0 +1,56 @@ +/* + * Tests imported from http://code.google.com/p/json-path/ to + * test some 'real-world' examples. json-path is licensed under + * the Apache 2 license. http://www.apache.org/licenses/LICENSE-2.0 + */ +package cc.spray.json + +import org.specs2.mutable.Specification + +class JsonPathTests extends Specification with SpecHelpers { + import JsonLenses._ + import DefaultJsonProtocol._ + + val json = JsonParser( + """ + |{ "store": { + | "book": [ + | { "category": "reference", + | "author": "Nigel Rees", + | "title": "Sayings of the Century", + | "price": 8.95 + | }, + | { "category": "fiction", + | "author": "Evelyn Waugh", + | "title": "Sword of Honour", + | "price": 12.99, + | "isbn": "0-553-21311-3" + | } + | ], + | "bicycle": { + | "color": "red", + | "price": 19.95 + | } + | } + |} + """.stripMargin) + + "Examples" should { + "All authors" in { + json extract ("store" / "book" andThen elements / "author").get[String] must be_==(Seq("Nigel Rees", "Evelyn Waugh")) + } + "Author of first book" in { + json extract ("store" / "book" andThen element(0) / "author").get[String] must be_==("Nigel Rees") + } + "Books with category 'reference'" in { + json extract ("store" / "book" andThen filter("category".is[String](_ == "reference")) / "title").get[String] must be_==(Seq("Sayings of the Century")) + } + "Books that cost more than 10 USD" in { + json extract ("store" / "book" andThen filter("price".is[Double](_ >= 10)) / "title").get[String] must be_==(Seq("Sword of Honour")) + } + "All books that have isbn" in { + json extract ("store" / "book" andThen filter("isbn".is[JsValue](_ => true)) / "title").get[String] must be_==(Seq("Sword of Honour")) + } + "All prices" in todo + } +} |