Package fr.gouv.vitam.common.mongo

# Class MongoRule

java.lang.Object
org.junit.rules.ExternalResource
fr.gouv.vitam.common.mongo.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 final String`
  `COUNTER`
  `static final String`
  `ID`
  `static final String`
  `MONGO_HOST`
  `static final String`
  `VITAM_DB`
  `static final String`
  `VITAM_SEQUENCE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MongoRule(com.mongodb.MongoClientSettings.Builder mongoClientSettingsBuilder, String... collectionsToBePurged)`
  `MongoRule(String dbName, com.mongodb.MongoClientSettings.Builder mongoClientSettingsBuilder, String... collectionsToBePurged)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `MongoRule`
  `addCollectionToBePurged(String collectionName)`
  `protected void`
  `after()`
  `void`
  `close()`
  `static String`
  `getDatabaseName()`
  `static int`
  `getDataBasePort()`
  `com.mongodb.client.MongoClient`
  `getMongoClient()`
  `com.mongodb.client.MongoCollection<org.bson.Document>`
  `getMongoCollection(String collectionName)`
  `<TDocument>
  com.mongodb.client.MongoCollection<TDocument>`
  `getMongoCollection(String collectionName, Class<TDocument> clazz)`
  `com.mongodb.client.MongoDatabase`
  `getMongoDatabase()`
  `void`
  `handleAfter()`
  `void`
  `handleAfter(Set<String> collections)`
  `void`
  `handleAfterClass()`
  Used when annotated @ClassRule

  ### 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 Details

  - ### VITAM_DB

    public static final String VITAM_DB
    See Also:
      - Constant Field Values

  - ### MONGO_HOST

    public static final String MONGO_HOST
    See Also:
      - Constant Field Values

  - ### VITAM_SEQUENCE

    public static final String VITAM_SEQUENCE
    See Also:
      - Constant Field Values

  - ### COUNTER

    public static final String COUNTER
    See Also:
      - Constant Field Values

  - ### ID

    public static final String ID
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### MongoRule

    public MongoRule(com.mongodb.MongoClientSettings.Builder mongoClientSettingsBuilder, String... collectionsToBePurged)

  - ### MongoRule

    public MongoRule(String dbName, com.mongodb.MongoClientSettings.Builder mongoClientSettingsBuilder, String... collectionsToBePurged)

- ## Method Details

  - ### getDatabaseName

    public static String getDatabaseName()

  - ### after

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

  - ### addCollectionToBePurged

    public MongoRule addCollectionToBePurged(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(String collectionName)

  - ### getMongoCollection

    public <TDocument> com.mongodb.client.MongoCollection<TDocument> getMongoCollection(String collectionName, Class<TDocument> clazz)

  - ### handleAfter

    public void handleAfter(Set<String> collections)

  - ### close

    public void close()