Class MongoRule

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

    public class MongoRule
    extends org.junit.rules.ExternalResource
    Launch a single instance of Mongo database, drop collection after each test
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String COUNTER  
      static java.lang.String ID  
      static java.lang.String MONGO_HOST  
      static java.lang.String VITAM_DB  
      static java.lang.String VITAM_SEQUENCE  
    • Constructor Summary

      Constructors 
      Constructor Description
      MongoRule​(com.mongodb.MongoClientSettings.Builder mongoClientSettingsBuilder, java.lang.String... collectionsToBePurged)  
      MongoRule​(java.lang.String dbName, com.mongodb.MongoClientSettings.Builder mongoClientSettingsBuilder, java.lang.String... collectionsToBePurged)  
    • Constructor Detail

      • MongoRule

        public MongoRule​(com.mongodb.MongoClientSettings.Builder mongoClientSettingsBuilder,
                         java.lang.String... collectionsToBePurged)
      • MongoRule

        public MongoRule​(java.lang.String dbName,
                         com.mongodb.MongoClientSettings.Builder mongoClientSettingsBuilder,
                         java.lang.String... collectionsToBePurged)
    • Method Detail

      • getDatabaseName

        public static java.lang.String getDatabaseName()
      • after

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

        public MongoRule addCollectionToBePurged​(java.lang.String collectionName)
      • handleAfterClass

        public void handleAfterClass()
        Used when annotated @ClassRule
      • handleAfter

        public void handleAfter()
      • getDataBasePort

        public static int getDataBasePort()
      • getMongoClient

        public com.mongodb.client.MongoClient getMongoClient()
      • getMongoDatabase

        public com.mongodb.client.MongoDatabase getMongoDatabase()
      • getMongoCollection

        public com.mongodb.client.MongoCollection<org.bson.Document> getMongoCollection​(java.lang.String collectionName)
      • getMongoCollection

        public <TDocument> com.mongodb.client.MongoCollection<TDocument> getMongoCollection​(java.lang.String collectionName,
                                                                                            java.lang.Class<TDocument> clazz)
      • handleAfter

        public void handleAfter​(java.util.Set<java.lang.String> collections)
      • close

        public void close()