Class MongoDatabasePolicy

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    class MongoDatabasePolicy
    extends org.junit.rules.ExternalResource
    Instantiates a new connection to Fongo (or Mongo) database depending on the current profile (unit or integration tests).

    By default, this rule is executed as part of a unit test and in-memory database Fongo is used.

    However, if the maven profile is set to IT (eg. via command line $ mvn -Pit install) this rule will connect to an existing (external) Mongo instance (localhost).

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private com.mongodb.MongoClient client  
      private com.mongodb.client.MongoDatabase database  
      private static java.lang.String DB_NAME  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MongoDatabasePolicy​(com.mongodb.MongoClient client)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void after()  
      (package private) static MongoDatabasePolicy create()
      Creates an instance based on current maven profile (as defined by -Pit).
      (package private) com.mongodb.client.MongoDatabase database()  
      • Methods inherited from class org.junit.rules.ExternalResource

        apply, before
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • database

        private final com.mongodb.client.MongoDatabase database
      • client

        private final com.mongodb.MongoClient client
    • Constructor Detail

      • MongoDatabasePolicy

        private MongoDatabasePolicy​(com.mongodb.MongoClient client)
    • Method Detail

      • create

        static MongoDatabasePolicy create()
        Creates an instance based on current maven profile (as defined by -Pit).
        Returns:
        new instance of the policy to be used by unit tests
      • database

        com.mongodb.client.MongoDatabase database()
      • after

        protected void after()
        Overrides:
        after in class org.junit.rules.ExternalResource