|
|
@@ -0,0 +1,506 @@
|
|
|
+package com.tflucke.webroutes.unit.parsers
|
|
|
+
|
|
|
+import sbt.{File,Logger}
|
|
|
+import com.tflucke.webroutes.models.{FullName,Method,URL}
|
|
|
+import URL.{EmbeddedSymbol,QuerySymbol}
|
|
|
+import com.tflucke.webroutes.models.URL.PathStep
|
|
|
+import com.tflucke.webroutes.parsers.PlayParser
|
|
|
+import org.scalatest.{PropSpec,Matchers}
|
|
|
+
|
|
|
+class PlayExampleRouteTest extends PropSpec with Matchers {
|
|
|
+ def makeRouteFile(name: String): File =
|
|
|
+ new File(getClass.getClassLoader.getResource(name).getPath)
|
|
|
+
|
|
|
+ val apis = PlayParser.parseFile(makeRouteFile("play-examples-route"),
|
|
|
+ Logger.Null)
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api =>
|
|
|
+ api.fn == 'show && api.controller == 'Clients
|
|
|
+ )
|
|
|
+ property("Clients.show route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Clients.show route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Clients.show route should use the path /clients/:id") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("clients"),
|
|
|
+ Right(EmbeddedSymbol("id", _))), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Clients.show route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Clients.show route should use the Clients controller") {
|
|
|
+ api.get.controller.name should be ("Clients")
|
|
|
+ }
|
|
|
+ property("Clients.show route should use the show function") {
|
|
|
+ api.get.fn.name should be ("show")
|
|
|
+ }
|
|
|
+ property("Clients.show route should have a single Long argument") {
|
|
|
+ api.get.args.size should be (1)
|
|
|
+ api.get.args(0) should be (('id, FullName("Long"), None))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api =>
|
|
|
+ api.fn == 'display && api.controller == 'Clients
|
|
|
+ )
|
|
|
+ property("Clients.display route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Clients.display route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Clients.display route should use the path /clients/display/:id") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _,
|
|
|
+ Seq(Left(""),
|
|
|
+ Left("clients"),
|
|
|
+ Left("display"),
|
|
|
+ Right(EmbeddedSymbol("id", _))), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Clients.display route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Clients.display route should use the Clients controller") {
|
|
|
+ api.get.controller.name should be ("Clients")
|
|
|
+ }
|
|
|
+ property("Clients.display route should use the display function") {
|
|
|
+ api.get.fn.name should be ("display")
|
|
|
+ }
|
|
|
+ property("Clients.display route should have a single Long argument") {
|
|
|
+ api.get.args.size should be (1)
|
|
|
+ api.get.args(0) should be (('id, FullName("Long"), None))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'newThing)
|
|
|
+ property("Api.newThing route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Api.newThing route should use the POST method") {
|
|
|
+ api.get.method should be (Method.POST)
|
|
|
+ }
|
|
|
+ property("Api.newThing route should use the path /api/new") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("api"), Left("new")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Api.newThing route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Api.newThing route should use the Api controller") {
|
|
|
+ api.get.controller.name should be ("Api")
|
|
|
+ }
|
|
|
+ property("Api.newThing route should use the newThing function") {
|
|
|
+ api.get.fn.name should be ("newThing")
|
|
|
+ }
|
|
|
+ property("Api.newThing route should have no arguments") {
|
|
|
+ api.get.args.size should be (0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'makeThing)
|
|
|
+ property("Api.makeThing route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Api.makeThing route should use the POST method") {
|
|
|
+ api.get.method should be (Method.POST)
|
|
|
+ }
|
|
|
+ property("Api.makeThing route should use the path /api/make") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("api"), Left("make")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Api.makeThing route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Api.makeThing route should use the Api controller") {
|
|
|
+ api.get.controller.name should be ("Api")
|
|
|
+ }
|
|
|
+ property("Api.makeThing route should use the makeThing function") {
|
|
|
+ api.get.fn.name should be ("makeThing")
|
|
|
+ }
|
|
|
+ property("Api.makeThing route should have no arguments") {
|
|
|
+ api.get.args.size should be (0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'listAll)
|
|
|
+ property("Clients.listAll route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Clients.listAll route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Clients.listAll route should use the path /clients/all") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("clients"), Left("all")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Clients.listAll route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Clients.listAll route should use the Clients controller") {
|
|
|
+ api.get.controller.name should be ("Clients")
|
|
|
+ }
|
|
|
+ property("Clients.listAll route should use the listAll function") {
|
|
|
+ api.get.fn.name should be ("listAll")
|
|
|
+ }
|
|
|
+ property("Clients.listAll route should have no arguments") {
|
|
|
+ api.get.args.size should be (0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'download)
|
|
|
+ property("Application.download route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Application.download route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Application.download route should use the path /files/*name") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("files"),
|
|
|
+ Right(EmbeddedSymbol("name", _))), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Application.download route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Application.download route should use the Application controller") {
|
|
|
+ api.get.controller.name should be ("Application")
|
|
|
+ }
|
|
|
+ property("Application.download route should use the download function") {
|
|
|
+ api.get.fn.name should be ("download")
|
|
|
+ }
|
|
|
+ property("Application.download route should have a single String argument") {
|
|
|
+ api.get.args.size should be (1)
|
|
|
+ api.get.args(0) should be (('name, FullName("String"), None))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'show && api.controller == 'Items)
|
|
|
+ property("Items.show route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Items.show route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Items.show route should use the path /items/:id") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("items"),
|
|
|
+ Right(EmbeddedSymbol("id", _))), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Items.show route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Items.show route should use the Items controller") {
|
|
|
+ api.get.controller.name should be ("Items")
|
|
|
+ }
|
|
|
+ property("Items.show route should use the show function") {
|
|
|
+ api.get.fn.name should be ("show")
|
|
|
+ }
|
|
|
+ property("Items.show route should have a single Long argument") {
|
|
|
+ api.get.args.size should be (1)
|
|
|
+ api.get.args(0) should be (('id, FullName("Long"), None))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api =>
|
|
|
+ api.fn == 'homePage && api.controller == 'Application
|
|
|
+ )
|
|
|
+ property("Application.homePage route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Application.homePage route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Application.homePage route should use the path /") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Application.homePage route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Application.homePage route should use the Application controller") {
|
|
|
+ api.get.controller.name should be ("Application")
|
|
|
+ }
|
|
|
+ property("Application.homePage route should use the homePage function") {
|
|
|
+ api.get.fn.name should be ("homePage")
|
|
|
+ }
|
|
|
+ property("Application.homePage route should have no arguments") {
|
|
|
+ api.get.args.size should be (0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'show && api.controller == 'Application)
|
|
|
+ property("Application.show route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Application.show route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Application.show route should use the path /") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Application.show route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Application.show route should use the Application controller") {
|
|
|
+ api.get.controller.name should be ("Application")
|
|
|
+ }
|
|
|
+ property("Application.show route should use the show function") {
|
|
|
+ api.get.fn.name should be ("show")
|
|
|
+ }
|
|
|
+ property("Application.show route should have no arguments") {
|
|
|
+ api.get.args.size should be (0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'display && api.controller == 'Application)
|
|
|
+ property("Application.display route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Application.display route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Application.display route should use the path /") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Application.display route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Application.display route should use the Application controller") {
|
|
|
+ api.get.controller.name should be ("Application")
|
|
|
+ }
|
|
|
+ property("Application.display route should use the display function") {
|
|
|
+ api.get.fn.name should be ("display")
|
|
|
+ }
|
|
|
+ property("Application.display route should have a single String argument") {
|
|
|
+ api.get.args.size should be (1)
|
|
|
+ api.get.args(0) should be (('page, FullName("String"), None))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.controller =='Clients && api.fn == 'list)
|
|
|
+ property("Clients.list route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Clients.list route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Clients.list route should use the path /clients") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("clients")), map)
|
|
|
+ if map("page") == Right(
|
|
|
+ QuerySymbol("page", QuerySymbol.defaultEncoder)
|
|
|
+ ) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Clients.list route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Clients.list route should use the Clients controller") {
|
|
|
+ api.get.controller.name should be ("Clients")
|
|
|
+ }
|
|
|
+ property("Clients.list route should use the list function") {
|
|
|
+ api.get.fn.name should be ("list")
|
|
|
+ }
|
|
|
+ property("Clients.list route should have a single Int argument with default") {
|
|
|
+ api.get.args.size should be (1)
|
|
|
+ api.get.args(0) should be (('page, FullName("Int"), Some("1")))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.controller =='Api && api.fn == 'list)
|
|
|
+ property("Api.list route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Api.list route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Api.list route should use the path /api/list-all") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("api"), Left("list-all")), map)
|
|
|
+ if map("version") == Right(
|
|
|
+ QuerySymbol("version", QuerySymbol.optionEncoder)
|
|
|
+ ) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Api.list route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Api.list route should use the Api controller") {
|
|
|
+ api.get.controller.name should be ("Api")
|
|
|
+ }
|
|
|
+ property("Api.list route should use the list function") {
|
|
|
+ api.get.fn.name should be ("list")
|
|
|
+ }
|
|
|
+ property("Api.list route should have a single Optional argument") {
|
|
|
+ api.get.args.size should be (1)
|
|
|
+ api.get.args(0) should be (('version, FullName("Option[String]"), None))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'redirect)
|
|
|
+ property("Default.redirect route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Default.redirect route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Default.redirect route should use the path /about") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("about")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Default.redirect route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Default.redirect route should use the Default controller") {
|
|
|
+ api.get.controller.name should be ("Default")
|
|
|
+ }
|
|
|
+ property("Default.redirect route should use the redirect function") {
|
|
|
+ api.get.fn.name should be ("redirect")
|
|
|
+ }
|
|
|
+ property("Default.redirect route should have no arguments") {
|
|
|
+ api.get.args.size should be (0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'notFound)
|
|
|
+ property("Default.notFound route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Default.notFound route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Default.notFound route should use the path /orders") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("orders")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Default.notFound route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Default.notFound route should use the Default controller") {
|
|
|
+ api.get.controller.name should be ("Default")
|
|
|
+ }
|
|
|
+ property("Default.notFound route should use the notFound function") {
|
|
|
+ api.get.fn.name should be ("notFound")
|
|
|
+ }
|
|
|
+ property("Default.notFound route should have no arguments") {
|
|
|
+ api.get.args.size should be (0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'error)
|
|
|
+ property("Default.error route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Default.error route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Default.error route should use the path /clients") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("clients")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Default.error route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Default.error route should use the Default controller") {
|
|
|
+ api.get.controller.name should be ("Default")
|
|
|
+ }
|
|
|
+ property("Default.error route should use the error function") {
|
|
|
+ api.get.fn.name should be ("error")
|
|
|
+ }
|
|
|
+ property("Default.error route should have no arguments") {
|
|
|
+ api.get.args.size should be (0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ val api = apis.find(api => api.fn == 'todo)
|
|
|
+ property("Default.todo route should parse completely") {
|
|
|
+ api should not be None
|
|
|
+ }
|
|
|
+ property("Default.todo route should use the GET method") {
|
|
|
+ api.get.method should be (Method.GET)
|
|
|
+ }
|
|
|
+ property("Default.todo route should use the path /posts") {
|
|
|
+ api.get.url should matchPattern {
|
|
|
+ case URL(_, _, _, Seq(Left(""), Left("posts")), _) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Default.todo route should use the controllers package") {
|
|
|
+ api.get.pack should matchPattern {
|
|
|
+ case FullName(Seq("controllers"), Nil) =>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ property("Default.todo route should use the Default controller") {
|
|
|
+ api.get.controller.name should be ("Default")
|
|
|
+ }
|
|
|
+ property("Default.todo route should use the todo function") {
|
|
|
+ api.get.fn.name should be ("todo")
|
|
|
+ }
|
|
|
+ property("Default.todo route should have no arguments") {
|
|
|
+ api.get.args.size should be (0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|