Test the application

For integration testing you generally need to replace components which are at the frontier of your system and deeply embedded in your application.

This is can be done with the replace method:

import org.zalando.grafter.syntax.rewriter._

trait Database
object mockDatabase extends Database {
  // mock the database operations
}

// you can also replace the production configuration!
val testConfiguration =
  ApplicationConfig.prod.
    replace[HttpConfig](HttpConfig("localhost", 8080))

// create the application from the test configuration
// and mock the database
val application: Application =
  Application.reader[ApplicationConfig].apply(testConfiguration).
    singletons.
    replace[Database](mockDatabase)

application.startAll

Note: due to a limitation with the rewriting, final case classes with one arguments cannot be replaced!

It is also particularly important to test that the application itself is properly configured.