Scala Test Doesnt Work with Split Routes

Hello,

I have splitted my routes file and I am using macwire for Compile Time DI, my main route file looks something as following

GET / controllers.Application.index
→ /:version/standard standard.Routes

In the standard.routes file

NoDocs

GET /:version/sectionview/list/all controllers.standard.SectionView.allViewList(version: String)

My ScalaTest looks like following

class MetadataSpec extends PlaySpec with BeforeAndAfterAll with OneServerPerSuiteWithComponents {
“myTestSpec” must {
“test multi routes” in {
val Some(result: Future[Result]) = route(app, FakeRequest(GET, “/v1/sectionview/list/all”))
Helpers.status(result) must equal(OK)
}
}

But above returns the page not found error. This works fine if I place this route under main routes file. Can you please suggest?

PS: I have defined custom trait OneServerPerSuiteWithComponents as following as somewith the play provided was not working.

trait OneServerPerSuiteWithComponents
extends BaseOneServerPerSuite
with WithApplicationComponents[InfoserverComponents] {
this: TestSuite =>

override implicit lazy val app: Application = fakeApplication
/**

  • @return the components to be used by the application
    */
    override def createComponents(context: Context): InfoserverComponents = new InfoserverComponents(context)
    }

trait WithApplicationComponents[C <: BuiltInComponents] extends FakeApplicationFactory {
private var _components: C = _

/**

  • @return The current components
    */
    final def components: C = synchronized{_components}

/**

  • @return the components to be used by the application
    */
    def createComponents(context: Context): C

/**

  • @return new application instance and set the components. This must be called for components to be properly set up.
    */
    final def fakeApplication: Application = {
    _components = createComponents(context)
    initialize(_components)
    }

/**

  • Initialize the application from the components. This can be used to do eager instantiation or otherwise
  • set up things.
  • @return the application that will be used for testing
    */
    def initialize(components: C): Application = components.application

/**

  • @return a context to use to create the application.
    */
    def context: ApplicationLoader.Context = {
    val classLoader = ApplicationLoader.getClass.getClassLoader
    val env = new Environment(new java.io.File("."), classLoader, Mode.Test)
    Context.create(env)
    }
    }

whereas in the custom application loader I have following

class InfoserverComponents(context: Context)
extends BuiltInComponentsFromContext(context)
with InfoserverModule
with AssetsComponents
with HttpFiltersComponents {
lazy val router: Router = {
val prefix = “/”
val standardRoutes = wire[root.standard.Routes] withPrefix("/")
wire[Routes]
}
}

Please post your question to Discussions · playframework/playframework · GitHub

More information here: Moving to GitHub Discussions - #2

Actually the Play Framework category should be read only by now… Not sure how you were able to post here.