This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
François LAROCHE
committed
Feb 14, 2017
1 parent
5111816
commit 0787941
Showing
6 changed files
with
147 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
play-2.5/swagger-play2/test/PlayDelegatedApiScannerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import io.swagger.config.ScannerFactory | ||
import org.specs2.mock.Mockito | ||
import org.specs2.mutable._ | ||
import play.modules.swagger._ | ||
import play.routes.compiler.Route | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
class PlayDelegatedApiScannerSpec extends Specification with Mockito { | ||
|
||
val routes: List[Route] = play.modules.swagger.SwaggerPluginHelper.parseRoutes( | ||
"delegation", | ||
"", | ||
_ => {}, | ||
Thread.currentThread().getContextClassLoader) | ||
|
||
|
||
val routesRules: Map[String, Route] = Map(routes.map { route: Route => | ||
s"${route.call.packageName}.${route.call.controller}$$.${route.call.method}" -> route | ||
}: _*) | ||
|
||
|
||
val swaggerConfig = new PlaySwaggerConfig() | ||
swaggerConfig.setBasePath("") | ||
swaggerConfig.setHost("127.0.0.1") | ||
|
||
PlayConfigFactory.setConfig(swaggerConfig) | ||
|
||
var scanner = new PlayApiScanner() | ||
ScannerFactory.setScanner(scanner) | ||
val route = new RouteWrapper(routesRules.asJava) | ||
RouteFactory.setRoute(route) | ||
|
||
|
||
"route parsing" should { | ||
"separate delegated paths correctly" in { | ||
|
||
val urls = ApiListingCache.listing("", "127.0.0.1").get.getPaths.keySet().asScala | ||
|
||
urls must contain("/api/all") | ||
urls must contain("/api/my/action") | ||
urls must contain("/api/subdelegated/all") | ||
urls must contain("/api/subdelegated/my/action") | ||
urls must contain("/api/subdelegated") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-> /subdelegated subdelegated.Routes | ||
|
||
GET /my/action testdata.DelegatedController.list | ||
GET /all testdata.DelegatedController.list2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-> /api delegated.Routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
GET /my/action testdata.DelegatedController.list3 | ||
GET /all testdata.DelegatedController.list4 | ||
GET / testdata.DelegatedController.list5 |
24 changes: 24 additions & 0 deletions
24
play-2.5/swagger-play2/test/testdata/DelegatedController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package testdata | ||
|
||
import io.swagger.annotations.{Api, ApiOperation} | ||
import play.api.mvc.{Action, Controller} | ||
|
||
@Api | ||
object DelegatedController extends Controller { | ||
|
||
@ApiOperation(value = "list") | ||
def list = Action { _ => Ok("test case")} | ||
|
||
@ApiOperation(value = "list2") | ||
def list2 = Action { _ => Ok("test case")} | ||
|
||
@ApiOperation(value = "list3") | ||
def list3 = Action { _ => Ok("test case")} | ||
|
||
@ApiOperation(value = "list4") | ||
def list4 = Action { _ => Ok("test case")} | ||
|
||
@ApiOperation(value = "list5") | ||
def list5 = Action { _ => Ok("test case")} | ||
|
||
} |