【问题标题】:Iterating all Play Framework routes in Test在测试中迭代所有 Play Framework 路由
【发布时间】:2015-05-05 06:40:07
【问题描述】:

有没有办法迭代routes 文件中所有描述的服务?需要 URL 和 HTTP 方法。

我需要这个功能来运行一些集成测试。

我正在使用 Play for Java。

【问题讨论】:

    标签: java routes integration-testing playframework-2.3


    【解决方案1】:

    不容易。不久前我设法破解了它(没有scala技术)。我会发布该代码也许它可以使用。

    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;
    }
    

    不用担心.iterator() 显示The method iterator() is ambiguous for the type Seq&lt;Tuple3&lt;String,String,String&gt;&gt;。它在游戏中编译得很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多