Class MongoDBTestBase

java.lang.Object
org.mongojack.MongoDBTestBase
Direct Known Subclasses:
TestAggregate, TestAggregationBuilder, TestBsonSerializers, TestCustomObjectMapper, TestDBCursor, TestDBProjection, TestDBQuery, TestDBRefHandling, TestDBSort, TestDBUpdate, TestDBUpdateSerialization, TestIdAnnotatedClass, TestJacksonCodecRegistry, TestJacksonMongoCollection, TestJacksonMongoCollectionCustomObjectMapper, TestJavaTimeHandling, TestJsonViews, TestMapReduce, TestObjectIdHandling, TestParsingAndGenerating, TestParsingAndGeneratingPolymorphicTypes, TestQuerySerialization, TestUUIDHandling

public abstract class MongoDBTestBase extends Object
Base class for unit tests that run against MongoDB. Assumes there is a MongoDB instance listening on the default port on localhost, and that we can do whatever we want to a database called "unittest".
  • Field Details

    • mongo

      protected com.mongodb.client.MongoClient mongo
    • db

      protected com.mongodb.client.MongoDatabase db
    • uuidRepresentation

      protected org.bson.UuidRepresentation uuidRepresentation
  • Constructor Details

    • MongoDBTestBase

      public MongoDBTestBase()
  • Method Details

    • startDb

      @BeforeAll public static void startDb()
    • connectToDb

      @BeforeEach public void connectToDb()
    • disconnectFromDb

      @AfterEach public void disconnectFromDb()
    • getMongoCollection

      protected <T> com.mongodb.client.MongoCollection<T> getMongoCollection(String name, Class<T> documentClass)
      Get a collection with the given name, and store it, so that it will be dropped in clean up
      Parameters:
      name - The name of the collection
      Returns:
      The collection
    • getMongoCollection

      protected <T> com.mongodb.client.MongoCollection<T> getMongoCollection(Class<T> documentClass)
      Get a collection with a random name. Should grant some degree of isolation from tests running in parallel.
      Returns:
      The collection
    • configure

      protected <T> JacksonMongoCollection<T> configure(JacksonMongoCollection<T> collection)
    • getCollection

      protected <T> JacksonMongoCollection<T> getCollection(Class<T> type)
    • getCollection

      protected <T> JacksonMongoCollection<T> getCollection(Class<T> type, JacksonMongoCollection.JacksonMongoCollectionBuilder builder)
    • getCollectionWithView

      protected <T> JacksonMongoCollection<T> getCollectionWithView(Class<T> type, Class<?> view)
    • getCollection

      protected <T> JacksonMongoCollection<T> getCollection(Class<T> type, String collectionName)
    • getCollection

      protected <T> JacksonMongoCollection<T> getCollection(Class<T> type, tools.jackson.databind.ObjectMapper mapper)
    • getUnderlyingCollection

      protected com.mongodb.client.MongoCollection<org.bson.Document> getUnderlyingCollection(JacksonMongoCollection<?> coll)