|
|
@@ -2,7 +2,7 @@ package com.tflucke.webroutes.unit.parsers
|
|
|
|
|
|
import sbt.File
|
|
|
import scala.io.Source
|
|
|
-import com.tflucke.webroutes.RouteDef
|
|
|
+import com.tflucke.webroutes.models.{FullName,Method,RouteDef,URL}
|
|
|
import com.tflucke.webroutes.parsers.PlayParser
|
|
|
import org.scalatest._
|
|
|
import java.io.FileNotFoundException
|
|
|
@@ -25,52 +25,66 @@ class PlayParserTest extends PropSpec with Matchers {
|
|
|
}
|
|
|
|
|
|
val apis = PlayParser.parseFile(userFile)
|
|
|
- val queryApi = apis.find(api => api.fn == "query")
|
|
|
- val addApi = apis.find(api => api.fn == "addUser")
|
|
|
- val getApi = apis.find(api => api.fn == "get")
|
|
|
- val updateApi = apis.find(api => api.fn == "updateUser")
|
|
|
- val deleteApi = apis.find(api => api.fn == "delete")
|
|
|
+ val queryApi = apis.find(api => api.fn == 'query)
|
|
|
+ val addApi = apis.find(api => api.fn == 'addUser)
|
|
|
+ val getApi = apis.find(api => api.fn == 'get)
|
|
|
+ val updateApi = apis.find(api => api.fn == 'updateUser)
|
|
|
+ val deleteApi = apis.find(api => api.fn == 'delete)
|
|
|
|
|
|
property("the users route file should produce a get api") {
|
|
|
getApi should not be None
|
|
|
}
|
|
|
property("the get api should use the GET method") {
|
|
|
- getApi.get.method should be ("GET")
|
|
|
+ getApi.get.method should be (Method.GET)
|
|
|
}
|
|
|
property("the get api should have the correct URL") {
|
|
|
- getApi.get.url should be ("/user/:id")
|
|
|
+ getApi.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("user"), Right('id)), _) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the get api should have the correct package") {
|
|
|
- getApi.get.pack should be ("org.sample.users")
|
|
|
+ getApi.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("org", "sample", "users"), Nil) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the get api should have the UserController") {
|
|
|
- getApi.get.controller should be ("UserController")
|
|
|
+ getApi.get.controller.name should be ("UserController")
|
|
|
}
|
|
|
property("the get api should have return type User") {
|
|
|
- getApi.get.retType should be ("org.sample.users.shared.User")
|
|
|
+ getApi.get.retType should matchPattern {
|
|
|
+ case FullName(Seq("org", "sample", "users", "shared", "User"), Nil) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the get api should have a single Long argument") {
|
|
|
getApi.get.args.size should be (1)
|
|
|
- getApi.get.args(0).replace(" ", "") should be ("id:Long")
|
|
|
+ getApi.get.args(0) should be (('id, FullName("Long")))
|
|
|
}
|
|
|
|
|
|
property("the users route file should produce a query api") {
|
|
|
queryApi should not be None
|
|
|
}
|
|
|
property("the query api should use the GET method") {
|
|
|
- queryApi.get.method should be ("GET")
|
|
|
+ queryApi.get.method should be (Method.GET)
|
|
|
}
|
|
|
property("the query api should have the correct URL") {
|
|
|
- queryApi.get.url should be ("/user")
|
|
|
+ queryApi.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("user")), _) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the query api should have the correct package") {
|
|
|
- queryApi.get.pack should be ("org.sample.users")
|
|
|
+ queryApi.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("org", "sample", "users"), Nil) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the query api should have the UserController") {
|
|
|
- queryApi.get.controller should be ("UserController")
|
|
|
+ queryApi.get.controller.name should be ("UserController")
|
|
|
}
|
|
|
property("the query api should have return type Seq[User]") {
|
|
|
- queryApi.get.retType should be ("Seq[org.sample.users.shared.User]")
|
|
|
+ queryApi.get.retType should matchPattern {
|
|
|
+ case FullName(Seq("Seq"), Seq(
|
|
|
+ FullName(Seq("org", "sample", "users", "shared", "User"), Nil)
|
|
|
+ )) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the query api should have no arguments") {
|
|
|
queryApi.get.args.size should be (0)
|
|
|
@@ -80,71 +94,93 @@ class PlayParserTest extends PropSpec with Matchers {
|
|
|
addApi should not be None
|
|
|
}
|
|
|
property("the add api should use the PUT method") {
|
|
|
- addApi.get.method should be ("PUT")
|
|
|
+ addApi.get.method should be (Method.PUT)
|
|
|
}
|
|
|
property("the add api should have the correct URL") {
|
|
|
- addApi.get.url should be ("/user")
|
|
|
+ addApi.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("user")), _) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the add api should have the correct package") {
|
|
|
- addApi.get.pack should be ("org.sample.users")
|
|
|
+ addApi.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("org", "sample", "users"), Nil) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the add api should have the UserController") {
|
|
|
- addApi.get.controller should be ("UserController")
|
|
|
+ addApi.get.controller.name should be ("UserController")
|
|
|
}
|
|
|
property("the add api should have return type User") {
|
|
|
- addApi.get.retType should be ("org.sample.users.shared.User")
|
|
|
+ addApi.get.retType should matchPattern {
|
|
|
+ case FullName(Seq("org", "sample", "users", "shared", "User"), Nil) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the add api should have only a User body argument") {
|
|
|
- addApi.get.bodyType should be (Some("org.sample.users.shared.User"))
|
|
|
+ addApi.get.bodyType should matchPattern {
|
|
|
+ case Some(FullName(Seq("org", "sample", "users", "shared", "User"), Nil)) =>
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
property("the users route file should produce a update api") {
|
|
|
updateApi should not be None
|
|
|
}
|
|
|
property("the update api should use the POST method") {
|
|
|
- updateApi.get.method should be ("POST")
|
|
|
+ updateApi.get.method should be (Method.POST)
|
|
|
}
|
|
|
property("the update api should have the correct URL") {
|
|
|
- updateApi.get.url should be ("/user/:id")
|
|
|
+ updateApi.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("user"), Right('id)), _) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the update api should have the correct package") {
|
|
|
- updateApi.get.pack should be ("org.sample.users")
|
|
|
+ updateApi.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("org", "sample", "users"), Nil) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the update api should have the UserController") {
|
|
|
- updateApi.get.controller should be ("UserController")
|
|
|
+ updateApi.get.controller.name should be ("UserController")
|
|
|
}
|
|
|
property("the update api should have return type User") {
|
|
|
- updateApi.get.retType should be ("org.sample.users.shared.User")
|
|
|
+ updateApi.get.retType should matchPattern {
|
|
|
+ case FullName(Seq("org", "sample", "users", "shared", "User"), Nil) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the update api should have a Long and User arguments") {
|
|
|
updateApi.get.args.size should be (1)
|
|
|
- updateApi.get.args(0).replace(" ", "") should be ("id:Long")
|
|
|
+ updateApi.get.args(0) should be (('id, FullName("Long")))
|
|
|
}
|
|
|
property("the update api should have only a User body argument") {
|
|
|
- addApi.get.bodyType should be (Some("org.sample.users.shared.User"))
|
|
|
+ addApi.get.bodyType should matchPattern {
|
|
|
+ case Some(FullName(Seq("org", "sample", "users", "shared", "User"), Nil)) =>
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
property("the users route file should produce a delete api") {
|
|
|
deleteApi should not be None
|
|
|
}
|
|
|
property("the delete api should use the DELETE method") {
|
|
|
- deleteApi.get.method should be ("DELETE")
|
|
|
+ deleteApi.get.method should be (Method.DELETE)
|
|
|
}
|
|
|
property("the delete api should have the correct URL") {
|
|
|
- deleteApi.get.url should be ("/user/:id")
|
|
|
+ deleteApi.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("user"), Right('id)), _) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the delete api should have the correct package") {
|
|
|
- deleteApi.get.pack should be ("org.sample.users")
|
|
|
+ deleteApi.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("org", "sample", "users"), Nil) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the delete api should have the UserController") {
|
|
|
- deleteApi.get.controller should be ("UserController")
|
|
|
+ deleteApi.get.controller.name should be ("UserController")
|
|
|
}
|
|
|
property("the delete api should have return type User") {
|
|
|
- deleteApi.get.retType should be ("org.sample.users.shared.User")
|
|
|
+ deleteApi.get.retType should matchPattern {
|
|
|
+ case FullName(Seq("org", "sample", "users", "shared", "User"), Nil) =>
|
|
|
+ }
|
|
|
}
|
|
|
property("the delete api should have a Long and User arguments") {
|
|
|
deleteApi.get.args.size should be (1)
|
|
|
- getApi.get.args(0).replace(" ", "") should be ("id:Long")
|
|
|
+ getApi.get.args(0) should be (('id, FullName("Long")))
|
|
|
}
|
|
|
|
|
|
// "PlayParser" when {
|