Skip to content

Commit 2b9376b

Browse files
committed
updated tests, merged with 2.11 branch
1 parent deb2ba4 commit 2b9376b

File tree

9 files changed

+161
-75
lines changed

9 files changed

+161
-75
lines changed

samples/java-play2/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ more about both the spec and the framework at http://swagger.wordnik.com. For m
66
about Wordnik's APIs, please visit http://developer.wordnik.com. There is an online version of this
77
server at http://petstore.swagger.wordnik.com/api/api-docs.json
88

9-
## Version compatibility
10-
=======
11-
This version is compatible with Play 2.3.x and Swagger 1.3.10
12-
139
### To build from source
1410
Please follow instructions to build the top-level [swagger-core project](https://github.com/wordnik/swagger-core)
1511

@@ -19,14 +15,14 @@ The swagger-play2 module lives in maven central:
1915
```scala
2016
val appDependencies: Seq[sbt.ModuleID] = Seq(
2117
/* your other dependencies */
22-
"com.wordnik" %% "swagger-play2" % "1.3.10"
18+
"com.wordnik" %% "swagger-play2" % "1.3.10-SNAPSHOT"
2319
)
2420
```
2521

2622
You can run the sample app as such:
2723

2824
````
29-
sbt run
25+
play run
3026
````
3127

32-
The application will listen on port 9000 and respond to `http://localhost:9000/api-docs`
28+
The application will listen on port 9000 and respond to `http://localhost:9000/api-docs.json`

samples/java-play2/conf/routes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ GET /api-docs controllers.ApiHelpController.getResources
99

1010
# OPTIONS /*wholepath controllers.PetApiController.getOptions(wholepath)
1111

12+
GET /api-docs/admin controllers.ApiHelpController.getResource(path = "/admin")
13+
GET /admin/health controllers.HealthController.getHealth
14+
GET /admin/ping controllers.HealthController.ping
15+
1216
GET /api-docs/pet controllers.ApiHelpController.getResource(path = "/pet")
1317
POST /pet controllers.PetApiController.addPet
1418
PUT /pet controllers.PetApiController.updatePet

samples/java-play2/project/Build.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ object ApplicationBuild extends Build {
1818
libraryDependencies ++= appDependencies,
1919
resolvers := Seq(
2020
"Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository",
21+
Resolver.url("Local Ivy Repository", url("file://"+Path.userHome.absolutePath+"/.ivy2/local"))(Resolver.ivyStylePatterns),
2122
"sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
2223
"sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases",
2324
"java-net" at "http://download.java.net/maven/2",
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package test
2+
3+
import com.wordnik.swagger.core._
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}
10+
11+
import org.specs2.mutable._
12+
13+
import play.api.test._
14+
import play.api.test.Helpers._
15+
16+
import scala.io._
17+
import scala.collection.JavaConverters._
18+
19+
class IntegrationSpec extends Specification {
20+
implicit val formats = SwaggerSerializers.formats
21+
22+
"Application" should {
23+
"have the proper resource metadata" in {
24+
running(TestServer(3333)) {
25+
val json = Source.fromURL("http://localhost:3333/api-docs").mkString
26+
val doc = parse(json).extract[ResourceListing]
27+
doc.swaggerVersion must_==("1.2")
28+
}
29+
}
30+
31+
"contain all apis defined in the routes without api key" in {
32+
running(TestServer(3333)) {
33+
val json = Source.fromURL("http://localhost:3333/api-docs").mkString
34+
val doc = parse(json).extract[ResourceListing]
35+
doc.apis.size must_==(3)
36+
(doc.apis.map(_.path).toSet &
37+
Set(
38+
"/admin",
39+
"/pet",
40+
"/user")
41+
).size must_==(3)
42+
}
43+
}
44+
45+
"contain all operations defined in the pet resource without api key" in {
46+
running(TestServer(3333)) {
47+
val json = Source.fromURL("http://localhost:3333/api-docs/pet").mkString
48+
val doc = parse(json).extract[ApiListing]
49+
(doc.models.get.keys.toSet &
50+
Set(
51+
"Category",
52+
"Tag",
53+
"Pet")
54+
).size must_==(3)
55+
}
56+
}
57+
58+
"contain models without api key" in {
59+
running(TestServer(3333)) {
60+
val json = Source.fromURL("http://localhost:3333/api-docs/pet").mkString
61+
val doc = parse(json).extract[ApiListing]
62+
(doc.apis.map(_.path).toSet &
63+
Set(
64+
"/pet/findByTags",
65+
"/pet/findByStatus",
66+
"/pet/{id}")
67+
).size must_==(3)
68+
}
69+
}
70+
71+
"no apis from store resource without valid api key" in {
72+
running(TestServer(3333)) {
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))
76+
}
77+
}
78+
79+
"no models from store resource without valid api key" in {
80+
running(TestServer(3333)) {
81+
val json = Source.fromURL("http://localhost:3333/api-docs/store").mkString
82+
val doc = parse(json).extract[ApiListing]
83+
doc.models must_==None
84+
}
85+
}
86+
87+
"contain apis from store resource valid api key" in {
88+
running(TestServer(3333)) {
89+
val json = Source.fromURL("http://localhost:3333/api-docs/store?api_key=special-key").mkString
90+
val doc = parse(json).extract[ApiListing]
91+
doc.apis.map(_.path).size must_==(2)
92+
}
93+
}
94+
95+
"contain correct models from store resource valid api key" in {
96+
running(TestServer(3333)) {
97+
val json = Source.fromURL("http://localhost:3333/api-docs/store?api_key=special-key").mkString
98+
val doc = parse(json).extract[ApiListing]
99+
doc.models.get.keys.toSet.size must_==(1)
100+
}
101+
}
102+
103+
"contain all operations defined in the pet resource with api key" in {
104+
running(TestServer(3333)) {
105+
val json = Source.fromURL("http://localhost:3333/api-docs/pet?api_key=special-key").mkString
106+
val doc = parse(json).extract[ApiListing]
107+
(doc.apis.map(_.path).toSet &
108+
Set(
109+
"/pet/findByTags",
110+
"/pet/findByStatus",
111+
"/pet/{id}")
112+
).size must_==(3)
113+
}
114+
}
115+
}
116+
}

