4

I want to use Embedded MongoDB with Spring Boot for testing.

Here's the dependency I'm importing:

testCompile('de.flapdoodle.embed:de.flapdoodle.embed.mongo')

Whenever I start the SpringBootTest the EmbeddedMongoAutoConfiguration initializes the MongodExecutable bean and that bean starts to download a zip file (version 3.2.2) from a url. How do I configure it so that it will use the zip file located within my src/test/resources directory?

George
  • 2,820
  • 4
  • 29
  • 56
  • Did you read the comments here: [Embedded MongoDB when running integration tests](https://stackoverflow.com/a/9830861/2313887) ? Essentially *".... It just gathers information about the current operating system and downloads the appropriate platform-specific MongoDB binaries from the internet ..."* which seems to be "by design". If you're looking for "mocking" then you probably want to look elsewhere, as this seems just to be an installer and instance runner. – Neil Lunn May 04 '18 at 01:21

1 Answers1

7

How do I configure it so that it will use the zip file located within my src/test/resources directory?

I don't know that this can be done. My solution has been to have a copy installed (for myself and my team) in the following directory:

Linux : $HOME/.embedmongo/linux/mongodb-linux-x86_64-3.2.2.tgz
Windows : C:\Users\<username>\.embedmongo\win32\mongodb-win32-x86_64-3.x.x.zip

This will avoid the need to download the embedded mongo for the Flapdoodle OSS, which Spring uses.

Caveat: If your team needs a different version of embedded mongo you can change the version for the EmbeddedMongoProperties class by adding this property to your application.properties (or .yml) file:

spring.mongodb.embedded.version = 3.4.6

elesg
  • 63
  • 1
  • 5
Kris Wheeler
  • 279
  • 4
  • 8