11package test
22
33import com .wordnik .swagger .core ._
4- import com .wordnik .swagger .core .util .ScalaJsonUtil
5- import com .wordnik .swagger .model .ResourceListing
6- import com .wordnik .swagger .model .ApiDescription
7- import com .wordnik .swagger .model .Operation
8- import com .wordnik .swagger .model .ApiListing
4+ import com .wordnik .swagger .model ._
5+
6+ import org .json4s ._
7+ import org .json4s .JsonDSL ._
8+ import org .json4s .jackson .JsonMethods ._
9+ import org .json4s .jackson .Serialization .{read , write }
910
1011import org .specs2 .mutable ._
1112
@@ -16,21 +17,21 @@ import scala.io._
1617import scala .collection .JavaConverters ._
1718
1819class IntegrationSpec extends Specification {
19- val mapper = ScalaJsonUtil .mapper
20+ implicit val formats = SwaggerSerializers .formats
2021
2122 " Application" should {
2223 " have the proper resource metadata" in {
2324 running(TestServer (3333 )) {
24- val json = Source .fromURL(" http://localhost:3333/api-docs.json " ).mkString
25- val doc = mapper.readValue (json, classOf [ResourceListing ])
25+ val json = Source .fromURL(" http://localhost:3333/api-docs" ).mkString
26+ val doc = parse (json).extract [ResourceListing ]
2627 doc.swaggerVersion must_== (" 1.2" )
2728 }
2829 }
2930
3031 " contain all apis defined in the routes without api key" in {
3132 running(TestServer (3333 )) {
32- val json = Source .fromURL(" http://localhost:3333/api-docs.json " ).mkString
33- val doc = mapper.readValue (json, classOf [ResourceListing ])
33+ val json = Source .fromURL(" http://localhost:3333/api-docs" ).mkString
34+ val doc = parse (json).extract [ResourceListing ]
3435 doc.apis.size must_== (3 )
3536 (doc.apis.map(_.path).toSet &
3637 Set (
@@ -43,8 +44,8 @@ class IntegrationSpec extends Specification {
4344
4445 " contain all operations defined in the pet resource without api key" in {
4546 running(TestServer (3333 )) {
46- val json = Source .fromURL(" http://localhost:3333/api-docs.json /pet" ).mkString
47- val doc = mapper.readValue (json, classOf [ApiListing ])
47+ val json = Source .fromURL(" http://localhost:3333/api-docs/pet" ).mkString
48+ val doc = parse (json).extract [ApiListing ]
4849 (doc.models.get.keys.toSet &
4950 Set (
5051 " Category" ,
@@ -56,58 +57,58 @@ class IntegrationSpec extends Specification {
5657
5758 " contain models without api key" in {
5859 running(TestServer (3333 )) {
59- val json = Source .fromURL(" http://localhost:3333/api-docs.json /pet" ).mkString
60- val doc = mapper.readValue (json, classOf [ApiListing ])
60+ val json = Source .fromURL(" http://localhost:3333/api-docs/pet" ).mkString
61+ val doc = parse (json).extract [ApiListing ]
6162 (doc.apis.map(_.path).toSet &
6263 Set (
63- " /pet.json /findByTags" ,
64- " /pet.json /findByStatus" ,
65- " /pet.json /{id}" )
64+ " /pet/findByTags" ,
65+ " /pet/findByStatus" ,
66+ " /pet/{id}" )
6667 ).size must_== (3 )
6768 }
6869 }
6970
7071 " no apis from store resource without valid api key" in {
7172 running(TestServer (3333 )) {
72- val json = Source .fromURL(" http://localhost:3333/api-docs.json /store" ).mkString
73- val doc = mapper.readValue (json, classOf [ApiListing ])
74- Option (doc.apis) must_== (None )
73+ val json = Source .fromURL(" http://localhost:3333/api-docs/store" ).mkString
74+ val doc = parse (json).extract [ApiListing ]
75+ Option (doc.apis) must_== (Some ( List .empty) )
7576 }
7677 }
7778
7879 " no models from store resource without valid api key" in {
7980 running(TestServer (3333 )) {
80- val json = Source .fromURL(" http://localhost:3333/api-docs.json /store" ).mkString
81- val doc = mapper.readValue (json, classOf [ApiListing ])
81+ val json = Source .fromURL(" http://localhost:3333/api-docs/store" ).mkString
82+ val doc = parse (json).extract [ApiListing ]
8283 doc.models must_== None
8384 }
8485 }
8586
8687 " contain apis from store resource valid api key" in {
8788 running(TestServer (3333 )) {
88- val json = Source .fromURL(" http://localhost:3333/api-docs.json /store?api_key=special-key" ).mkString
89- val doc = mapper.readValue (json, classOf [ApiListing ])
89+ val json = Source .fromURL(" http://localhost:3333/api-docs/store?api_key=special-key" ).mkString
90+ val doc = parse (json).extract [ApiListing ]
9091 doc.apis.map(_.path).size must_== (2 )
9192 }
9293 }
9394
9495 " contain correct models from store resource valid api key" in {
9596 running(TestServer (3333 )) {
96- val json = Source .fromURL(" http://localhost:3333/api-docs.json /store?api_key=special-key" ).mkString
97- val doc = mapper.readValue (json, classOf [ApiListing ])
97+ val json = Source .fromURL(" http://localhost:3333/api-docs/store?api_key=special-key" ).mkString
98+ val doc = parse (json).extract [ApiListing ]
9899 doc.models.get.keys.toSet.size must_== (1 )
99100 }
100101 }
101102
102103 " contain all operations defined in the pet resource with api key" in {
103104 running(TestServer (3333 )) {
104- val json = Source .fromURL(" http://localhost:3333/api-docs.json /pet?api_key=special-key" ).mkString
105- val doc = mapper.readValue (json, classOf [ApiListing ])
105+ val json = Source .fromURL(" http://localhost:3333/api-docs/pet?api_key=special-key" ).mkString
106+ val doc = parse (json).extract [ApiListing ]
106107 (doc.apis.map(_.path).toSet &
107108 Set (
108- " /pet.json /findByTags" ,
109- " /pet.json /findByStatus" ,
110- " /pet.json /{id}" )
109+ " /pet/findByTags" ,
110+ " /pet/findByStatus" ,
111+ " /pet/{id}" )
111112 ).size must_== (3 )
112113 }
113114 }
0 commit comments