Package org.mongojack
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 Summary
Fields Modifier and Type Field Description protected com.mongodb.client.MongoDatabase
db
protected com.mongodb.client.MongoClient
mongo
protected org.bson.UuidRepresentation
uuidRepresentation
-
Constructor Summary
Constructors Constructor Description MongoDBTestBase()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> org.mongojack.JacksonMongoCollection<T>
configure(org.mongojack.JacksonMongoCollection<T> collection)
void
connectToDb()
void
disconnectFromDb()
protected <T> org.mongojack.JacksonMongoCollection<T>
getCollection(Class<T> type)
protected <T> org.mongojack.JacksonMongoCollection<T>
getCollection(Class<T> type, com.fasterxml.jackson.databind.ObjectMapper mapper)
protected <T> org.mongojack.JacksonMongoCollection<T>
getCollection(Class<T> type, String collectionName)
protected <T> org.mongojack.JacksonMongoCollection<T>
getCollection(Class<T> type, org.mongojack.JacksonMongoCollection.JacksonMongoCollectionBuilder builder)
protected <T> org.mongojack.JacksonMongoCollection<T>
getCollectionWithView(Class<T> type, Class<?> view)
protected <T> com.mongodb.client.MongoCollection<T>
getMongoCollection(Class<T> documentClass)
Get a collection with a random name.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 upprotected com.mongodb.client.MongoCollection<org.bson.Document>
getUnderlyingCollection(org.mongojack.JacksonMongoCollection<?> coll)
static void
startDb()
-
-
-
Method Detail
-
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> org.mongojack.JacksonMongoCollection<T> configure(org.mongojack.JacksonMongoCollection<T> collection)
-
getCollection
protected <T> org.mongojack.JacksonMongoCollection<T> getCollection(Class<T> type)
-
getCollection
protected <T> org.mongojack.JacksonMongoCollection<T> getCollection(Class<T> type, org.mongojack.JacksonMongoCollection.JacksonMongoCollectionBuilder builder)
-
getCollectionWithView
protected <T> org.mongojack.JacksonMongoCollection<T> getCollectionWithView(Class<T> type, Class<?> view)
-
getCollection
protected <T> org.mongojack.JacksonMongoCollection<T> getCollection(Class<T> type, String collectionName)
-
getCollection
protected <T> org.mongojack.JacksonMongoCollection<T> getCollection(Class<T> type, com.fasterxml.jackson.databind.ObjectMapper mapper)
-
getUnderlyingCollection
protected com.mongodb.client.MongoCollection<org.bson.Document> getUnderlyingCollection(org.mongojack.JacksonMongoCollection<?> coll)
-
-