如何使用消息文件创建自己的消息Api



在我的游戏框架应用程序中,有一个消息文件,我可以用来定义我自己的消息。例如

##############Application Error messages
error.incorrectBodyType=Incorrect body type. Body type must be JSON
error.incorrectBodyContentInLoginRequest=No Login info found in the request. Check format
error.incorrectUsernameOrPassword = Incorrect username or password
error.unregisteredUser = registration not complete
error.ghostUsername = No record found for the username
error.unauthenticated = You must first sign in
error.unauthorized = You are not permitted
####### Application Success Messages
success.signoutSuccessful = Signout Successful

播放框架使这些消息可供我的Controller使用,我可以像使用messagesApi("error.unauthenticated")(langs.availables(0))一样使用它们。

我无法弄清楚如何在单元测试中使用messages文件。我正在使用编译时注入,并正在创建我自己的所需类实例。要创建MessagesApi,有一个DefaultMessagesApi方法,但它需要map,而不是File

我可以在我的单元测试中创建消息,如下所示,但我必须复制将消息从文件复制到此messages map

val messagesApi = new DefaultMessagesApi( //takes map of maps. the first is the language file, the 2nd is the map between message title and description
    Map("en" -> //the language file
      Map("error.incorrectBodyType" -> "Incorrect body type. Body type must be JSON",
        "error.incorrectUsernameOrPassword"->"Incorrect username or password",
        "error.incorrectBodyContentInLoginRequest"->"No Login info found in the request. Check format", //map between message title and description
        "error.unregisteredUser" -> "registration not complete",
        "error.ghostUsername" -> "No record found for the username",
        "success.signoutSuccessful" -> "Signout Successful",
        "error.unauthenticated" -> "You must first sign in",
        "error.unauthorized" -> "You are not permitted")
    )
  )

有没有办法读取messages文件并在测试用例中使用它?

我的测试用例已经扩展OneAppPerSuiteWithComponents .我使用了已经可用的OneAppPerSuiteWithComponents components.messagesApi并从messages文件中读取

最新更新