|
@@ -0,0 +1,157 @@
|
|
|
|
|
+package name.tflucke.webroutes.unit.parsers
|
|
|
|
|
+
|
|
|
|
|
+import sbt.File
|
|
|
|
|
+import scala.io.Source
|
|
|
|
|
+import name.tflucke.webroutes.RouteDef
|
|
|
|
|
+import name.tflucke.webroutes.parsers.PlayParser
|
|
|
|
|
+import org.scalatest._
|
|
|
|
|
+import java.io.FileNotFoundException
|
|
|
|
|
+
|
|
|
|
|
+class PlayParserTest extends PropSpec with Matchers {
|
|
|
|
|
+ def makeRouteFile(name: String): File = new File(getClass.getClassLoader.getResource(name).getPath)
|
|
|
|
|
+
|
|
|
|
|
+ val emptyFile = makeRouteFile("empty-route")
|
|
|
|
|
+ val noSharedFile = makeRouteFile("no-shared-route")
|
|
|
|
|
+ val nonexistantFile = new File("does-not-exist") /* Cannot load non-existent resource */
|
|
|
|
|
+ val userFile = makeRouteFile("user-route")
|
|
|
|
|
+
|
|
|
|
|
+ property("an empty file should produce an empty list") {
|
|
|
|
|
+ PlayParser().parseFile(emptyFile).size should be (0)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ property("the users route file should produce a list of 5 elements ") {
|
|
|
|
|
+ apis.size should be (5)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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")
|
|
|
|
|
+
|
|
|
|
|
+ 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")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the get api should have the correct URL") {
|
|
|
|
|
+ getApi.get.url should be ("/user/:id")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the get api should have the correct package") {
|
|
|
|
|
+ getApi.get.pack should be ("org.sample.users")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the get api should have the UserController") {
|
|
|
|
|
+ getApi.get.controller should be ("UserController")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the get api should have return type User") {
|
|
|
|
|
+ getApi.get.retType should be ("org.sample.users.shared.User")
|
|
|
|
|
+ }
|
|
|
|
|
+ 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")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the query api should have the correct URL") {
|
|
|
|
|
+ queryApi.get.url should be ("/user")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the query api should have the correct package") {
|
|
|
|
|
+ queryApi.get.pack should be ("org.sample.users")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the query api should have the UserController") {
|
|
|
|
|
+ queryApi.get.controller should be ("UserController")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the query api should have return type Seq[User]") {
|
|
|
|
|
+ queryApi.get.retType should be ("Seq[org.sample.users.shared.User]")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the query api should have no arguments") {
|
|
|
|
|
+ queryApi.get.args.size should be (0)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ property("the users route file should produce a add api") {
|
|
|
|
|
+ addApi should not be None
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the add api should use the PUT method") {
|
|
|
|
|
+ addApi.get.method should be ("PUT")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the add api should have the correct URL") {
|
|
|
|
|
+ addApi.get.url should be ("/user")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the add api should have the correct package") {
|
|
|
|
|
+ addApi.get.pack should be ("org.sample.users")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the add api should have the UserController") {
|
|
|
|
|
+ addApi.get.controller should be ("UserController")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the add api should have return type User") {
|
|
|
|
|
+ addApi.get.retType should be ("org.sample.users.shared.User")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the add api should have only a User argument") {
|
|
|
|
|
+ addApi.get.args.size should be (1)
|
|
|
|
|
+ addApi.get.args(0).replace(" ", "") should be ("_body:org.sample.users.shared.User")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the update api should have the correct URL") {
|
|
|
|
|
+ updateApi.get.url should be ("/user/:id")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the update api should have the correct package") {
|
|
|
|
|
+ updateApi.get.pack should be ("org.sample.users")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the update api should have the UserController") {
|
|
|
|
|
+ updateApi.get.controller should be ("UserController")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the update api should have return type User") {
|
|
|
|
|
+ updateApi.get.retType should be ("org.sample.users.shared.User")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the update api should have a Long and User arguments") {
|
|
|
|
|
+ updateApi.get.args.size should be (2)
|
|
|
|
|
+ updateApi.get.args(0).replace(" ", "") should be ("id:Long")
|
|
|
|
|
+ updateApi.get.args(1).replace(" ", "") should be ("_body:org.sample.users.shared.User")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the delete api should have the correct URL") {
|
|
|
|
|
+ deleteApi.get.url should be ("/user/:id")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the delete api should have the correct package") {
|
|
|
|
|
+ deleteApi.get.pack should be ("org.sample.users")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the delete api should have the UserController") {
|
|
|
|
|
+ deleteApi.get.controller should be ("UserController")
|
|
|
|
|
+ }
|
|
|
|
|
+ property("the delete api should have return type User") {
|
|
|
|
|
+ deleteApi.get.retType should be ("org.sample.users.shared.User")
|
|
|
|
|
+ }
|
|
|
|
|
+ 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")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // "PlayParser" when {
|
|
|
|
|
+ // "given a non-existent file" should {
|
|
|
|
|
+ // "produce FileNotFoundException" in {
|
|
|
|
|
+ // assertThrows[FileNotFoundException] {
|
|
|
|
|
+ // PlayParser().parseFile(nonexistantFile)
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+}
|