title: In memory mongo database for unit tests in a private network
body: <p>I have a java/spring-boot/maven project that uses <code>Mongo</code> as database. I want to create some tests (unit tests and integration tests) for this project, that would run in a clean machine. To help with that, I started to look for in memory mongo database, that would be applicable only for unit tests.</p>
  
  <p>I've found <a href="https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo" rel="nofollow noreferrer">Flapdoodle</a>, and it worked as expected in my local machine. I could run the tests I needed without having the whole Mongo setup. However, it downloads <code>EmbeddedMongo</code>, which is something that can't be done on the official build machine (Continuous integration), since it runs in a private network and it can't download it.</p>
  
  <p>Since it tries to download <code>EmbeddedMongo</code> only on the first time, I thought - maybe if I manually place the folder <code>.embedmongo</code> on the build machine, it wouldn't need to download it from the unreachable server. So I tried to configure it using the <a href="https://github.com/joelittlejohn/embedmongo-maven-plugin" rel="nofollow noreferrer">embedmongo-maven-plugin</a> suggested on Flapdoodle's github read me. I tried, on my local Windows machine, to create a configuration that wouldn't download it (pom.xml code below) by creating a separate folder and telling it to look for a different folder, but it always tries to download it (does not look for a different folder). </p>
  
  <p>I'm surely missing something here... Could you help me with that?</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.7.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.mycompany.root&lt;/groupId&gt;
      &lt;artifactId&gt;project&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;name&gt;project&lt;/name&gt;
      &lt;description&gt;My Project&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-mongodb&lt;/artifactId&gt;
              &lt;version&gt;2.1.9.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;de.flapdoodle.embed&lt;/groupId&gt;
              &lt;artifactId&gt;de.flapdoodle.embed.mongo&lt;/artifactId&gt;
              &lt;version&gt;2.2.0&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;com.github.joelittlejohn.embedmongo&lt;/groupId&gt;
                  &lt;artifactId&gt;embedmongo-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;0.4.1&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;start&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;start&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;randomPort&gt;true&lt;/randomPort&gt;
                              &lt;!-- optional, default is false, if true allocates a random port and overrides embedmongo.port --&gt;
  
                              &lt;databaseDirectory&gt;C:/dev&lt;/databaseDirectory&gt;
                              &lt;!-- optional, default is a new dir in java.io.tmpdir --&gt;
  
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;stop&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;stop&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  
  </code></pre>
  
  <p>I'm really not sure if I'm on the correct path - the <code>embedmongo-maven-plugin</code> does not seem to make any difference here... I could use another in-memory database solution, but Flapdoodle seems to be the simplest one, and that's why I'm currently trying with it.</p>
  
  <p>-- Edit --</p>
  
  <p>I've just tried the other suggested plugin, as below:</p>
  
  <pre class="lang-xml prettyprint-override"><code>            &lt;plugin&gt;
                  &lt;groupId&gt;com.syncleus.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-mongodb-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.1.1&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;start&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;start&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
  
                              &lt;artifactDirectory&gt;C:/dev/.embedmongo&lt;/artifactDirectory&gt;
                              &lt;!-- optional, set directory where MongoDB artifacts are stores,
                                   default is ~/.embedmongo --&gt;
  
  
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;stop&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;stop&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  </code></pre>
  
  <p>However, it does not seem to work at all - even if I just add with no configurations (to run as default), it fails running locally (in an open network). I wonder if there are any other options...</p>