[英]Iterating all Play Framework routes in Test
Is there any way to Iterate all described services in routes
file? 有没有办法迭代
routes
文件中所有描述的服务? URL and HTTP methods are needed. 需要URL和HTTP方法。
I need this feature for running some integration test. 我需要此功能来运行一些集成测试。
I am using Play for Java. 我正在使用Play for Java。
Not easily. 不容易。 I managed to hack my way through it a while ago(no scala know-how).
我不久前设法破解了它(没有scala专有技术)。 I'll post that code maybe it can be of use.
我会发布该代码也许它可以使用。
public static List<String[]> parseRoutes() {
scala.Option<play.core.Router.Routes> option = Play.application().getWrappedApplication().routes();
if (option.isDefined()) {
play.core.Router.Routes routes = option.get();
scala.collection.Seq<scala.Tuple3<String, String, String>> doc = routes.documentation();
scala.collection.Iterator<scala.Tuple3<String, String, String>> it = doc.iterator();
List<String[]> listOfRoutes = new ArrayList<String[]>();
while(it.hasNext()) {
scala.Tuple3<String, String, String> tuple = it.next();
//tuple._1() is the method and tuple._2() the url... tuple._3() is the controller name
String[] route = {tuple._1(), tuple._2()};
listOfRoutes.add(route);
Logger.debug("route -> " + Arrays.toString(route));
}
return listOfRoutes;
}
return null;
}
Don't worry about the .iterator()
showing a The method iterator() is ambiguous for the type Seq<Tuple3<String,String,String>>
. 不要担心
.iterator()
显示一个The method iterator() is ambiguous for the type Seq<Tuple3<String,String,String>>
。 It compiles just fine in play. 它在游戏中编译得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.