GithubHelp home page GithubHelp logo

mongodb-integration-plugin's Introduction

**********************************
*** Overview
**********************************

This maven plugin manages a mongodb instance to be used during integration testing.

The plugin will start a mongod instance during the 'pre-integration-test' phase of the default maven lifecyle.
The plugin can be configured to prepopulate the database with data from various files. The plugin uses mongoimport
for this.

The plugin will stop the mongod instance during the 'post-integration-test' phase.

Should the build fail during the 'integration-test' phase, a special shutdown hook will ensure that the mongod instance
is still shutdown.

In theory, you would use this plugin with something like the Failsafe Plugin which is responsible for running
integration tests during the maven 'integration-test' phase.

**********************************
*** Prerequisites
**********************************

You will need to have mongodb installed on the machine where the maven build/integration tests will run.
The system user that will execute the maven build will need permissions to execute the mongod and mongoimport binaries.
The directory that stores the mongodb databases must exist.

**********************************
*** POM Configuration
**********************************

In order to use this plugin in a project, add the following to your pom:

<build>
    <plugins>
        <plugin>
            <groupId>biz.neustar.webmetrics.maven.plugins</groupId>
            <artifactId>mongodb-integration</artifactId>
            <version>1.0-SNAPSHOT</version>
            <configuration>
                <absolutePathToMongod>/Users/batman/src/mongodb-osx-x86_64-1.8.2/bin/mongod</absolutePathToMongod>
                <absolutePathToDatabaseDirectory>/Users/batman/mongodata</absolutePathToDatabaseDirectory>
                <absolutePathToMongoimport>/Users/batman/src/mongodb-osx-x86_64-1.8.2/bin/mongoimport</absolutePathToMongoimport>
                <databaseName>test</databaseName>
                <dbInitFiles>
                    <foo>/Users/batman/mongodb-init-data.txt</foo>
                </dbInitFiles>
            </configuration>
            <executions>
                <execution>
                    <id>start-mongod</id>
                    <goals>
                        <goal>start-mongod</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop-mongod</id>
                    <goals>
                        <goal>stop-mongod</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

**********************************
*** Plugin Configuration
**********************************

absolutePathToMongod -              The path to the mongod binary.

absolutePathToMongoimport -         The path to the mongoimport binary.

absolutePathToDatabaseDirectory -   Optional parameter. The path to the directory that stores the mongo database files.
                                    This folder must exist beforehand.
                                    It is passed as the '--dbpath' argument to mongod. By default, mongod will store
                                    data in /data/db although it won't automatically create that directory. The default
                                    value for this property is '/data/db'.

databaseName -                      Optional parameter; if this is specified, then the 'dbInitFiles' parameter must be
                                    defined. The name of the database into which the data files will be loaded. This
                                    database will be created if it does not already exist.

dbInitFiles -                       Optional parameter; if this is specified, then the 'databaseName' parameter must be
                                    defined. A map of collection names to data file names. In the example above, the
                                    file 'mongodb-init-data.txt' will be loaded into a collection named 'foo' in the
                                    database named 'test'.

secondsToWaitForMongodStartup -     Optional parameter; specifies the amount of time (in seconds) to wait between
                                    starting mongod and importing data into the database. This only applies if 
                                    'databaseName' and 'dbInitFiles' are configured. The default value is 2 seconds.

**********************************
*** Failsafe Plugin Configuration
**********************************

To be of any actual use, this mongodb integration plugin needs integration tests. Below is an
example Failsafe Plugin configuration which will execute src/test/java/**/*IT.java tests.

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.9</version>
        <executions>
            <execution>
                <id>integration-test</id>
                <goals>
                    <goal>integration-test</goal>
                </goals>
            </execution>
            <execution>
                <id>verify</id>
                <goals>
                    <goal>verify</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>

To execute the whole build/integration test process with mongodb you would then execute:
mvn verify

mongodb-integration-plugin's People

Contributors

bpossolo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.