samples/scala-play2/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ server at http://petstore.swagger.wordnik.com/api/api-docs.json
88

99
## Version compatibility
1010
=======
11-
This version is compatible with Play 2.3.x and Swagger 1.3.10
11+
This version is compatible with Play 2.2.0 and Swagger 1.3.10-SNAPSHOT
1212

1313
### To build Swagger from source (optional)
1414
Please follow instructions to build the top-level [swagger-core project](https://github.com/wordnik/swagger-core)
@@ -19,14 +19,14 @@ The swagger-play2 module lives in maven central:
1919
```scala
2020
val appDependencies: Seq[sbt.ModuleID] = Seq(
2121
/* your other dependencies */
22-
"com.wordnik" %% "swagger-play2" % "1.3.10"
22+
"com.wordnik" %% "swagger-play2" % "1.3.10-SNAPSHOT"
2323
)
2424
```
2525

2626
You can run the sample app as such:
2727

2828
````
29-
sbt run
29+
play run
3030
````
3131

3232
The application will listen on port 9000 and respond to `http://localhost:9000/api-docs`

samples/scala-play2/conf/routes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ GET /pet/:id @controllers.PetApiController.getPetById(id)
2323

2424
GET /api-docs/store controllers.ApiHelpController.getResource(path = "/store")
2525
POST /store/order controllers.StoreApiController.placeOrder
26-
GET /store/order controllers.StoreApiController.getOrders(isComplete: Boolean)
26+
GET /store/order controllers.StoreApiController.getOrders(isComplete:Boolean)
2727
GET /store/order/:orderId controllers.StoreApiController.getOrderById(orderId)
2828
DELETE /store/order/:orderId controllers.StoreApiController.deleteOrder(orderId)
2929

samples/scala-play2/project/Build.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ object ApplicationBuild extends Build {
1818
libraryDependencies ++= appDependencies,
1919
resolvers := Seq(
2020
"Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository",
21+
Resolver.url("Local Ivy Repository", url("file://"+Path.userHome.absolutePath+"/.ivy2/local"))(Resolver.ivyStylePatterns),
2122
"sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
2223
"sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases",
2324
"java-net" at "http://download.java.net/maven/2",

samples/scala-play2/test/ApplicationSpec.scala

Lines changed: 0 additions & 33 deletions
This file was deleted.

samples/scala-play2/test/IntegrationSpec.scala

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package test
22

33
import 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

1011
import org.specs2.mutable._
1112

@@ -16,21 +17,21 @@ import scala.io._
1617
import scala.collection.JavaConverters._
1718

1819
class 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

Comments
 (0)