Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:20:09+00:00 2026-06-14T09:20:09+00:00

I have a specs2 test which uses a FakeApplication and an embedded mongodb database.

  • 0

I have a specs2 test which uses a FakeApplication and an embedded mongodb database.

def inMemoryMongoDatabase(name: String = "default"): Map[String, String] = {
    val dbname: String = "play-test-" + scala.util.Random.nextInt
    Map(
        ("mongodb." + name + ".db" -> dbname),
        ("mongodb." + name + ".port" -> EmbeddedMongoTestPort.toString))
}

override def around[T <% Result](t: => T) = {
    running(FakeApplication(additionalConfiguration = inMemoryMongoDatabase(), additionalPlugins = Seq("se.radley.plugin.salat.SalatPlugin"))) {
        t // execute t inside a http session
    }
}

The FakeApplication uses the default application.conf configuration in the conf directory and additional configuration for the test databases that are created for each test.
This was working find until we setup a mongodb replicat set. Now the application.conf contains configuration for this replicat set

mongodb.default.replicaset {
host1.host = "localhost"
host1.port = 27017
host2.host = "localhost"
host2.port = 27018
host3.host = "localhost"
host3.port = 27019
}

As the FakeApplication uses the default configuration the tests fail because the hosts of the replicaset cannot be found. I want to have a different configuration for my tests, basically remove the mongodb.default.replicaset entry. If mongodb.default.replicaset were a simple Map[String, String] that would be easy as I could just add it to the additonalConfiguration but when I try to do that it fails because the expected value type is not a String but an Object. I have also tried to provide a separate test.conf file to the FakeApplication via the path parameter.

override def around[T <% Result](t: => T) = {
    running(FakeApplication(path = new java.io.File("conf/test.conf"), additionalConfiguration = inMemoryMongoDatabase(), additionalPlugins = Seq("se.radley.plugin.salat.SalatPlugin"))) {
        t // execute t inside a http session
    }
}

That didn’t work either as it didn’t load any config.

I would greatly appreciate any help. Thanks.

Chris

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:20:10+00:00Added an answer on June 14, 2026 at 9:20 am

    The problem is how to specify the test.conf file when running an intergration test using Play’s FakeAppication. In my integration test I cannot call play -Dconfig.file=conf/test.conf.

    What I managed to do is this:

    object FakeSalatApp extends Around {
    
     def EmbeddedMongoTestPort: Int = 27028
    
     def inMemoryMongoDatabase(name: String = "default"): Map[String, String] = {
       val dbname: String = "play-test-" + scala.util.Random.nextInt
       Map(
         ("mongodb." + name + ".db" -> dbname),
         ("mongodb." + name + ".port" -> EmbeddedMongoTestPort.toString),
         ("mongodb." + name + ".replicaset.host1.host" -> "localhost"),
         ("mongodb." + name + ".replicaset.host1.port" -> EmbeddedMongoTestPort.toString),
         ("mongodb." + name + ".replicaset.host2.host" -> "localhost"),
         ("mongodb." + name + ".replicaset.host2.port" -> (EmbeddedMongoTestPort + 1).toString),
         ("mongodb." + name + ".replicaset.host3.host" -> "localhost"),
         ("mongodb." + name + ".replicaset.host3.port" -> (EmbeddedMongoTestPort + 2).toString))
      }
    
     override def around[T <% Result](t: => T) = {
       running(FakeApplication(additionalConfiguration = inMemoryMongoDatabase(), additionalPlugins = Seq("se.radley.plugin.salat.SalatPlugin"))) {
         t // execute t inside a http session
       }
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

RSpec newbie here. I'm trying to test my models, which have methods that uses
I have written a ScalaCheck test case within Specs2. The test case gives up
I have a section of my test suite which runs a bunch of really
I have an Android application which uses the NDK to execute a large amount
I have the following method: def save(entity: A): Either[List[Error],A] + {.... which I want
I have a script which you can pass test suites as parameters to: $
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.